@0xpolygonid/js-sdk 1.17.1 → 1.17.2
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 +1290 -361
- package/dist/browser/esm/index.js.map +1 -1
- package/dist/browser/umd/index.js +1287 -358
- package/dist/browser/umd/index.js.map +1 -1
- package/dist/node/cjs/identity/identity-wallet.js +61 -35
- package/dist/node/cjs/storage/blockchain/state.js +1 -1
- package/dist/node/esm/identity/identity-wallet.js +61 -35
- package/dist/node/esm/storage/blockchain/state.js +1 -1
- package/dist/types/identity/identity-wallet.d.ts +1 -0
- package/package.json +2 -2
|
@@ -685,16 +685,8 @@ class IdentityWallet {
|
|
|
685
685
|
await this.updateIdentityState(did, true, newTreeState);
|
|
686
686
|
return txId;
|
|
687
687
|
}
|
|
688
|
-
|
|
689
|
-
|
|
690
|
-
) {
|
|
691
|
-
opts.seed = opts.seed ?? (0, js_crypto_1.getRandomBytes)(32);
|
|
692
|
-
opts.revocationOpts.nonce =
|
|
693
|
-
opts.revocationOpts.nonce ??
|
|
694
|
-
(isOldStateGenesis
|
|
695
|
-
? 0
|
|
696
|
-
: opts.revocationOpts.nonce ?? new DataView((0, js_crypto_1.getRandomBytes)(12).buffer).getUint32(0));
|
|
697
|
-
const { authClaim, pubKey } = await this.createAuthCoreClaim(opts.revocationOpts.nonce ?? 0, opts.seed);
|
|
688
|
+
async getAuthBJJCredential(did, oldTreeState, { nonce, seed, id, type }) {
|
|
689
|
+
const { authClaim, pubKey } = await this.createAuthCoreClaim(nonce, seed);
|
|
698
690
|
const { hi, hv } = authClaim.hiHv();
|
|
699
691
|
await this._storage.mt.addToMerkleTree(did.string(), storage_1.MerkleTreeType.Claims, hi, hv);
|
|
700
692
|
// Calculate current state after adding credential to merkle tree
|
|
@@ -704,34 +696,68 @@ class IdentityWallet {
|
|
|
704
696
|
oldTreeState.revocationRoot.bigInt(),
|
|
705
697
|
oldTreeState.rootOfRoots.bigInt()
|
|
706
698
|
]);
|
|
707
|
-
|
|
708
|
-
|
|
709
|
-
|
|
710
|
-
const credsWithIden3MTPProof = await this.generateIden3SparseMerkleTreeProof(did, [credential], txId, receipt?.blockNumber, block?.timestamp, undefined, {
|
|
711
|
-
revNonce: Number(authClaim.getRevocationNonce()),
|
|
712
|
-
subjectPosition: verifiable_1.SubjectPosition.None,
|
|
713
|
-
merklizedRootPosition: verifiable_1.MerklizedRootPosition.None,
|
|
714
|
-
updatable: false,
|
|
715
|
-
version: 0,
|
|
716
|
-
merklizeOpts: { documentLoader: (0, schema_processor_1.cacheLoader)() }
|
|
699
|
+
return this.createAuthBJJCredential(did, pubKey, authClaim, currentState, {
|
|
700
|
+
id,
|
|
701
|
+
type
|
|
717
702
|
});
|
|
718
|
-
|
|
719
|
-
|
|
720
|
-
|
|
721
|
-
|
|
722
|
-
|
|
723
|
-
|
|
703
|
+
}
|
|
704
|
+
/** {@inheritdoc IIdentityWallet.addBJJAuthCredential} */
|
|
705
|
+
async addBJJAuthCredential(did, oldTreeState, isOldStateGenesis, ethSigner, opts, prover // it will be needed in case of non ethereum identities
|
|
706
|
+
) {
|
|
707
|
+
opts.seed = opts.seed ?? (0, js_crypto_1.getRandomBytes)(32);
|
|
708
|
+
opts.revocationOpts.nonce =
|
|
709
|
+
opts.revocationOpts.nonce ??
|
|
710
|
+
(isOldStateGenesis
|
|
711
|
+
? 0
|
|
712
|
+
: opts.revocationOpts.nonce ?? new DataView((0, js_crypto_1.getRandomBytes)(12).buffer).getUint32(0));
|
|
713
|
+
const credential = await this.getAuthBJJCredential(did, oldTreeState, {
|
|
714
|
+
nonce: opts.revocationOpts.nonce,
|
|
715
|
+
seed: opts.seed,
|
|
716
|
+
id: opts.revocationOpts.id,
|
|
717
|
+
type: opts.revocationOpts.type
|
|
724
718
|
});
|
|
725
|
-
const
|
|
726
|
-
|
|
727
|
-
|
|
719
|
+
const addMtpToCredAndPublishRevState = async () => {
|
|
720
|
+
const { receipt, block } = await this._transactionService.getTransactionReceiptAndBlock(txId);
|
|
721
|
+
const credsWithIden3MTPProof = await this.generateIden3SparseMerkleTreeProof(did, [credential], txId, receipt?.blockNumber, block?.timestamp, undefined, {
|
|
722
|
+
revNonce: opts.revocationOpts.nonce ?? 0,
|
|
723
|
+
subjectPosition: verifiable_1.SubjectPosition.None,
|
|
724
|
+
merklizedRootPosition: verifiable_1.MerklizedRootPosition.None,
|
|
725
|
+
updatable: false,
|
|
726
|
+
version: 0,
|
|
727
|
+
merklizeOpts: { documentLoader: (0, schema_processor_1.cacheLoader)() }
|
|
728
|
+
});
|
|
729
|
+
await this._credentialWallet.saveAll(credsWithIden3MTPProof);
|
|
730
|
+
await this.publishRevocationInfoByCredentialStatusType(did, opts.revocationOpts.type, {
|
|
731
|
+
rhsUrl: opts.revocationOpts.id,
|
|
732
|
+
onChain: opts.revocationOpts.onChain
|
|
733
|
+
});
|
|
734
|
+
return credsWithIden3MTPProof[0];
|
|
735
|
+
};
|
|
736
|
+
let txId = '';
|
|
737
|
+
let attempt = 2;
|
|
738
|
+
do {
|
|
739
|
+
try {
|
|
740
|
+
txId = await this.transitState(did, oldTreeState, isOldStateGenesis, ethSigner, prover);
|
|
741
|
+
break;
|
|
742
|
+
}
|
|
743
|
+
catch (err) {
|
|
744
|
+
console.warn(`Error while transiting state, retrying state transition, attempt: ${attempt}`, err);
|
|
745
|
+
}
|
|
746
|
+
} while (--attempt);
|
|
747
|
+
if (!txId) {
|
|
748
|
+
const oldTransitStateInfoJson = JSON.stringify({
|
|
749
|
+
claimsRoot: oldTreeState.claimsRoot.hex(),
|
|
750
|
+
revocationRoot: oldTreeState.revocationRoot.hex(),
|
|
751
|
+
rootOfRoots: oldTreeState.rootOfRoots.hex(),
|
|
752
|
+
state: oldTreeState.state.hex(),
|
|
753
|
+
isOldStateGenesis,
|
|
754
|
+
credentialId: credential.id,
|
|
755
|
+
did: did.string()
|
|
756
|
+
}, null, 2);
|
|
757
|
+
await this._credentialWallet.save(credential);
|
|
758
|
+
throw new Error(`Error publishing state, info to publish: ${oldTransitStateInfoJson}`);
|
|
728
759
|
}
|
|
729
|
-
|
|
730
|
-
await this.publishRevocationInfoByCredentialStatusType(did, opts.revocationOpts.type, {
|
|
731
|
-
rhsUrl: opts.revocationOpts.id,
|
|
732
|
-
onChain: opts.revocationOpts.onChain
|
|
733
|
-
});
|
|
734
|
-
return credential;
|
|
760
|
+
return addMtpToCredAndPublishRevState();
|
|
735
761
|
}
|
|
736
762
|
}
|
|
737
763
|
exports.IdentityWallet = IdentityWallet;
|
|
@@ -185,7 +185,7 @@ class EthStateStorage {
|
|
|
185
185
|
const chainId = (0, js_iden3_core_1.getChainId)(js_iden3_core_1.DID.blockchainFromId(idTyped), js_iden3_core_1.DID.networkIdFromId(idTyped));
|
|
186
186
|
const config = this.networkByChainId(chainId);
|
|
187
187
|
const provider = new ethers_1.JsonRpcProvider(config.url);
|
|
188
|
-
const stateContract = new ethers_1.Contract(config.contractAddress, State_json_1.default,
|
|
188
|
+
const stateContract = new ethers_1.Contract(config.contractAddress, State_json_1.default, provider);
|
|
189
189
|
return { stateContract, provider };
|
|
190
190
|
}
|
|
191
191
|
networkByChainId(chainId) {
|
|
@@ -659,16 +659,8 @@ export class IdentityWallet {
|
|
|
659
659
|
await this.updateIdentityState(did, true, newTreeState);
|
|
660
660
|
return txId;
|
|
661
661
|
}
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
) {
|
|
665
|
-
opts.seed = opts.seed ?? getRandomBytes(32);
|
|
666
|
-
opts.revocationOpts.nonce =
|
|
667
|
-
opts.revocationOpts.nonce ??
|
|
668
|
-
(isOldStateGenesis
|
|
669
|
-
? 0
|
|
670
|
-
: opts.revocationOpts.nonce ?? new DataView(getRandomBytes(12).buffer).getUint32(0));
|
|
671
|
-
const { authClaim, pubKey } = await this.createAuthCoreClaim(opts.revocationOpts.nonce ?? 0, opts.seed);
|
|
662
|
+
async getAuthBJJCredential(did, oldTreeState, { nonce, seed, id, type }) {
|
|
663
|
+
const { authClaim, pubKey } = await this.createAuthCoreClaim(nonce, seed);
|
|
672
664
|
const { hi, hv } = authClaim.hiHv();
|
|
673
665
|
await this._storage.mt.addToMerkleTree(did.string(), MerkleTreeType.Claims, hi, hv);
|
|
674
666
|
// Calculate current state after adding credential to merkle tree
|
|
@@ -678,33 +670,67 @@ export class IdentityWallet {
|
|
|
678
670
|
oldTreeState.revocationRoot.bigInt(),
|
|
679
671
|
oldTreeState.rootOfRoots.bigInt()
|
|
680
672
|
]);
|
|
681
|
-
|
|
682
|
-
|
|
683
|
-
|
|
684
|
-
const credsWithIden3MTPProof = await this.generateIden3SparseMerkleTreeProof(did, [credential], txId, receipt?.blockNumber, block?.timestamp, undefined, {
|
|
685
|
-
revNonce: Number(authClaim.getRevocationNonce()),
|
|
686
|
-
subjectPosition: SubjectPosition.None,
|
|
687
|
-
merklizedRootPosition: MerklizedRootPosition.None,
|
|
688
|
-
updatable: false,
|
|
689
|
-
version: 0,
|
|
690
|
-
merklizeOpts: { documentLoader: cacheLoader() }
|
|
673
|
+
return this.createAuthBJJCredential(did, pubKey, authClaim, currentState, {
|
|
674
|
+
id,
|
|
675
|
+
type
|
|
691
676
|
});
|
|
692
|
-
|
|
693
|
-
|
|
694
|
-
|
|
695
|
-
|
|
696
|
-
|
|
697
|
-
|
|
677
|
+
}
|
|
678
|
+
/** {@inheritdoc IIdentityWallet.addBJJAuthCredential} */
|
|
679
|
+
async addBJJAuthCredential(did, oldTreeState, isOldStateGenesis, ethSigner, opts, prover // it will be needed in case of non ethereum identities
|
|
680
|
+
) {
|
|
681
|
+
opts.seed = opts.seed ?? getRandomBytes(32);
|
|
682
|
+
opts.revocationOpts.nonce =
|
|
683
|
+
opts.revocationOpts.nonce ??
|
|
684
|
+
(isOldStateGenesis
|
|
685
|
+
? 0
|
|
686
|
+
: opts.revocationOpts.nonce ?? new DataView(getRandomBytes(12).buffer).getUint32(0));
|
|
687
|
+
const credential = await this.getAuthBJJCredential(did, oldTreeState, {
|
|
688
|
+
nonce: opts.revocationOpts.nonce,
|
|
689
|
+
seed: opts.seed,
|
|
690
|
+
id: opts.revocationOpts.id,
|
|
691
|
+
type: opts.revocationOpts.type
|
|
698
692
|
});
|
|
699
|
-
const
|
|
700
|
-
|
|
701
|
-
|
|
693
|
+
const addMtpToCredAndPublishRevState = async () => {
|
|
694
|
+
const { receipt, block } = await this._transactionService.getTransactionReceiptAndBlock(txId);
|
|
695
|
+
const credsWithIden3MTPProof = await this.generateIden3SparseMerkleTreeProof(did, [credential], txId, receipt?.blockNumber, block?.timestamp, undefined, {
|
|
696
|
+
revNonce: opts.revocationOpts.nonce ?? 0,
|
|
697
|
+
subjectPosition: SubjectPosition.None,
|
|
698
|
+
merklizedRootPosition: MerklizedRootPosition.None,
|
|
699
|
+
updatable: false,
|
|
700
|
+
version: 0,
|
|
701
|
+
merklizeOpts: { documentLoader: cacheLoader() }
|
|
702
|
+
});
|
|
703
|
+
await this._credentialWallet.saveAll(credsWithIden3MTPProof);
|
|
704
|
+
await this.publishRevocationInfoByCredentialStatusType(did, opts.revocationOpts.type, {
|
|
705
|
+
rhsUrl: opts.revocationOpts.id,
|
|
706
|
+
onChain: opts.revocationOpts.onChain
|
|
707
|
+
});
|
|
708
|
+
return credsWithIden3MTPProof[0];
|
|
709
|
+
};
|
|
710
|
+
let txId = '';
|
|
711
|
+
let attempt = 2;
|
|
712
|
+
do {
|
|
713
|
+
try {
|
|
714
|
+
txId = await this.transitState(did, oldTreeState, isOldStateGenesis, ethSigner, prover);
|
|
715
|
+
break;
|
|
716
|
+
}
|
|
717
|
+
catch (err) {
|
|
718
|
+
console.warn(`Error while transiting state, retrying state transition, attempt: ${attempt}`, err);
|
|
719
|
+
}
|
|
720
|
+
} while (--attempt);
|
|
721
|
+
if (!txId) {
|
|
722
|
+
const oldTransitStateInfoJson = JSON.stringify({
|
|
723
|
+
claimsRoot: oldTreeState.claimsRoot.hex(),
|
|
724
|
+
revocationRoot: oldTreeState.revocationRoot.hex(),
|
|
725
|
+
rootOfRoots: oldTreeState.rootOfRoots.hex(),
|
|
726
|
+
state: oldTreeState.state.hex(),
|
|
727
|
+
isOldStateGenesis,
|
|
728
|
+
credentialId: credential.id,
|
|
729
|
+
did: did.string()
|
|
730
|
+
}, null, 2);
|
|
731
|
+
await this._credentialWallet.save(credential);
|
|
732
|
+
throw new Error(`Error publishing state, info to publish: ${oldTransitStateInfoJson}`);
|
|
702
733
|
}
|
|
703
|
-
|
|
704
|
-
await this.publishRevocationInfoByCredentialStatusType(did, opts.revocationOpts.type, {
|
|
705
|
-
rhsUrl: opts.revocationOpts.id,
|
|
706
|
-
onChain: opts.revocationOpts.onChain
|
|
707
|
-
});
|
|
708
|
-
return credential;
|
|
734
|
+
return addMtpToCredAndPublishRevState();
|
|
709
735
|
}
|
|
710
736
|
}
|
|
@@ -179,7 +179,7 @@ export class EthStateStorage {
|
|
|
179
179
|
const chainId = getChainId(DID.blockchainFromId(idTyped), DID.networkIdFromId(idTyped));
|
|
180
180
|
const config = this.networkByChainId(chainId);
|
|
181
181
|
const provider = new JsonRpcProvider(config.url);
|
|
182
|
-
const stateContract = new Contract(config.contractAddress, abi,
|
|
182
|
+
const stateContract = new Contract(config.contractAddress, abi, provider);
|
|
183
183
|
return { stateContract, provider };
|
|
184
184
|
}
|
|
185
185
|
networkByChainId(chainId) {
|
|
@@ -444,6 +444,7 @@ export declare class IdentityWallet implements IIdentityWallet {
|
|
|
444
444
|
updateIdentityState(issuerDID: DID, published: boolean, treeState?: TreeState): Promise<void>;
|
|
445
445
|
/** {@inheritdoc IIdentityWallet.transitState} */
|
|
446
446
|
transitState(did: DID, oldTreeState: TreeState, isOldStateGenesis: boolean, ethSigner: Signer, prover?: IZKProver): Promise<string>;
|
|
447
|
+
private getAuthBJJCredential;
|
|
447
448
|
/** {@inheritdoc IIdentityWallet.addBJJAuthCredential} */
|
|
448
449
|
addBJJAuthCredential(did: DID, oldTreeState: TreeState, isOldStateGenesis: boolean, ethSigner: Signer, opts: AuthBJJCredentialCreationOptions, prover?: IZKProver): Promise<W3CCredential>;
|
|
449
450
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@0xpolygonid/js-sdk",
|
|
3
|
-
"version": "1.17.
|
|
3
|
+
"version": "1.17.2",
|
|
4
4
|
"description": "SDK to work with Polygon ID",
|
|
5
5
|
"main": "dist/node/cjs/index.js",
|
|
6
6
|
"module": "dist/node/esm/index.js",
|
|
@@ -101,7 +101,7 @@
|
|
|
101
101
|
"ajv-formats": "2.1.1",
|
|
102
102
|
"did-jwt": "8.0.4",
|
|
103
103
|
"did-resolver": "4.1.0",
|
|
104
|
-
"ethers": "6.
|
|
104
|
+
"ethers": "^6.13.1",
|
|
105
105
|
"idb-keyval": "6.2.0",
|
|
106
106
|
"js-sha3": "0.9.3",
|
|
107
107
|
"jsonld": "8.3.1",
|