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: use cesrnumber when parsing sn in rotate event #257

Merged
merged 2 commits into from
May 9, 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
8 changes: 4 additions & 4 deletions src/keri/core/eventing.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,9 +67,9 @@ export function rotate({
throw new Error(`Invalid ilk = ${ilk} for rot or drt.`);
}

const sner = Number(sn);
if (sner < 1) {
throw new Error(`Invalid sn = 0x${sner.toString()} for rot or drt.`);
const sner = new CesrNumber({}, sn);
if (sner.num < 1) {
throw new Error(`Invalid sn = 0x${sner.numh} for rot or drt.`);
}
let _isit: number;

Expand Down Expand Up @@ -199,7 +199,7 @@ export function rotate({
t: _ilk,
d: '',
i: pre,
s: sner.toString(16),
s: sner.numh,
p: dig,
kt:
tholder.num &&
Expand Down
29 changes: 28 additions & 1 deletion test/core/eventing.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,12 @@ import libsodium from 'libsodium-wrappers-sumo';
import { Signer } from '../../src/keri/core/signer';
import { strict as assert } from 'assert';
import { MtrDex } from '../../src/keri/core/matter';
import { incept, messagize } from '../../src/keri/core/eventing';
import { incept, messagize, rotate } from '../../src/keri/core/eventing';
import { Saider } from '../../src/keri/core/saider';
import { Diger } from '../../src/keri/core/diger';
import { b, d, Ilks } from '../../src/keri/core/core';
import { Siger } from '../../src/keri/core/siger';
import { randomBytes } from 'crypto';

describe('key event function', () => {
it('incept should create inception events', async () => {
Expand Down Expand Up @@ -190,4 +191,30 @@ describe('key event function', () => {
'BhfNFh5uk-WxvhsL-AABAABB3MJGmBXxSEryNHw3YwZZLRl_6Ws4Me2WFq8PrQ6WlluSOpPqbwXuiG9RvNWZkqeW8A_0VRjokGMVRZ3m-c0I'
);
});

it('Rotate should create rotation event with hex sequence number', async () => {
await libsodium.ready;

const signer0 = new Signer({ transferable: true });
const signer1 = new Signer({ transferable: true });
const keys0 = [signer0.verfer.qb64];
const ndigs = [new Diger({}, signer1.verfer.qb64b).qb64];
const serder = incept({ keys: keys0, ndigs });

function createRotation(sn: number) {
return rotate({
keys: keys0,
pre: serder.ked.i,
ndigs: serder.ked.n,
sn,
isith: 1,
nsith: 1,
}).ked['s'];
}

assert.equal(createRotation(1), '1');
assert.equal(createRotation(10), 'a');
assert.equal(createRotation(14), 'e');
assert.equal(createRotation(255), 'ff');
});
});
Loading