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

Credential issuance and IPEX grant message for multisig participants #118

Merged
merged 3 commits into from
Oct 17, 2023
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
4 changes: 2 additions & 2 deletions examples/scripts/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ async function connect() {
const exchanges = client.exchanges();

let salt = 'abcdefghijk0123456789';
let res = identifiers.create('multisig-ts', { bran: salt });
let res = await identifiers.create('multisig-ts', { bran: salt });
let op = await res.op();
let aid = op['response'];

Expand Down Expand Up @@ -86,7 +86,7 @@ async function connect() {
let sigTs = aid['state'];

let states = [sigPy, kli, sigTs];
let ires = identifiers.create('multisig', {
let ires = await identifiers.create('multisig', {
algo: signify.Algos.group,
mhab: aid,
delpre: 'EHpD0-CDWOdu5RJ8jHBSUkOqBZ3cXeDVHWNb_Ul89VI7',
Expand Down
3 changes: 3 additions & 0 deletions examples/scripts/multisig-create-credential.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/bin/bash

npx --package=signify-ts ts-node --esm multisig-create-credential.ts
246 changes: 246 additions & 0 deletions examples/scripts/multisig-create-credential.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,246 @@
import signify from 'signify-ts';

await connect();

async function connect() {
let url = 'http://127.0.0.1:3901';
let bran = '0123456789abcdefghijk';

await signify.ready();
const client = new signify.SignifyClient(url, bran);
console.log(client.controller.pre);
const [evt, sign] = client.controller?.event ?? [];
const data = {
icp: evt.ked,
sig: sign.qb64,
stem: client.controller?.stem,
pidx: 1,
tier: client.controller?.tier,
};

await fetch('http://127.0.0.1:3903/boot', {
method: 'POST',
body: JSON.stringify(data),
headers: {
'Content-Type': 'application/json',
},
});

await client.connect();
let d = await client.state();
console.log('Connected: ');
console.log(' Agent: ', d.agent.i, ' Controller: ', d.controller.state.i);

let identifiers = client.identifiers();
const oobis = client.oobis();
const operations = client.operations();
const exchanges = client.exchanges();

let salt = '0123456789lmnopqrstuv';
let res = await identifiers.create('agent0', {bran: salt});
let op = await res.op();
let aid = op['response'];

await identifiers.addEndRole('agent0', 'agent', d.agent.i);

console.log('Created AID: ', aid);

console.log('Resolving multisig1...');
op = await oobis.resolve(
'http://127.0.0.1:5642/oobi/EKYLUMmNPZeEs77Zvclf0bSN5IN-mLfLpx2ySb-HDlk4/witness',
'multisig1'
);
while (!op['done']) {
op = await operations.get(op['name']);
await new Promise((resolve) => setTimeout(resolve, 1000)); // sleep for 1 second
}
console.log('done.');
let multisig1 = op['response'];

console.log('Resolving multisig2...');
op = await oobis.resolve(
'http://127.0.0.1:5642/oobi/EJccSRTfXYF6wrUVuenAIHzwcx3hJugeiJsEKmndi5q1/witness',
'multisig2'
);
while (!op['done']) {
op = await operations.get(op['name']);
await new Promise((resolve) => setTimeout(resolve, 1000)); // sleep for 1 second
}
console.log('done.');
let multisig2 = op['response'];

aid = await identifiers.get('agent0');
let agent0 = aid['state'];

let states = [multisig2, multisig1, agent0];
let ires = await identifiers.create('multisig', {
algo: signify.Algos.group,
mhab: aid,
toad: 3,
wits: [
'BBilc4-L3tFUnfM_wJr4S4OJanAv_VmF_dJNN6vkf2Ha',
'BLskRTInXnMxWaGqcpSyMgo0nYbalW99cGZESrz3zapM',
'BIKKuvBwpmDVA4Ds-EpL5bt9OqPzWPja2LigFYZN2YfX',
],
isith: ['1/3', '1/3', '1/3'],
nsith: ['1/3', '1/3', '1/3'],
states: states,
rstates: states,
});

let serder = ires.serder;
let sigs = ires.sigs;
let sigers = sigs.map((sig: any) => new signify.Siger({qb64: sig}));

let ims = signify.d(signify.messagize(serder, sigers));
let atc = ims.substring(serder.size);
let embeds = {
icp: [serder, atc],
};

let smids = states.map((state) => state['i']);
let recp = [multisig2, multisig1].map((state) => state['i']);

await exchanges.send(
'agent0',
'multisig',
aid,
'/multisig/icp',
{gid: serder.pre, smids: smids, rmids: smids},
embeds,
recp
);

let multisigAID = serder.pre
console.log("Waiting for multisig AID to be created")

op = await ires.op()
while (!op['done']) {
op = await operations.get(op['name']);
await new Promise((resolve) => setTimeout(resolve, 1000)); // sleep for 1 second
}
console.log('done.');

console.log("Resolving schema...")
op = await oobis.resolve(
'http://127.0.0.1:7723/oobi/EBfdlu8R27Fbx-ehrqwImnK-8Cm79sqbAQ4MmvEAYqao',
'schema'
);
while (!op['done']) {
op = await operations.get(op['name']);
await new Promise((resolve) => setTimeout(resolve, 1000)); // sleep for 1 second
}
console.log('done.');
let schemaSAID = "EBfdlu8R27Fbx-ehrqwImnK-8Cm79sqbAQ4MmvEAYqao"


console.log("Creating registry...")
let vcpRes1 = await client.registries().create({
name: 'multisig',
registryName: 'vLEI Registry',
nonce: 'AHSNDV3ABI6U8OIgKaj3aky91ZpNL54I5_7-qwtC6q2s',
});

let op1 = await vcpRes1.op();
serder = vcpRes1.regser;
let regk = serder.pre
let anc = vcpRes1.serder;
sigs = vcpRes1.sigs;

sigers = sigs.map((sig: any) => new signify.Siger({qb64: sig}));
ims = signify.d(signify.messagize(anc, sigers));
atc = ims.substring(anc.size);

let regbeds = {
vcp: [serder, ''],
anc: [anc, atc],
};

recp = ["EKYLUMmNPZeEs77Zvclf0bSN5IN-mLfLpx2ySb-HDlk4", "EJccSRTfXYF6wrUVuenAIHzwcx3hJugeiJsEKmndi5q1"]
await client.exchanges().send(
'agent0',
'multisig',
aid,
'/multisig/vcp',
{gid: multisigAID, usage: 'Issue vLEIs'},
regbeds,
recp
);

while (!op1['done']) {
op1 = await operations.get(op1['name']);
await new Promise((resolve) => setTimeout(resolve, 1000)); // sleep for 1 second
}
console.log('done.');

console.log("Creating credential from multisig...")
// Issue credential
const vcdata = {
LEI: '5493001KJTIIGC8Y1R17',
};
let holder = "ELjSFdrTdCebJlmvbFNX9-TLhR2PO0_60al1kQp5_e6k"

let TIME = "2023-09-25T16:01:37.000000+00:00"
let credRes = await client.credentials().issue('multisig', regk, schemaSAID, holder, vcdata,
undefined, undefined, TIME);
op1 = await credRes.op()

let acdc = new signify.Serder(credRes.acdc)
let iss = credRes.iserder
let ianc = credRes.anc
let isigs = credRes.sigs

sigers = isigs.map((sig: any) => new signify.Siger({qb64: sig}));
ims = signify.d(signify.messagize(ianc, sigers));
atc = ims.substring(anc.size);

let vcembeds = {
acdc: [acdc, ''],
iss: [iss, ''],
anc: [ianc, atc],
};

await client.exchanges().send(
'agent0',
'multisig',
aid,
'/multisig/iss',
{gid: multisigAID},
vcembeds,
recp
);

while (!op1['done']) {
op1 = await client.operations().get(op1.name);
await new Promise((resolve) => setTimeout(resolve, 1000));
}

console.log("Creating IPEX grant message to send...")

let [grant, gsigs, end] = await client.ipex().grant("multisig", holder, "", acdc, iss, ianc, atc, undefined, TIME)
let m = await client.identifiers().get("multisig")

let mstate = m["state"]
let seal = ['SealEvent', {i: m['prefix'], s: mstate["ee"]["s"], d: mstate["ee"]["d"]}];
sigers = gsigs.map((sig: any) => new signify.Siger({qb64: sig}));

let gims = signify.d(signify.messagize(grant, sigers, seal, undefined, undefined, true));
atc = gims.substring(grant.size)
atc += end

let gembeds: any = {
exn: [grant, atc]
}

await client.exchanges().send(
'agent0',
'multisig',
aid,
'/multisig/exn',
{gid: multisigAID},
gembeds,
recp
);

console.log("... done!")
}
3 changes: 2 additions & 1 deletion examples/scripts/multisig-kli.sh
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,5 @@ kli multisig incept --name multisig-kli --alias multisig-kli --group multisig --

read -n 1 -r -p "Press any key to create endpoints for multisig AID..."

kli multisig ends add --name multisig-kli --alias multisig --role agent --role mailbox

kli ends add --name multisig-kli --alias multisig --role mailbox --eid BIKKuvBwpmDVA4Ds-EpL5bt9OqPzWPja2LigFYZN2YfX
6 changes: 6 additions & 0 deletions examples/scripts/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 10 additions & 1 deletion src/keri/app/clienting.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { ExternalModule, KeyManager } from '../core/keeping';
import { Identifier } from './aiding';
import { Contacts, Challenges } from './contacting';
import { Oobis, Operations, KeyEvents, KeyStates } from './coring';
import { Credentials, Registries, Schemas } from './credentialing';
import {Credentials, Ipex, Registries, Schemas} from './credentialing';
import { Notifications } from './notifying';
import { Escrows } from './escrowing';
import { Groups } from './grouping';
Expand Down Expand Up @@ -417,6 +417,15 @@ export class SignifyClient {
return new Credentials(this);
}


/**
* Get IPEX resource
* @returns {Ipex}
*/
ipex(): Ipex {
return new Ipex(this);
}

/**
* Get registries resource
* @returns {Registries}
Expand Down
Loading
Loading