From 5dda06153aaef9e452d948ec0b4ff81134b293f4 Mon Sep 17 00:00:00 2001 From: lenkan Date: Tue, 13 Feb 2024 21:42:29 +0100 Subject: [PATCH 1/3] fix sn to int parsing to use base 16 --- src/keri/app/aiding.ts | 4 ++-- src/keri/app/credentialing.ts | 6 +++--- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/keri/app/aiding.ts b/src/keri/app/aiding.ts index 9ce09417..a4e5269e 100644 --- a/src/keri/app/aiding.ts +++ b/src/keri/app/aiding.ts @@ -254,7 +254,7 @@ export class Identifier { const pre: string = hab.prefix; const state = hab.state; - const sn = Number(state.s); + const sn = parseInt(state.s, 16); const dig = state.d; data = Array.isArray(data) ? data : [data]; @@ -307,7 +307,7 @@ export class Identifier { const state = hab.state; const count = state.k.length; const dig = state.d; - const ridx = Number(state.s) + 1; + const ridx = parseInt(state.s, 16) + 1; const wits = state.b; let isith = state.nt; diff --git a/src/keri/app/credentialing.ts b/src/keri/app/credentialing.ts index 058ccdd4..ccdfe22b 100644 --- a/src/keri/app/credentialing.ts +++ b/src/keri/app/credentialing.ts @@ -224,7 +224,7 @@ export class Credentials { dt: dt, }); - const sn = Number(hab.state.s); + const sn = parseInt(hab.state.s, 16); const anc = interact({ pre: hab.prefix, sn: sn + 1, @@ -308,7 +308,7 @@ export class Credentials { var estOnly = false; } - const sn = Number(state.s); + const sn = parseInt(state.s, 16); const dig = state.d; const data: any = [ @@ -583,7 +583,7 @@ export class Registries { throw new Error('establishment only not implemented'); } else { const state = hab.state; - const sn = Number(state.s); + const sn = parseInt(state.s, 16); const dig = state.d; const data: any = [ From a646807f403ead57f471d0214690acc67d8449eb Mon Sep 17 00:00:00 2001 From: lenkan Date: Tue, 13 Feb 2024 21:58:38 +0100 Subject: [PATCH 2/3] add test for aid state s > 10 --- src/keri/app/aiding.ts | 2 -- test/app/aiding.test.ts | 65 ++++++++++++++++++++++++++++++++++++----- 2 files changed, 58 insertions(+), 9 deletions(-) diff --git a/src/keri/app/aiding.ts b/src/keri/app/aiding.ts index a4e5269e..c0bad4d1 100644 --- a/src/keri/app/aiding.ts +++ b/src/keri/app/aiding.ts @@ -259,8 +259,6 @@ export class Identifier { data = Array.isArray(data) ? data : [data]; - data = Array.isArray(data) ? data : [data]; - const serder = interact({ pre: pre, sn: sn + 1, diff --git a/test/app/aiding.test.ts b/test/app/aiding.test.ts index 094389d3..898ce65d 100644 --- a/test/app/aiding.test.ts +++ b/test/app/aiding.test.ts @@ -191,6 +191,30 @@ describe('Aiding', () => { assert.deepEqual(lastCall.body.salty.transferable, true); }); + it('Can rotate salty identifier with sn > 10', async () => { + const aid1 = await createMockIdentifierState('aid1', bran, {}); + client.fetch.mockResolvedValueOnce( + Response.json({ + ...aid1, + state: { + ...aid1.state, + s: 'a', + }, + }) + ); + client.fetch.mockResolvedValueOnce(Response.json({})); + + await client.identifiers().rotate('aid1'); + const lastCall = client.getLastMockRequest(); + assert.equal(lastCall.path, '/identifiers/aid1'); + assert.equal(lastCall.method, 'PUT'); + expect(lastCall.body.rot).toMatchObject({ + v: 'KERI10JSON000160_', + t: 'rot', + s: 'b', + }); + }); + it('Can create interact event', async () => { const data = [ { @@ -217,13 +241,7 @@ describe('Aiding', () => { i: 'ELUvZ8aJEHAQE-0nsevyYTP98rBbGJUrTj5an-pCmwrK', s: '1', p: 'ELUvZ8aJEHAQE-0nsevyYTP98rBbGJUrTj5an-pCmwrK', - a: [ - { - i: 'ELUvZ8aJEHAQE-0nsevyYTP98rBbGJUrTj5an-pCmwrK', - s: 0, - d: 'ELUvZ8aJEHAQE-0nsevyYTP98rBbGJUrTj5an-pCmwrK', - }, - ], + a: data, }); assert.deepEqual(lastCall.body.sigs, [ @@ -231,6 +249,39 @@ describe('Aiding', () => { ]); }); + it('Can create interact event when sequence number > 10', async () => { + const data = [ + { + i: 'ELUvZ8aJEHAQE-0nsevyYTP98rBbGJUrTj5an-pCmwrK', + s: 0, + d: 'ELUvZ8aJEHAQE-0nsevyYTP98rBbGJUrTj5an-pCmwrK', + }, + ]; + + const aid1 = await createMockIdentifierState('aid1', bran); + client.fetch.mockResolvedValueOnce( + Response.json({ + ...aid1, + state: { + ...aid1.state, + s: 'a', + }, + }) + ); + client.fetch.mockResolvedValueOnce(Response.json({})); + + await client.identifiers().interact('aid1', data); + + const lastCall = client.getLastMockRequest(); + + expect(lastCall.path).toEqual('/identifiers/aid1?type=ixn'); + expect(lastCall.method).toEqual('PUT'); + expect(lastCall.body.ixn).toMatchObject({ + s: 'b', + a: data, + }); + }); + it('Can add end role', async () => { const aid1 = await createMockIdentifierState('aid1', bran, {}); client.fetch.mockResolvedValueOnce(Response.json(aid1)); From 9bae76deea0c8568b1d3e9379664ad6c03e1ce4d Mon Sep 17 00:00:00 2001 From: lenkan Date: Tue, 13 Feb 2024 22:01:16 +0100 Subject: [PATCH 3/3] fix string template --- src/keri/core/number.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/keri/core/number.ts b/src/keri/core/number.ts index 082a2e14..18a4d27d 100644 --- a/src/keri/core/number.ts +++ b/src/keri/core/number.ts @@ -40,7 +40,7 @@ export class CesrNumber extends Matter { // make huge version of code code = code = NumDex.Huge; } else { - throw new Error('Invalid num = {num}, too large to encode.'); + throw new Error(`Invalid num = ${num}, too large to encode.`); } raw = intToBytes(_num, Matter._rawSize(code));