diff --git a/src/keri/app/aiding.ts b/src/keri/app/aiding.ts index 9ce09417..c0bad4d1 100644 --- a/src/keri/app/aiding.ts +++ b/src/keri/app/aiding.ts @@ -254,13 +254,11 @@ 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]; - data = Array.isArray(data) ? data : [data]; - const serder = interact({ pre: pre, sn: sn + 1, @@ -307,7 +305,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 = [ 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)); 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));