Skip to content

Commit aadfce0

Browse files
authored
Merge pull request #216 from lenkan/fix-int-parsing
fix sn to int parsing to use base 16
2 parents ec97594 + 9bae76d commit aadfce0

File tree

4 files changed

+64
-15
lines changed

4 files changed

+64
-15
lines changed

src/keri/app/aiding.ts

+2-4
Original file line numberDiff line numberDiff line change
@@ -254,13 +254,11 @@ export class Identifier {
254254
const pre: string = hab.prefix;
255255

256256
const state = hab.state;
257-
const sn = Number(state.s);
257+
const sn = parseInt(state.s, 16);
258258
const dig = state.d;
259259

260260
data = Array.isArray(data) ? data : [data];
261261

262-
data = Array.isArray(data) ? data : [data];
263-
264262
const serder = interact({
265263
pre: pre,
266264
sn: sn + 1,
@@ -307,7 +305,7 @@ export class Identifier {
307305
const state = hab.state;
308306
const count = state.k.length;
309307
const dig = state.d;
310-
const ridx = Number(state.s) + 1;
308+
const ridx = parseInt(state.s, 16) + 1;
311309
const wits = state.b;
312310
let isith = state.nt;
313311

src/keri/app/credentialing.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -224,7 +224,7 @@ export class Credentials {
224224
dt: dt,
225225
});
226226

227-
const sn = Number(hab.state.s);
227+
const sn = parseInt(hab.state.s, 16);
228228
const anc = interact({
229229
pre: hab.prefix,
230230
sn: sn + 1,
@@ -308,7 +308,7 @@ export class Credentials {
308308
var estOnly = false;
309309
}
310310

311-
const sn = Number(state.s);
311+
const sn = parseInt(state.s, 16);
312312
const dig = state.d;
313313

314314
const data: any = [
@@ -583,7 +583,7 @@ export class Registries {
583583
throw new Error('establishment only not implemented');
584584
} else {
585585
const state = hab.state;
586-
const sn = Number(state.s);
586+
const sn = parseInt(state.s, 16);
587587
const dig = state.d;
588588

589589
const data: any = [

src/keri/core/number.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ export class CesrNumber extends Matter {
4040
// make huge version of code
4141
code = code = NumDex.Huge;
4242
} else {
43-
throw new Error('Invalid num = {num}, too large to encode.');
43+
throw new Error(`Invalid num = ${num}, too large to encode.`);
4444
}
4545

4646
raw = intToBytes(_num, Matter._rawSize(code));

test/app/aiding.test.ts

+58-7
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,30 @@ describe('Aiding', () => {
191191
assert.deepEqual(lastCall.body.salty.transferable, true);
192192
});
193193

194+
it('Can rotate salty identifier with sn > 10', async () => {
195+
const aid1 = await createMockIdentifierState('aid1', bran, {});
196+
client.fetch.mockResolvedValueOnce(
197+
Response.json({
198+
...aid1,
199+
state: {
200+
...aid1.state,
201+
s: 'a',
202+
},
203+
})
204+
);
205+
client.fetch.mockResolvedValueOnce(Response.json({}));
206+
207+
await client.identifiers().rotate('aid1');
208+
const lastCall = client.getLastMockRequest();
209+
assert.equal(lastCall.path, '/identifiers/aid1');
210+
assert.equal(lastCall.method, 'PUT');
211+
expect(lastCall.body.rot).toMatchObject({
212+
v: 'KERI10JSON000160_',
213+
t: 'rot',
214+
s: 'b',
215+
});
216+
});
217+
194218
it('Can create interact event', async () => {
195219
const data = [
196220
{
@@ -217,20 +241,47 @@ describe('Aiding', () => {
217241
i: 'ELUvZ8aJEHAQE-0nsevyYTP98rBbGJUrTj5an-pCmwrK',
218242
s: '1',
219243
p: 'ELUvZ8aJEHAQE-0nsevyYTP98rBbGJUrTj5an-pCmwrK',
220-
a: [
221-
{
222-
i: 'ELUvZ8aJEHAQE-0nsevyYTP98rBbGJUrTj5an-pCmwrK',
223-
s: 0,
224-
d: 'ELUvZ8aJEHAQE-0nsevyYTP98rBbGJUrTj5an-pCmwrK',
225-
},
226-
],
244+
a: data,
227245
});
228246

229247
assert.deepEqual(lastCall.body.sigs, [
230248
'AADEzKk-5LT6vH-PWFb_1i1A8FW-KGHORtTOCZrKF4gtWkCr9vN1z_mDSVKRc6MKktpdeB3Ub1fWCGpnS50hRgoJ',
231249
]);
232250
});
233251

252+
it('Can create interact event when sequence number > 10', async () => {
253+
const data = [
254+
{
255+
i: 'ELUvZ8aJEHAQE-0nsevyYTP98rBbGJUrTj5an-pCmwrK',
256+
s: 0,
257+
d: 'ELUvZ8aJEHAQE-0nsevyYTP98rBbGJUrTj5an-pCmwrK',
258+
},
259+
];
260+
261+
const aid1 = await createMockIdentifierState('aid1', bran);
262+
client.fetch.mockResolvedValueOnce(
263+
Response.json({
264+
...aid1,
265+
state: {
266+
...aid1.state,
267+
s: 'a',
268+
},
269+
})
270+
);
271+
client.fetch.mockResolvedValueOnce(Response.json({}));
272+
273+
await client.identifiers().interact('aid1', data);
274+
275+
const lastCall = client.getLastMockRequest();
276+
277+
expect(lastCall.path).toEqual('/identifiers/aid1?type=ixn');
278+
expect(lastCall.method).toEqual('PUT');
279+
expect(lastCall.body.ixn).toMatchObject({
280+
s: 'b',
281+
a: data,
282+
});
283+
});
284+
234285
it('Can add end role', async () => {
235286
const aid1 = await createMockIdentifierState('aid1', bran, {});
236287
client.fetch.mockResolvedValueOnce(Response.json(aid1));

0 commit comments

Comments
 (0)