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 hex encoded seq num issue when sn is greater than 10 #239

Closed
wants to merge 1 commit into from
Closed
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
43 changes: 43 additions & 0 deletions examples/integration-scripts/singlesig-rot-bulk.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import { strict as assert } from 'assert';
import signify, { SignifyClient, CesrNumber } from 'signify-ts';
import { waitOperation } from './utils/test-util';
import { getOrCreateClient, getOrCreateIdentifier } from './utils/test-setup';

const WITNESS_AIDS = [
'BBilc4-L3tFUnfM_wJr4S4OJanAv_VmF_dJNN6vkf2Ha',
'BLskRTInXnMxWaGqcpSyMgo0nYbalW99cGZESrz3zapM',
'BIKKuvBwpmDVA4Ds-EpL5bt9OqPzWPja2LigFYZN2YfX',
];

test('multisig', async function run() {
await signify.ready();

const [client1] = await Promise.all([getOrCreateClient()]);

let [aid1] = await Promise.all([createAID(client1, 'aid1', WITNESS_AIDS)]);

aid1 = await client1.identifiers().get(aid1.name);
assert.equal(aid1.name, 'aid1');
assert.equal(aid1.state.s, '0');
assert.equal(Number.isInteger(aid1.state.s), false);
assert.equal(Number(aid1.state.s), 0);

let rotCount = 15;
for (let i = 1; i < rotCount; i++) {
let rotResult = await client1.identifiers().rotate(aid1.name);
await waitOperation(client1, await rotResult.op());

aid1 = await client1.identifiers().get(aid1.name);
let sner = new CesrNumber({}, undefined, aid1.state.s);
assert.equal(sner.num, i);
assert.equal(sner.numh, i.toString(16));
}
}, 400000);

async function createAID(client: SignifyClient, name: string, wits: string[]) {
await getOrCreateIdentifier(client, name, {
wits: wits,
toad: wits.length,
});
return await client.identifiers().get(name);
}
8 changes: 5 additions & 3 deletions src/keri/app/aiding.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { MtrDex } from '../core/matter';
import { Serder } from '../core/serder';
import { parseRangeHeaders } from '../core/httping';
import { KeyManager } from '../core/keeping';
import { CesrNumber } from '../core/number';

/** Arguments required to create an identfier */
export interface CreateIdentiferArgs {
Expand Down Expand Up @@ -254,7 +255,7 @@ export class Identifier {
const pre: string = hab.prefix;

const state = hab.state;
const sn = Number(state.s);
const sner = new CesrNumber({}, undefined, state.s);
const dig = state.d;

data = Array.isArray(data) ? data : [data];
Expand All @@ -263,7 +264,7 @@ export class Identifier {

const serder = interact({
pre: pre,
sn: sn + 1,
sn: sner.num + 1,
data: data,
dig: dig,
version: undefined,
Expand Down Expand Up @@ -307,7 +308,8 @@ export class Identifier {
const state = hab.state;
const count = state.k.length;
const dig = state.d;
const ridx = Number(state.s) + 1;
const sner = new CesrNumber({}, undefined, state.s);
const ridx = sner.num + 1;
const wits = state.b;
let isith = state.nt;

Expand Down
13 changes: 7 additions & 6 deletions src/keri/app/credentialing.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import {
serializeIssExnAttachment,
} from '../core/utils';
import { Operation } from './coring';
import { CesrNumber } from '../core/number';

/** Types of credentials */
export class CredentialTypes {
Expand Down Expand Up @@ -230,10 +231,10 @@ export class Credentials {
dt: dt,
});

const sn = Number(hab.state.s);
const sner = new CesrNumber({}, undefined, hab.state.s);
const anc = interact({
pre: hab.prefix,
sn: sn + 1,
sn: sner.num + 1,
data: [
{
i: iss.i,
Expand Down Expand Up @@ -320,7 +321,7 @@ export class Credentials {
var estOnly = false;
}

const sn = Number(state.s);
const sner = new CesrNumber({}, undefined, state.s);
const dig = state.d;

const data: any = [
Expand All @@ -339,7 +340,7 @@ export class Credentials {
} else {
const serder = interact({
pre: pre,
sn: sn + 1,
sn: sner.num + 1,
data: data,
dig: dig,
version: undefined,
Expand Down Expand Up @@ -604,7 +605,7 @@ export class Registries {
throw new Error('establishment only not implemented');
} else {
const state = hab.state;
const sn = Number(state.s);
const sner = new CesrNumber({}, undefined, state.s);
const dig = state.d;

const data: any = [
Expand All @@ -617,7 +618,7 @@ export class Registries {

const serder = interact({
pre: pre,
sn: sn + 1,
sn: sner.num + 1,
data: data,
dig: dig,
version: Versionage,
Expand Down
Loading