From e306dbac7294191014c925f68a8670f32617754a Mon Sep 17 00:00:00 2001 From: pfeairheller Date: Mon, 16 Oct 2023 13:43:35 -0700 Subject: [PATCH] Added multisig sending IPEX grant EXN message. --- .../scripts/multisig-create-credential.ts | 29 ++++++++- src/keri/app/clienting.ts | 11 +++- src/keri/app/credentialing.ts | 65 +++++++++++++++++++ src/keri/app/exchanging.ts | 14 ++-- src/keri/core/eventing.ts | 4 +- 5 files changed, 115 insertions(+), 8 deletions(-) diff --git a/examples/scripts/multisig-create-credential.ts b/examples/scripts/multisig-create-credential.ts index 12b41780..052431c2 100644 --- a/examples/scripts/multisig-create-credential.ts +++ b/examples/scripts/multisig-create-credential.ts @@ -180,7 +180,7 @@ async function connect() { }; let holder = "ELjSFdrTdCebJlmvbFNX9-TLhR2PO0_60al1kQp5_e6k" - let TIME="2023-09-25T16:01:37.000000+00:00" + 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() @@ -215,5 +215,32 @@ async function connect() { 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!") } diff --git a/src/keri/app/clienting.ts b/src/keri/app/clienting.ts index 15dfa2a9..730c7417 100644 --- a/src/keri/app/clienting.ts +++ b/src/keri/app/clienting.ts @@ -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'; @@ -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} diff --git a/src/keri/app/credentialing.ts b/src/keri/app/credentialing.ts index 6ccbc816..a2b13733 100644 --- a/src/keri/app/credentialing.ts +++ b/src/keri/app/credentialing.ts @@ -695,3 +695,68 @@ export class Schemas { return await res.json(); } } + + +/** + * Ipex + */ + +export class Ipex { + client: SignifyClient; + /** + * Schemas + * @param {SignifyClient} client + */ + constructor(client: SignifyClient) { + this.client = client; + } + + /** + * Create an IPEX grant EXN message + * @async + * @param {string} name Name or alias of the identifier + * @param {string} recp qb64 AID of recipient of the grant + * @param {string} message accompany human readable description of the credential being issued + * @param {Serder} acdc Credential + * @param {Serder} iss TEL issuance event + * @param {Serder} anc Anchoring event + * @param {string} atc attachments for the anchoring event + * @param {string} agree Option qb64 SAID of agree message this grant is responding to + * @param {string} datetime Optional datetime to set for the credential + * @returns {Promise} A promise to the long-running operation + */ + async grant( + name: string, + recp: string, + message: string, + acdc: Serder, + iss: Serder, + anc:Serder, + atc: string, + agree?:string, + datetime?: string, + ): Promise<[Serder, string[], string]> { + let hab = await this.client.identifiers().get(name); + let data: any = { + m: message, + 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 + ); + } + +} diff --git a/src/keri/app/exchanging.ts b/src/keri/app/exchanging.ts index cf15306c..7f62dd53 100644 --- a/src/keri/app/exchanging.ts +++ b/src/keri/app/exchanging.ts @@ -28,21 +28,27 @@ export class Exchanges { * @param route * @param payload * @param embeds + * @param recipient + * @param datetime + * @param dig */ async createExchangeMessage( sender: Dict, route: string, payload: Dict, - embeds: Dict + embeds: Dict, + recipient?: string, + datetime?: string, + dig?: string ): Promise<[Serder, string[], string]> { let keeper = this.client.manager!.get(sender); let [exn, end] = exchange( route, payload, sender['prefix'], - undefined, - undefined, - undefined, + recipient, + datetime, + dig, undefined, embeds ); diff --git a/src/keri/core/eventing.ts b/src/keri/core/eventing.ts index 28ddad57..5983d01f 100644 --- a/src/keri/core/eventing.ts +++ b/src/keri/core/eventing.ts @@ -432,9 +432,9 @@ export function messagize( new Counter({ code: CtrDex.TransIdxSigGroups, count: 1 }) .qb64b ); - atc = concat(atc, seal.i.encode('utf-8')); + atc = concat(atc, new TextEncoder().encode(seal[1].i)); atc = concat(atc, new Seqner(seal[1].s).qb64b); - atc = concat(atc, seal.d.encode('utf-8')); + atc = concat(atc, new TextEncoder().encode(seal[1].d)); } else if (seal[0] == 'SealLast') { atc = concat( atc,