Skip to content

Commit

Permalink
Update randomPasscode to return 21 characters (WebOfTrust#243)
Browse files Browse the repository at this point in the history
  • Loading branch information
lenkan authored and daviddm committed May 8, 2024
1 parent 288dbbe commit ca69726
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 3 deletions.
3 changes: 2 additions & 1 deletion src/keri/app/coring.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
13 changes: 12 additions & 1 deletion test/app/controller.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 () => {
Expand Down Expand Up @@ -44,4 +44,15 @@ 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);
});
});
2 changes: 1 addition & 1 deletion test/app/coring.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 () => {
Expand Down

0 comments on commit ca69726

Please sign in to comment.