From e7f46e6879b78af26bd6c9c8a657ed374dbd09e1 Mon Sep 17 00:00:00 2001 From: lenkan Date: Mon, 8 Apr 2024 17:52:22 +0200 Subject: [PATCH 1/2] WIP: test for passcode --- test/app/controller.test.ts | 32 +++++++++++++++++++++++++++++++- 1 file changed, 31 insertions(+), 1 deletion(-) diff --git a/test/app/controller.test.ts b/test/app/controller.test.ts index 6550627d..df619d4d 100644 --- a/test/app/controller.test.ts +++ b/test/app/controller.test.ts @@ -4,7 +4,7 @@ import libsodium from 'libsodium-wrappers-sumo'; import { openManager } from '../../src/keri/core/manager'; import { Signer } from '../../src/keri/core/signer'; import { MtrDex } from '../../src/keri/core/matter'; -import { Tier } from '../../src'; +import { Tier, randomPasscode } from '../../src'; describe('Controller', () => { it('manage account AID signing and agent verification', async () => { @@ -44,4 +44,34 @@ describe('Controller', () => { 'EIIY2SgE_bqKLl2MlnREUawJ79jTuucvWwh-S6zsSUFo' ); }); + + it('should generate unique controller AIDs per passcode', async () => { + await libsodium.ready; + const passcode1 = randomPasscode(); + const passcode2 = randomPasscode(); + + const controller1 = new Controller(passcode1, Tier.low); + const controller2 = new Controller(passcode2, Tier.low); + + assert.notEqual(controller1.pre, controller2.pre); + }); + + it('should generate unique controller AIDs per passcode', async () => { + await libsodium.ready; + const template = randomPasscode(); + + // Create new passcode where we know that the last character is different + const passcode1 = template.substring(0, template.length - 1) + 'a'; + const passcode2 = template.substring(0, template.length - 1) + 'b'; + + console.log(template.length); + assert.equal(passcode1.length, template.length); + assert.equal(passcode2.length, template.length); + assert.notEqual(passcode1, passcode2); + + const controller1 = new Controller(passcode1, Tier.low); + const controller2 = new Controller(passcode2, Tier.low); + + assert.notEqual(controller1.pre, controller2.pre); + }); }); From 30b1892069866c054e11d313dff49f8bbc262fc6 Mon Sep 17 00:00:00 2001 From: lenkan Date: Tue, 9 Apr 2024 17:14:58 +0200 Subject: [PATCH 2/2] generate passcodes with 21 characters instead of 22 --- src/keri/app/coring.ts | 3 ++- test/app/controller.test.ts | 19 ------------------- test/app/coring.test.ts | 2 +- 3 files changed, 3 insertions(+), 21 deletions(-) diff --git a/src/keri/app/coring.ts b/src/keri/app/coring.ts index a1d6af5b..fab67518 100644 --- a/src/keri/app/coring.ts +++ b/src/keri/app/coring.ts @@ -7,7 +7,8 @@ export function randomPasscode(): string { const raw = libsodium.randombytes_buf(16); const salter = new Salter({ raw: raw }); - return salter.qb64.substring(2); + // https://github.com/WebOfTrust/signify-ts/issues/242 + return salter.qb64.substring(2, 23); } export function randomNonce(): string { diff --git a/test/app/controller.test.ts b/test/app/controller.test.ts index df619d4d..b7cc52c8 100644 --- a/test/app/controller.test.ts +++ b/test/app/controller.test.ts @@ -55,23 +55,4 @@ describe('Controller', () => { assert.notEqual(controller1.pre, controller2.pre); }); - - it('should generate unique controller AIDs per passcode', async () => { - await libsodium.ready; - const template = randomPasscode(); - - // Create new passcode where we know that the last character is different - const passcode1 = template.substring(0, template.length - 1) + 'a'; - const passcode2 = template.substring(0, template.length - 1) + 'b'; - - console.log(template.length); - assert.equal(passcode1.length, template.length); - assert.equal(passcode2.length, template.length); - assert.notEqual(passcode1, passcode2); - - const controller1 = new Controller(passcode1, Tier.low); - const controller2 = new Controller(passcode2, Tier.low); - - assert.notEqual(controller1.pre, controller2.pre); - }); }); diff --git a/test/app/coring.test.ts b/test/app/coring.test.ts index 15066d31..2ebf6185 100644 --- a/test/app/coring.test.ts +++ b/test/app/coring.test.ts @@ -161,7 +161,7 @@ describe('Coring', () => { it('Random passcode', async () => { await libsodium.ready; const passcode = randomPasscode(); - assert.equal(passcode.length, 22); + assert.equal(passcode.length, 21); }); it('Random nonce', async () => {