Skip to content

Commit

Permalink
Added multisig sending IPEX grant EXN message.
Browse files Browse the repository at this point in the history
  • Loading branch information
pfeairheller committed Oct 16, 2023
1 parent 4ee9eaf commit e306dba
Show file tree
Hide file tree
Showing 5 changed files with 115 additions and 8 deletions.
29 changes: 28 additions & 1 deletion examples/scripts/multisig-create-credential.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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!")
}
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
65 changes: 65 additions & 0 deletions src/keri/app/credentialing.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<any>} 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
);
}

}
14 changes: 10 additions & 4 deletions src/keri/app/exchanging.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,21 +28,27 @@ export class Exchanges {
* @param route
* @param payload
* @param embeds
* @param recipient
* @param datetime
* @param dig
*/
async createExchangeMessage(
sender: Dict<any>,
route: string,
payload: Dict<any>,
embeds: Dict<any>
embeds: Dict<any>,
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
);
Expand Down
4 changes: 2 additions & 2 deletions src/keri/core/eventing.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit e306dba

Please sign in to comment.