Skip to content

Commit

Permalink
pretty
Browse files Browse the repository at this point in the history
Signed-off-by: Kevin Griffin <[email protected]>
  • Loading branch information
m00sey committed Oct 25, 2023
1 parent 9245162 commit 6282052
Show file tree
Hide file tree
Showing 5 changed files with 242 additions and 200 deletions.
159 changes: 92 additions & 67 deletions examples/scripts/multisig-create-credential.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 = '0123456789lmnopqrstuv';
let res = await identifiers.create('agent0', {bran: salt});
let res = await identifiers.create('agent0', { bran: salt });
let op = await res.op();
let aid = op['response'];

Expand Down Expand Up @@ -90,7 +90,7 @@ async function connect() {

let serder = ires.serder;
let sigs = ires.sigs;
let sigers = sigs.map((sig: any) => new signify.Siger({qb64: sig}));
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);
Expand All @@ -106,22 +106,22 @@ async function connect() {
'multisig',
aid,
'/multisig/icp',
{gid: serder.pre, smids: smids, rmids: smids},
{ gid: serder.pre, smids: smids, rmids: smids },
embeds,
recp
);

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

op = await ires.op()
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...")
console.log('Resolving schema...');
op = await oobis.resolve(
'http://127.0.0.1:7723/oobi/EBfdlu8R27Fbx-ehrqwImnK-8Cm79sqbAQ4MmvEAYqao',
'schema'
Expand All @@ -131,10 +131,9 @@ async function connect() {
await new Promise((resolve) => setTimeout(resolve, 1000)); // sleep for 1 second
}
console.log('done.');
let schemaSAID = "EBfdlu8R27Fbx-ehrqwImnK-8Cm79sqbAQ4MmvEAYqao"
let schemaSAID = 'EBfdlu8R27Fbx-ehrqwImnK-8Cm79sqbAQ4MmvEAYqao';


console.log("Creating registry...")
console.log('Creating registry...');
let vcpRes1 = await client.registries().create({
name: 'multisig',
registryName: 'vLEI Registry',
Expand All @@ -143,11 +142,11 @@ async function connect() {

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

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

Expand All @@ -156,41 +155,56 @@ async function connect() {
anc: [anc, atc],
};

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

Expand All @@ -200,47 +214,58 @@ async function connect() {
anc: [ianc, atc],
};

await client.exchanges().send(
'agent0',
'multisig',
aid,
'/multisig/iss',
{gid: multisigAID},
vcembeds,
recp
);
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...")
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 [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 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 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
);
exn: [grant, atc],
};

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

console.log('... done!');
}
3 changes: 1 addition & 2 deletions 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, Ipex, 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,7 +417,6 @@ export class SignifyClient {
return new Credentials(this);
}


/**
* Get IPEX resource
* @returns {Ipex}
Expand Down
70 changes: 37 additions & 33 deletions src/keri/app/credentialing.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ export class CredentialResult {
}

get anc() {
return this._anc
return this._anc;
}

get sigs() {
Expand Down Expand Up @@ -165,7 +165,10 @@ export class Credentials {
let hab = await this.client.identifiers().get(name);
let pre: string = hab.prefix;

const dt = datetime === undefined ? new Date().toISOString().replace('Z', '000+00:00') : datetime;
const dt =
datetime === undefined
? new Date().toISOString().replace('Z', '000+00:00')
: datetime;

const vsacdc = versify(Ident.ACDC, undefined, Serials.JSON, 0);
const vs = versify(Ident.KERI, undefined, Serials.JSON, 0);
Expand Down Expand Up @@ -213,7 +216,7 @@ export class Credentials {
};

let [, iss] = Saider.saidify(_iss);
let iserder = new Serder(iss)
let iserder = new Serder(iss);

// Create paths and sign
let keeper = this.client!.manager!.get(hab);
Expand Down Expand Up @@ -255,9 +258,8 @@ export class Credentials {
ixn = anc.ked;
}

let res = this.issueFromEvents(hab,name, vc, iss, ixn, sigs)
return new CredentialResult(vc, iserder, anc, sigs, res)

let res = this.issueFromEvents(hab, name, vc, iss, ixn, sigs);
return new CredentialResult(vc, iserder, anc, sigs, res);
}

issueFromEvents(
Expand Down Expand Up @@ -696,7 +698,6 @@ export class Schemas {
}
}


/**
* Ipex
*/
Expand Down Expand Up @@ -731,32 +732,34 @@ export class Ipex {
message: string,
acdc: Serder,
iss: Serder,
anc:Serder,
anc: Serder,
atc: string,
agree?:string,
datetime?: string,
agree?: string,
datetime?: string
): Promise<[Serder, string[], string]> {
let hab = await this.client.identifiers().get(name);
let data: any = {
m: message,
i: recp
}
i: recp,
};

let embeds: any = {
acdc: [acdc, ''],
iss: [iss, ''],
anc: [anc, atc],
};

return this.client.exchanges().createExchangeMessage(
hab,
'/ipex/grant',
data,
embeds,
undefined,
datetime,
agree
);
return this.client
.exchanges()
.createExchangeMessage(
hab,
'/ipex/grant',
data,
embeds,
undefined,
datetime,
agree
);
}

/**
Expand All @@ -772,22 +775,23 @@ export class Ipex {
name: string,
message: string,
grant: string,
datetime?: string,
datetime?: string
): Promise<[Serder, string[], string]> {
let hab = await this.client.identifiers().get(name);
let data: any = {
m: message,
}
};

return this.client.exchanges().createExchangeMessage(
hab,
'/ipex/admit',
data,
{},
undefined,
datetime,
grant
);
return this.client
.exchanges()
.createExchangeMessage(
hab,
'/ipex/admit',
data,
{},
undefined,
datetime,
grant
);
}

}
Loading

0 comments on commit 6282052

Please sign in to comment.