Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix sn to int parsing to use base 16 #216

Merged
merged 3 commits into from
Feb 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 2 additions & 4 deletions src/keri/app/aiding.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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;

Expand Down
6 changes: 3 additions & 3 deletions src/keri/app/credentialing.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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 = [
Expand Down Expand Up @@ -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 = [
Expand Down
2 changes: 1 addition & 1 deletion src/keri/core/number.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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.`);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch!

}

raw = intToBytes(_num, Matter._rawSize(code));
Expand Down
65 changes: 58 additions & 7 deletions test/app/aiding.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 = [
{
Expand All @@ -217,20 +241,47 @@ 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, [
'AADEzKk-5LT6vH-PWFb_1i1A8FW-KGHORtTOCZrKF4gtWkCr9vN1z_mDSVKRc6MKktpdeB3Ub1fWCGpnS50hRgoJ',
]);
});

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));
Expand Down
Loading