Skip to content

Commit babd7d3

Browse files
Merge branch 'main' into feat/accept-header
2 parents 1f6d6cd + 1e72293 commit babd7d3

File tree

11 files changed

+640
-755
lines changed

11 files changed

+640
-755
lines changed

package-lock.json

+518-678
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@0xpolygonid/js-sdk",
3-
"version": "1.17.6",
3+
"version": "1.17.9",
44
"description": "SDK to work with Polygon ID",
55
"main": "dist/node/cjs/index.js",
66
"module": "dist/node/esm/index.js",
@@ -89,9 +89,9 @@
8989
"peerDependencies": {
9090
"@iden3/js-crypto": "1.1.0",
9191
"@iden3/js-iden3-core": "1.4.0",
92-
"@iden3/js-jsonld-merklization": "1.3.1",
93-
"@iden3/js-jwz": "1.6.0",
94-
"@iden3/js-merkletree": "1.2.0",
92+
"@iden3/js-jsonld-merklization": "1.4.1",
93+
"@iden3/js-jwz": "1.7.1",
94+
"@iden3/js-merkletree": "1.3.1",
9595
"ffjavascript": "0.3.0",
9696
"rfc4648": "1.5.3",
9797
"snarkjs": "0.7.4"

src/circuits/models.ts

+28-39
Original file line numberDiff line numberDiff line change
@@ -53,45 +53,34 @@ export class Query {
5353
}
5454

5555
validateValueArraySize(maxArrSize: number): void {
56-
switch (this.values.length) {
57-
case 0: {
58-
const zeroArrSizeOps = [Operators.NOOP, Operators.SD, Operators.NULLIFY];
59-
if (!zeroArrSizeOps.includes(this.operator)) {
60-
throw new Error(CircuitError.InvalidValuesArrSize);
61-
}
62-
return;
63-
}
64-
case 1: {
65-
const oneArrSizeOps = [
66-
Operators.EQ,
67-
Operators.LT,
68-
Operators.GT,
69-
Operators.NE,
70-
Operators.LTE,
71-
Operators.GTE,
72-
Operators.EXISTS
73-
];
74-
if (!oneArrSizeOps.includes(this.operator)) {
75-
throw new Error(CircuitError.InvalidValuesArrSize);
76-
}
77-
return;
78-
}
79-
case 2: {
80-
const twoArrSizeOps = [Operators.BETWEEN, Operators.NONBETWEEN];
81-
if (!twoArrSizeOps.includes(this.operator)) {
82-
throw new Error(CircuitError.InvalidValuesArrSize);
83-
}
84-
return;
85-
}
86-
default: {
87-
const maxArrSizeOps = [Operators.IN, Operators.NIN];
88-
if (!maxArrSizeOps.includes(this.operator)) {
89-
throw new Error(CircuitError.InvalidOperationType);
90-
}
91-
if (!this.values.length || this.values.length > maxArrSize) {
92-
throw new Error(CircuitError.InvalidValuesArrSize);
93-
}
94-
}
56+
if (
57+
[Operators.NOOP, Operators.SD, Operators.NULLIFY].includes(this.operator) &&
58+
this.values.length !== 0
59+
) {
60+
throw new Error(CircuitError.InvalidValuesArrSize);
61+
} else if (
62+
[
63+
Operators.EQ,
64+
Operators.LT,
65+
Operators.GT,
66+
Operators.NE,
67+
Operators.LTE,
68+
Operators.GTE,
69+
Operators.EXISTS
70+
].includes(this.operator) &&
71+
this.values.length !== 1
72+
) {
73+
throw new Error(CircuitError.InvalidValuesArrSize);
74+
} else if (
75+
[Operators.BETWEEN, Operators.NONBETWEEN].includes(this.operator) &&
76+
this.values.length !== 2
77+
) {
78+
throw new Error(CircuitError.InvalidValuesArrSize);
79+
} else if (
80+
[Operators.IN, Operators.NIN].includes(this.operator) &&
81+
this.values.length > maxArrSize
82+
) {
83+
throw new Error(CircuitError.InvalidValuesArrSize);
9584
}
9685
}
9786
}

src/credentials/status/sparse-merkle-tree.ts

+3-16
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { CredentialStatus, RevocationStatus, Issuer } from '../../verifiable';
22
import { CredentialStatusResolver } from './resolver';
3-
import { Proof } from '@iden3/js-merkletree';
3+
import { Proof, ProofJSON } from '@iden3/js-merkletree';
44

55
/**
66
* IssuerResolver is a class that allows to interact with the issuer's http endpoint to get revocation status.
@@ -33,14 +33,7 @@ export class IssuerResolver implements CredentialStatusResolver {
3333
*/
3434
export interface RevocationStatusResponse {
3535
issuer: Issuer;
36-
mtp: {
37-
existence: boolean;
38-
siblings: string[];
39-
node_aux: {
40-
key: string;
41-
value: string;
42-
};
43-
};
36+
mtp: ProofJSON;
4437
}
4538

4639
/**
@@ -50,14 +43,8 @@ export interface RevocationStatusResponse {
5043
* @returns {RevocationStatus} RevocationStatus
5144
*/
5245
export const toRevocationStatus = ({ issuer, mtp }: RevocationStatusResponse): RevocationStatus => {
53-
const p = Proof.fromJSON({
54-
nodeAux: mtp.node_aux,
55-
existence: mtp.existence,
56-
siblings: mtp.siblings
57-
});
58-
5946
return {
60-
mtp: p,
47+
mtp: Proof.fromJSON(mtp),
6148
issuer
6249
};
6350
};

src/iden3comm/types/protocol/payment.ts

+7-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
import { BasicMessage } from '../';
2-
import { PaymentRequestDataType, PaymentRequestType, PaymentType } from '../../../verifiable';
2+
import {
3+
PaymentRequestDataType,
4+
PaymentRequestType,
5+
PaymentType,
6+
SupportedCurrencies
7+
} from '../../../verifiable';
38
import { PROTOCOL_MESSAGE_TYPE } from '../../constants';
49

510
/** @beta PaymentRequestMessage is struct the represents payment-request message */
@@ -33,7 +38,7 @@ export type PaymentRequestDataInfo = {
3338
id: string;
3439
chainId: string;
3540
address: string;
36-
currency: string;
41+
currency: SupportedCurrencies;
3742
signature?: string;
3843
};
3944

src/storage/blockchain/onchain-revocation.ts

+4-9
Original file line numberDiff line numberDiff line change
@@ -132,17 +132,12 @@ export class OnChainRevocationStorage {
132132
const siblings = mtp.siblings?.map((s) => s.toString());
133133

134134
if (mtp.auxExistence) {
135-
const auxIndex = BigInt(mtp.auxIndex.toString());
136-
const auxValue = BigInt(mtp.auxValue.toString());
137135
nodeAux = {
138-
key: auxIndex.toString(),
139-
value: auxValue.toString()
136+
key: mtp.auxIndex.toString(),
137+
value: mtp.auxValue.toString()
140138
};
141139
}
142-
return Proof.fromJSON({
143-
existence: mtp.existence,
144-
nodeAux,
145-
siblings
146-
});
140+
141+
return Proof.fromJSON({ existence: mtp.existence, node_aux: nodeAux, siblings });
147142
}
148143
}

src/verifiable/constants.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,8 @@ export enum PaymentType {
144144
* @enum {number}
145145
*/
146146
export enum SupportedCurrencies {
147-
ETH = 'ETH'
147+
ETH = 'ETH',
148+
MATIC = 'MATIC'
148149
}
149150

150151
/**

src/verifiable/credential.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ export class W3CCredential {
9696

9797
static fromJSON(obj: any): W3CCredential {
9898
const w = new W3CCredential();
99-
Object.assign(w, obj);
99+
Object.assign(w, structuredClone(obj));
100100
w.proof = Array.isArray(w.proof)
101101
? w.proof.map(W3CCredential.proofFromJSON)
102102
: W3CCredential.proofFromJSON(w.proof);

src/verifiable/proof.ts

+4-4
Original file line numberDiff line numberDiff line change
@@ -95,11 +95,11 @@ export class Iden3SparseMerkleTreeProof {
9595
Hash.fromString(JSON.stringify(h))
9696
);
9797
const allSiblings = Proof.buildAllSiblings(obj?.mtp?.depth, notEmpties, siblingsHashes);
98-
let nodeAux = undefined;
99-
if (obj.mtp.nodeAux) {
98+
let nodeAux = obj.mtp.nodeAux || obj.mtp.node_aux;
99+
if (nodeAux) {
100100
nodeAux = {
101-
key: Hash.fromString(JSON.stringify(obj.mtp.nodeAux.key)),
102-
value: Hash.fromString(JSON.stringify(obj.mtp.nodeAux.value))
101+
key: Hash.fromString(JSON.stringify(nodeAux.key)),
102+
value: Hash.fromString(JSON.stringify(nodeAux.value))
103103
};
104104
}
105105
mtp = new Proof({ existence: obj?.mtp.existence, nodeAux: nodeAux, siblings: allSiblings });

tests/credentials/credential-validation.test.ts

+68
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import {
1717
IdentityStorage,
1818
InMemoryMerkleTreeStorage,
1919
IStateStorage,
20+
JsonDocumentObject,
2021
Profile,
2122
RootInfo,
2223
StateInfo,
@@ -489,4 +490,71 @@ describe('Verify credential proof', () => {
489490
const isValid = await credential.verifyProof(ProofType.Iden3SparseMerkleTreeProof, resolverURL);
490491
expect(isValid).to.be.eq(true);
491492
});
493+
494+
it('W3CCredential.fromJSON deep copy', async () => {
495+
const credObject = {
496+
id: 'urn:uuid:0f2a2d08-65e5-11ef-bc4e-0a58a9feac02',
497+
'@context': [
498+
'https://www.w3.org/2018/credentials/v1',
499+
'https://schema.iden3.io/core/jsonld/iden3proofs.jsonld',
500+
'ipfs://QmfK8fsSz5UWm44p5eN9KjsTzi1YEsDCG1LHMFcW9T2Dbe'
501+
],
502+
type: ['VerifiableCredential', 'HowManyAttribute'],
503+
issuanceDate: '2024-08-29T08:59:54.82008584Z',
504+
credentialSubject: {
505+
id: 'did:polygonid:privado:test:3LD3n5edw91PGdNh329rqRydBdaQj2Zwrqf7u49gU2',
506+
type: 'HowManyAttribute',
507+
'att-1-string': 'string',
508+
'att-2-int': 22,
509+
'att-3-bool': false,
510+
'att-4-obj': {
511+
'att-bool': true,
512+
'att-int': 14,
513+
'att-string': 'string2'
514+
}
515+
},
516+
credentialStatus: {
517+
id: 'https://issuer-node-api-v2-test.privado.id/v1/agent',
518+
revocationNonce: 683471303,
519+
type: 'Iden3commRevocationStatusV1.0'
520+
},
521+
issuer: 'did:polygonid:polygon:amoy:2qUPgJsiQP8sdQuckFEj73bDRU84NYnmzwQJr5M1Fd',
522+
credentialSchema: {
523+
id: 'https://ipfs.io/ipfs/QmQvWV4BJqV16czvr2Cpc8qe5mGG51sii4YuDyMPjSxYp7',
524+
type: 'JsonSchema2023'
525+
},
526+
proof: [
527+
{
528+
type: 'BJJSignature2021',
529+
issuerData: {
530+
id: 'did:polygonid:polygon:amoy:2qUPgJsiQP8sdQuckFEj73bDRU84NYnmzwQJr5M1Fd',
531+
state: {
532+
claimsTreeRoot: '8a68b09bc81d49cea0e0a0f56990a0b3cb1bb55d963d309fb357356d7897140d',
533+
value: '1c44078aa45ec70bebbb98f525edf3177ccb516e12beffd84fbdbaf86ad2bc13'
534+
},
535+
authCoreClaim:
536+
'cca3371a6cb1b715004407e325bd993c000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000548961cf73cbd6b488027734ea8dc2dd913b15f2dccf2ce13c7bb1fad409cb1a0504589c8c855e1455cf136d2fd27a4c1cded8915633f8e36a06843ef753b21e0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000',
537+
mtp: {
538+
existence: true,
539+
siblings: []
540+
},
541+
credentialStatus: {
542+
id: 'https://issuer-node-api-v2-test.privado.id/v1/agent',
543+
revocationNonce: 0,
544+
type: 'Iden3commRevocationStatusV1.0',
545+
statusIssuer: null
546+
}
547+
},
548+
coreClaim:
549+
'31df932e35b3beef628544cf7d28dbcb2200000000000000000000000000000002a2c7b26f04aff4b573354055c1d44e3a35021a75ec5e941c10780719aa0b008489bda654ede194c8fbd7e82417f48813157f04fb917f3a4413be6209d338290000000000000000000000000000000000000000000000000000000000000000c7f1bc2800000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000',
550+
signature:
551+
'4732c4e4350b84087cd43f463bbf4103b1a3561659ae6fb144ba0e78657281233d393fbef1490ba7492c56f3f89fe7e08e47ddcffef20d02f4a40bddfde06702'
552+
}
553+
]
554+
};
555+
const cred = W3CCredential.fromJSON(credObject);
556+
delete (credObject.credentialSubject as JsonDocumentObject)['att-4-obj'];
557+
expect(cred.credentialSubject['att-4-obj']).not.to.be.eq(undefined);
558+
expect(cred.credentialSubject['att-4-obj']['att-bool']).to.be.eq(true);
559+
});
492560
});

tests/handlers/payment.test.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ describe('payment-request handler', () => {
136136
id: '12432',
137137
chainId: '80002',
138138
address: '0x2C2007d72f533FfD409F0D9f515983e95bF14992',
139-
currency: 'ETH'
139+
currency: SupportedCurrencies.ETH
140140
},
141141
expiration: '2125558127',
142142
description: 'payment-request integration test'

0 commit comments

Comments
 (0)