@0xpolygonid/js-sdk 1.10.0 → 1.10.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/browser/esm/index.js +185 -2
- package/dist/browser/esm/index.js.map +1 -1
- package/dist/browser/umd/index.js +187 -1
- package/dist/browser/umd/index.js.map +1 -1
- package/dist/node/cjs/iden3comm/constants.js +5 -1
- package/dist/node/cjs/iden3comm/handlers/credential-proposal.js +213 -0
- package/dist/node/cjs/iden3comm/handlers/index.js +1 -0
- package/dist/node/cjs/iden3comm/types/index.js +1 -0
- package/dist/node/cjs/iden3comm/types/protocol/proposal-request.js +2 -0
- package/dist/node/esm/iden3comm/constants.js +5 -1
- package/dist/node/esm/iden3comm/handlers/credential-proposal.js +184 -0
- package/dist/node/esm/iden3comm/handlers/index.js +1 -0
- package/dist/node/esm/iden3comm/types/index.js +1 -0
- package/dist/node/esm/iden3comm/types/protocol/proposal-request.js +1 -0
- package/dist/types/iden3comm/constants.d.ts +2 -0
- package/dist/types/iden3comm/handlers/credential-proposal.d.ts +112 -0
- package/dist/types/iden3comm/handlers/index.d.ts +1 -0
- package/dist/types/iden3comm/types/index.d.ts +1 -0
- package/dist/types/iden3comm/types/protocol/proposal-request.d.ts +35 -0
- package/package.json +1 -1
|
@@ -63028,7 +63028,11 @@ var PolygonIdSdk = (function (exports) {
|
|
|
63028
63028
|
// ContractInvokeRequestMessageType is type for request of contract invoke request
|
|
63029
63029
|
CONTRACT_INVOKE_REQUEST_MESSAGE_TYPE: IDEN3_PROTOCOL + 'proofs/1.0/contract-invoke-request',
|
|
63030
63030
|
// CredentialOnchainOfferMessageType is type of message with credential onchain offering
|
|
63031
|
-
CREDENTIAL_ONCHAIN_OFFER_MESSAGE_TYPE: IDEN3_PROTOCOL + 'credentials/1.0/onchain-offer'
|
|
63031
|
+
CREDENTIAL_ONCHAIN_OFFER_MESSAGE_TYPE: IDEN3_PROTOCOL + 'credentials/1.0/onchain-offer',
|
|
63032
|
+
// ProposalRequestMessageType is type for proposal-request message
|
|
63033
|
+
PROPOSAL_REQUEST_MESSAGE_TYPE: IDEN3_PROTOCOL + 'credentials/0.1/proposal-request',
|
|
63034
|
+
// ProposalMessageType is type for proposal message
|
|
63035
|
+
PROPOSAL_MESSAGE_TYPE: IDEN3_PROTOCOL + 'credentials/0.1/proposal'
|
|
63032
63036
|
});
|
|
63033
63037
|
/**
|
|
63034
63038
|
* Media types for iden3 comm communication protocol
|
|
@@ -87894,6 +87898,185 @@ var PolygonIdSdk = (function (exports) {
|
|
|
87894
87898
|
}
|
|
87895
87899
|
}
|
|
87896
87900
|
|
|
87901
|
+
/**
|
|
87902
|
+
* @beta
|
|
87903
|
+
* createProposalRequest is a function to create protocol proposal-request protocol message
|
|
87904
|
+
* @param {DID} sender - sender did
|
|
87905
|
+
* @param {DID} receiver - receiver did
|
|
87906
|
+
* @param {ProposalRequestCreationOptions} opts - creation options
|
|
87907
|
+
* @returns `Promise<ProposalRequestMessage>`
|
|
87908
|
+
*/
|
|
87909
|
+
function createProposalRequest(sender, receiver, opts) {
|
|
87910
|
+
const uuidv4 = v4();
|
|
87911
|
+
const request = {
|
|
87912
|
+
id: uuidv4,
|
|
87913
|
+
thid: uuidv4,
|
|
87914
|
+
from: sender.string(),
|
|
87915
|
+
to: receiver.string(),
|
|
87916
|
+
typ: MediaType.PlainMessage,
|
|
87917
|
+
type: PROTOCOL_MESSAGE_TYPE.PROPOSAL_REQUEST_MESSAGE_TYPE,
|
|
87918
|
+
body: opts
|
|
87919
|
+
};
|
|
87920
|
+
return request;
|
|
87921
|
+
}
|
|
87922
|
+
/**
|
|
87923
|
+
* @beta
|
|
87924
|
+
* createProposal is a function to create protocol proposal protocol message
|
|
87925
|
+
* @param {DID} sender - sender did
|
|
87926
|
+
* @param {DID} receiver - receiver did
|
|
87927
|
+
* @param {Proposal[]} proposals - proposals
|
|
87928
|
+
* @returns `Promise<ProposalRequestMessage>`
|
|
87929
|
+
*/
|
|
87930
|
+
function createProposal(sender, receiver, proposals) {
|
|
87931
|
+
const uuidv4 = v4();
|
|
87932
|
+
const request = {
|
|
87933
|
+
id: uuidv4,
|
|
87934
|
+
thid: uuidv4,
|
|
87935
|
+
from: sender.string(),
|
|
87936
|
+
to: receiver.string(),
|
|
87937
|
+
typ: MediaType.PlainMessage,
|
|
87938
|
+
type: PROTOCOL_MESSAGE_TYPE.PROPOSAL_MESSAGE_TYPE,
|
|
87939
|
+
body: {
|
|
87940
|
+
proposals: proposals || []
|
|
87941
|
+
}
|
|
87942
|
+
};
|
|
87943
|
+
return request;
|
|
87944
|
+
}
|
|
87945
|
+
/**
|
|
87946
|
+
*
|
|
87947
|
+
* Allows to process ProposalRequest protocol message
|
|
87948
|
+
* @beta
|
|
87949
|
+
* @class CredentialProposalHandler
|
|
87950
|
+
* @implements implements ICredentialProposalHandler interface
|
|
87951
|
+
*/
|
|
87952
|
+
class CredentialProposalHandler {
|
|
87953
|
+
/**
|
|
87954
|
+
* @beta Creates an instance of CredentialProposalHandler.
|
|
87955
|
+
* @param {IPackageManager} _packerMgr - package manager to unpack message envelope
|
|
87956
|
+
* @param {IIdentityWallet} _identityWallet - identity wallet
|
|
87957
|
+
* @param {CredentialProposalHandlerParams} _params - credential proposal handler params
|
|
87958
|
+
*
|
|
87959
|
+
*/
|
|
87960
|
+
constructor(_packerMgr, _identityWallet, _params) {
|
|
87961
|
+
this._packerMgr = _packerMgr;
|
|
87962
|
+
this._identityWallet = _identityWallet;
|
|
87963
|
+
this._params = _params;
|
|
87964
|
+
}
|
|
87965
|
+
/**
|
|
87966
|
+
* @inheritdoc ICredentialProposalHandler#parseProposalRequest
|
|
87967
|
+
*/
|
|
87968
|
+
async parseProposalRequest(request) {
|
|
87969
|
+
const { unpackedMessage: message } = await this._packerMgr.unpack(request);
|
|
87970
|
+
const proposalRequest = message;
|
|
87971
|
+
if (message.type !== PROTOCOL_MESSAGE_TYPE.PROPOSAL_REQUEST_MESSAGE_TYPE) {
|
|
87972
|
+
throw new Error('Invalid media type');
|
|
87973
|
+
}
|
|
87974
|
+
return proposalRequest;
|
|
87975
|
+
}
|
|
87976
|
+
/**
|
|
87977
|
+
* @inheritdoc ICredentialProposalHandler#handleProposalRequest
|
|
87978
|
+
*/
|
|
87979
|
+
async handleProposalRequest(request,
|
|
87980
|
+
//eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
87981
|
+
opts) {
|
|
87982
|
+
if (this._params.packerParams.mediaType === MediaType.SignedMessage &&
|
|
87983
|
+
!this._params.packerParams.packerOptions) {
|
|
87984
|
+
throw new Error(`jws packer options are required for ${MediaType.SignedMessage}`);
|
|
87985
|
+
}
|
|
87986
|
+
const proposalRequest = await this.parseProposalRequest(request);
|
|
87987
|
+
if (!proposalRequest.to) {
|
|
87988
|
+
throw new Error(`failed request. empty 'to' field`);
|
|
87989
|
+
}
|
|
87990
|
+
if (!proposalRequest.from) {
|
|
87991
|
+
throw new Error(`failed request. empty 'from' field`);
|
|
87992
|
+
}
|
|
87993
|
+
if (!proposalRequest.body?.credentials?.length) {
|
|
87994
|
+
throw new Error(`failed request. no 'credentials' in body`);
|
|
87995
|
+
}
|
|
87996
|
+
const senderDID = Z$2.parse(proposalRequest.from);
|
|
87997
|
+
let credOfferMessage = undefined;
|
|
87998
|
+
let proposalMessage = undefined;
|
|
87999
|
+
for (let i = 0; i < proposalRequest.body.credentials.length; i++) {
|
|
88000
|
+
const cred = proposalRequest.body.credentials[i];
|
|
88001
|
+
// check if there is credentials in the wallet
|
|
88002
|
+
let credsFromWallet = [];
|
|
88003
|
+
try {
|
|
88004
|
+
credsFromWallet = await this._identityWallet.findOwnedCredentialsByDID(senderDID, {
|
|
88005
|
+
type: cred.type,
|
|
88006
|
+
context: cred.context
|
|
88007
|
+
});
|
|
88008
|
+
}
|
|
88009
|
+
catch (e) {
|
|
88010
|
+
if (e.message !== 'no credential satisfied query') {
|
|
88011
|
+
throw e;
|
|
88012
|
+
}
|
|
88013
|
+
}
|
|
88014
|
+
if (credsFromWallet.length) {
|
|
88015
|
+
const guid = v4();
|
|
88016
|
+
if (!credOfferMessage) {
|
|
88017
|
+
credOfferMessage = {
|
|
88018
|
+
id: guid,
|
|
88019
|
+
typ: this._params.packerParams.mediaType,
|
|
88020
|
+
type: PROTOCOL_MESSAGE_TYPE.CREDENTIAL_OFFER_MESSAGE_TYPE,
|
|
88021
|
+
thid: proposalRequest.thid ?? guid,
|
|
88022
|
+
body: {
|
|
88023
|
+
url: this._params.agentUrl,
|
|
88024
|
+
credentials: []
|
|
88025
|
+
},
|
|
88026
|
+
from: proposalRequest.to,
|
|
88027
|
+
to: proposalRequest.from
|
|
88028
|
+
};
|
|
88029
|
+
}
|
|
88030
|
+
credOfferMessage.body.credentials.push(...credsFromWallet.map((c) => ({
|
|
88031
|
+
id: c.id,
|
|
88032
|
+
description: ''
|
|
88033
|
+
})));
|
|
88034
|
+
continue;
|
|
88035
|
+
}
|
|
88036
|
+
// credential not found in the wallet, prepare proposal protocol message
|
|
88037
|
+
const proposal = await this._params.proposalResolverFn(cred.context, cred.type);
|
|
88038
|
+
if (!proposal) {
|
|
88039
|
+
throw new Error(`can't resolve Proposal for type: ${cred.type}, context: ${cred.context}`);
|
|
88040
|
+
}
|
|
88041
|
+
if (!proposalMessage) {
|
|
88042
|
+
const guid = v4();
|
|
88043
|
+
proposalMessage = {
|
|
88044
|
+
id: guid,
|
|
88045
|
+
typ: this._params.packerParams.mediaType,
|
|
88046
|
+
type: PROTOCOL_MESSAGE_TYPE.PROPOSAL_MESSAGE_TYPE,
|
|
88047
|
+
thid: proposalRequest.thid ?? guid,
|
|
88048
|
+
body: {
|
|
88049
|
+
proposals: []
|
|
88050
|
+
},
|
|
88051
|
+
from: proposalRequest.to,
|
|
88052
|
+
to: proposalRequest.from
|
|
88053
|
+
};
|
|
88054
|
+
}
|
|
88055
|
+
proposalMessage.body?.proposals.push(proposal);
|
|
88056
|
+
}
|
|
88057
|
+
// if there is credentials in the wallet, return offer protocol message, otherwise proposal
|
|
88058
|
+
const response = byteEncoder.encode(JSON.stringify(proposalMessage ?? credOfferMessage));
|
|
88059
|
+
const packerOpts = this._params.packerParams.mediaType === MediaType.SignedMessage
|
|
88060
|
+
? this._params.packerParams.packerOptions
|
|
88061
|
+
: {
|
|
88062
|
+
provingMethodAlg: T.provingMethodGroth16AuthV2Instance.methodAlg
|
|
88063
|
+
};
|
|
88064
|
+
return this._packerMgr.pack(this._params.packerParams.mediaType, response, {
|
|
88065
|
+
senderDID,
|
|
88066
|
+
...packerOpts
|
|
88067
|
+
});
|
|
88068
|
+
}
|
|
88069
|
+
/**
|
|
88070
|
+
* @inheritdoc ICredentialProposalHandler#handleProposal
|
|
88071
|
+
*/
|
|
88072
|
+
async handleProposal(proposal, opts) {
|
|
88073
|
+
if (opts?.proposalRequest && opts.proposalRequest.from !== proposal.to) {
|
|
88074
|
+
throw new Error(`sender of the request is not a target of response - expected ${opts.proposalRequest.from}, given ${proposal.to}`);
|
|
88075
|
+
}
|
|
88076
|
+
return { proposal };
|
|
88077
|
+
}
|
|
88078
|
+
}
|
|
88079
|
+
|
|
87897
88080
|
exports.AbstractPrivateKeyStore = AbstractPrivateKeyStore;
|
|
87898
88081
|
exports.AgentResolver = AgentResolver;
|
|
87899
88082
|
exports.AtomicQueryMTPV2Inputs = AtomicQueryMTPV2Inputs;
|
|
@@ -87919,6 +88102,7 @@ var PolygonIdSdk = (function (exports) {
|
|
|
87919
88102
|
exports.CircuitClaim = CircuitClaim;
|
|
87920
88103
|
exports.CircuitStorage = CircuitStorage;
|
|
87921
88104
|
exports.ContractRequestHandler = ContractRequestHandler;
|
|
88105
|
+
exports.CredentialProposalHandler = CredentialProposalHandler;
|
|
87922
88106
|
exports.CredentialStatusPublisherRegistry = CredentialStatusPublisherRegistry;
|
|
87923
88107
|
exports.CredentialStatusResolverRegistry = CredentialStatusResolverRegistry;
|
|
87924
88108
|
exports.CredentialStorage = CredentialStorage;
|
|
@@ -88018,6 +88202,8 @@ var PolygonIdSdk = (function (exports) {
|
|
|
88018
88202
|
exports.core = index$1;
|
|
88019
88203
|
exports.createAuthorizationRequest = createAuthorizationRequest;
|
|
88020
88204
|
exports.createAuthorizationRequestWithMessage = createAuthorizationRequestWithMessage;
|
|
88205
|
+
exports.createProposal = createProposal;
|
|
88206
|
+
exports.createProposalRequest = createProposalRequest;
|
|
88021
88207
|
exports.createSchemaHash = createSchemaHash;
|
|
88022
88208
|
exports.createVerifiablePresentation = createVerifiablePresentation;
|
|
88023
88209
|
exports.credentialSubjectKey = credentialSubjectKey;
|