From 251746989920171218c8dc9e8dad2c7025acb0dd Mon Sep 17 00:00:00 2001 From: Rodolfo Date: Fri, 31 May 2024 03:11:29 -0300 Subject: [PATCH] Fix non-transferable prefix (#265) * Fix non-transferable prefix * pretty --- src/keri/app/aiding.ts | 12 +++++++++--- src/keri/core/prefixer.ts | 2 +- test/app/aiding.test.ts | 39 +++++++++++++++++++++++++++++++++++++++ 3 files changed, 49 insertions(+), 4 deletions(-) diff --git a/src/keri/app/aiding.ts b/src/keri/app/aiding.ts index 011848fa..290acd2c 100644 --- a/src/keri/app/aiding.ts +++ b/src/keri/app/aiding.ts @@ -135,10 +135,10 @@ export class Identifier { const transferable = kargs.transferable ?? true; const isith = kargs.isith ?? '1'; - const nsith = kargs.nsith ?? '1'; + let nsith = kargs.nsith ?? '1'; let wits = kargs.wits ?? []; const toad = kargs.toad ?? 0; - const dcode = kargs.dcode ?? MtrDex.Blake3_256; + let dcode = kargs.dcode ?? MtrDex.Blake3_256; const proxy = kargs.proxy; const delpre = kargs.delpre; const data = kargs.data != undefined ? [kargs.data] : []; @@ -152,11 +152,17 @@ export class Identifier { const _ndigs = kargs.ndigs; const bran = kargs.bran; const count = kargs.count; - const ncount = kargs.ncount; + let ncount = kargs.ncount; const tier = kargs.tier; const extern_type = kargs.extern_type; const extern = kargs.extern; + if (!transferable) { + ncount = 0; + nsith = 0; + dcode = MtrDex.Ed25519N; + } + const xargs = { transferable: transferable, isith: isith, diff --git a/src/keri/core/prefixer.ts b/src/keri/core/prefixer.ts index b2e9faff..00ccd6bd 100644 --- a/src/keri/core/prefixer.ts +++ b/src/keri/core/prefixer.ts @@ -88,7 +88,7 @@ export class Prefixer extends Matter { throw new Error(`Error extracting public key = ${e}`); } - if (!(verfer.code in [MtrDex.Ed25519N])) { + if (verfer.code != MtrDex.Ed25519N) { throw new Error(`Mismatch derivation code = ${verfer.code}`); } diff --git a/test/app/aiding.test.ts b/test/app/aiding.test.ts index 0872fc6c..8a5c95f1 100644 --- a/test/app/aiding.test.ts +++ b/test/app/aiding.test.ts @@ -99,6 +99,45 @@ describe('Aiding', () => { assert.deepEqual(lastCall.body.salty.transferable, true); }); + it('Can create non-transferable salty identifiers', async () => { + client.fetch.mockResolvedValue(Response.json({})); + await client.identifiers().create('aid1', { + bran: '0123456789abcdefghijk', + transferable: false, + }); + + const lastCall = client.getLastMockRequest(); + assert.equal(lastCall.path, '/identifiers'); + assert.equal(lastCall.method, 'POST'); + assert.equal(lastCall.body.name, 'aid1'); + console.log(lastCall.body); + assert.deepEqual(lastCall.body.icp, { + v: 'KERI10JSON0000fd_', + t: 'icp', + d: 'EFI3s8I7M6b8iiOFJOqDfjuak9NQJtVx8N2Px_cm2lsN', + i: 'BPmhSfdhCPxr3EqjxzEtF8TVy0YX7ATo0Uc8oo2cnmY9', + s: '0', + kt: '1', + k: ['BPmhSfdhCPxr3EqjxzEtF8TVy0YX7ATo0Uc8oo2cnmY9'], + nt: '0', + n: [], + bt: '0', + b: [], + c: [], + a: [], + }); + assert.deepEqual(lastCall.body.sigs, [ + 'AAD43ke-FKLzD_eOJuE7-G5jeqjs9iyirE-atbxd4sSvEn-0fRibOWI5jtvlE8b8Dn8_rVRa1BUCyDfmEXzy1uwA', + ]); + assert.deepEqual(lastCall.body.salty.pidx, 0); + assert.deepEqual(lastCall.body.salty.kidx, 0); + assert.deepEqual(lastCall.body.salty.stem, 'signify:aid'); + assert.deepEqual(lastCall.body.salty.tier, 'low'); + assert.deepEqual(lastCall.body.salty.icodes, ['A']); + assert.deepEqual(lastCall.body.salty.dcode, 'B'); + assert.deepEqual(lastCall.body.salty.transferable, false); + }); + it('Can get identifiers with special characters in the name', async () => { client.fetch.mockResolvedValue(Response.json({})); await client.identifiers().get('a name with ñ!');