@docknetwork/wallet-sdk-web 1.7.8 → 1.7.9
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/README.md +15 -0
- package/dist/wallet-sdk-web.esm.js +88 -16
- package/dist/wallet-sdk-web.iife.js +88 -16
- package/dist/wallet-sdk-web.iife.min.js +2 -2
- package/package.json +2 -4
- package/src/index.js +17 -1
package/README.md
CHANGED
|
@@ -113,6 +113,21 @@ const credential = await wallet.addCredential('openid-credential-offer://...');
|
|
|
113
113
|
|
|
114
114
|
---
|
|
115
115
|
|
|
116
|
+
### `removeCredential`
|
|
117
|
+
|
|
118
|
+
Remove a credential from the wallet by its ID.
|
|
119
|
+
|
|
120
|
+
```javascript
|
|
121
|
+
await wallet.removeCredential('https://creds-testnet.truvera.io/credential-id');
|
|
122
|
+
```
|
|
123
|
+
|
|
124
|
+
**Parameters**:
|
|
125
|
+
- `credentialId` (string): The ID of the credential to remove.
|
|
126
|
+
|
|
127
|
+
**Returns**: `Promise<void>`
|
|
128
|
+
|
|
129
|
+
---
|
|
130
|
+
|
|
116
131
|
### `getDID`
|
|
117
132
|
|
|
118
133
|
Get the default Decentralized Identifier (DID) associated with the wallet.
|
|
@@ -570651,16 +570651,20 @@ const attributesToSkip$1 = [/^type/, /^issuer/, /^@context/, /^proof/, /^credent
|
|
|
570651
570651
|
const shouldSkipAttribute$1 = attributeName => attributesToSkip$1.some(regex => regex.test(attributeName));
|
|
570652
570652
|
function getPexRequiredAttributes$1(pexRequest) {
|
|
570653
570653
|
let selectedCredentials = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : [];
|
|
570654
|
-
|
|
570655
|
-
|
|
570654
|
+
// Match each credential to its best-fitting descriptor by checking which
|
|
570655
|
+
// descriptor's fields exist in the credential, rather than relying on
|
|
570656
|
+
// positional index. This allows credentials to be provided in any order.
|
|
570657
|
+
return selectedCredentials.map((credential, credIdx) => {
|
|
570658
|
+
const matchedDescriptor = findMatchingDescriptor(pexRequest.input_descriptors, credential);
|
|
570659
|
+
if (!matchedDescriptor) {
|
|
570660
|
+
return [];
|
|
570661
|
+
}
|
|
570662
|
+
return matchedDescriptor.constraints.fields.filter(field => {
|
|
570656
570663
|
if (field.filter || field.optional) {
|
|
570657
570664
|
return false;
|
|
570658
570665
|
}
|
|
570659
570666
|
try {
|
|
570660
|
-
|
|
570661
|
-
return false;
|
|
570662
|
-
}
|
|
570663
|
-
const paths = Array.isArray(field.path) ? field.path.flatMap(singlePath => JSONPath.paths(selectedCredentials[index], singlePath)) : JSONPath.paths(selectedCredentials[index], field.path);
|
|
570667
|
+
const paths = Array.isArray(field.path) ? field.path.flatMap(singlePath => JSONPath.paths(credential, singlePath)) : JSONPath.paths(credential, field.path);
|
|
570664
570668
|
return paths.length !== 0;
|
|
570665
570669
|
} catch (error) {
|
|
570666
570670
|
console.error("Error in field ".concat(field.path, ": ").concat(error.message));
|
|
@@ -570669,11 +570673,46 @@ function getPexRequiredAttributes$1(pexRequest) {
|
|
|
570669
570673
|
}).map(field => getAttributeName$1({
|
|
570670
570674
|
field,
|
|
570671
570675
|
selectedCredentials,
|
|
570672
|
-
index
|
|
570676
|
+
index: credIdx
|
|
570673
570677
|
})).filter(attributeName => {
|
|
570674
570678
|
return !shouldSkipAttribute$1(attributeName);
|
|
570675
570679
|
});
|
|
570676
|
-
})
|
|
570680
|
+
});
|
|
570681
|
+
}
|
|
570682
|
+
function findMatchingDescriptor(inputDescriptors, credential) {
|
|
570683
|
+
let bestMatch = null;
|
|
570684
|
+
let bestScore = -1;
|
|
570685
|
+
for (const descriptor of inputDescriptors) {
|
|
570686
|
+
var _descriptor$constrain;
|
|
570687
|
+
const fields = ((_descriptor$constrain = descriptor.constraints) === null || _descriptor$constrain === void 0 ? void 0 : _descriptor$constrain.fields) || [];
|
|
570688
|
+
if (fields.length === 0) {
|
|
570689
|
+
continue;
|
|
570690
|
+
}
|
|
570691
|
+
let matched = 0;
|
|
570692
|
+
for (const field of fields) {
|
|
570693
|
+
try {
|
|
570694
|
+
const fieldPaths = Array.isArray(field.path) ? field.path : [field.path];
|
|
570695
|
+
for (const p of fieldPaths) {
|
|
570696
|
+
const paths = JSONPath.paths(credential, p);
|
|
570697
|
+
if (paths.length > 0) {
|
|
570698
|
+
matched++;
|
|
570699
|
+
break;
|
|
570700
|
+
}
|
|
570701
|
+
}
|
|
570702
|
+
} catch (_unused) {
|
|
570703
|
+
// ignore
|
|
570704
|
+
}
|
|
570705
|
+
}
|
|
570706
|
+
|
|
570707
|
+
// Use match ratio so descriptors where all fields match score higher
|
|
570708
|
+
// than descriptors where only generic fields (e.g. issuer) match
|
|
570709
|
+
const score = matched / fields.length;
|
|
570710
|
+
if (score > bestScore) {
|
|
570711
|
+
bestScore = score;
|
|
570712
|
+
bestMatch = descriptor;
|
|
570713
|
+
}
|
|
570714
|
+
}
|
|
570715
|
+
return bestMatch;
|
|
570677
570716
|
}
|
|
570678
570717
|
|
|
570679
570718
|
/**
|
|
@@ -672614,7 +672653,7 @@ async function resolveProvingKeyConfig({
|
|
|
672614
672653
|
}
|
|
672615
672654
|
|
|
672616
672655
|
const blockchainCache = new Map();
|
|
672617
|
-
|
|
672656
|
+
let WITNESS_CACHE_TTL = 120000; // 2 minutes
|
|
672618
672657
|
async function fetchBlockchainData(credential, _membershipWitness) {
|
|
672619
672658
|
let witness = _membershipWitness;
|
|
672620
672659
|
let blockNo;
|
|
@@ -672665,8 +672704,12 @@ const getWitnessDetails = async (credential, _membershipWitness) => {
|
|
|
672665
672704
|
let rawData;
|
|
672666
672705
|
if (cacheKey) {
|
|
672667
672706
|
const cached = blockchainCache.get(cacheKey);
|
|
672668
|
-
if (cached
|
|
672669
|
-
|
|
672707
|
+
if (cached) {
|
|
672708
|
+
if (Date.now() - cached.timestamp < WITNESS_CACHE_TTL) {
|
|
672709
|
+
rawData = cached.data;
|
|
672710
|
+
} else {
|
|
672711
|
+
blockchainCache.delete(cacheKey);
|
|
672712
|
+
}
|
|
672670
672713
|
}
|
|
672671
672714
|
}
|
|
672672
672715
|
if (!rawData) {
|
|
@@ -675585,6 +675628,7 @@ class CredentialService {
|
|
|
675585
675628
|
* });
|
|
675586
675629
|
*/
|
|
675587
675630
|
async deriveVCFromPresentation(params) {
|
|
675631
|
+
var _proofRequest$request, _filteredProofRequest;
|
|
675588
675632
|
validation$5.deriveVCFromPresentation(params);
|
|
675589
675633
|
const {
|
|
675590
675634
|
credentials,
|
|
@@ -675606,22 +675650,37 @@ class CredentialService {
|
|
|
675606
675650
|
resolver: blockchainService.resolver
|
|
675607
675651
|
});
|
|
675608
675652
|
}
|
|
675609
|
-
|
|
675653
|
+
|
|
675654
|
+
// Filter proof request descriptors to only those matching the provided
|
|
675655
|
+
// credentials. This ensures correct mapping when credentials are provided
|
|
675656
|
+
// in a different order than the proof request's input_descriptors.
|
|
675657
|
+
let filteredProofRequest = proofRequest;
|
|
675658
|
+
if ((proofRequest === null || proofRequest === void 0 || (_proofRequest$request = proofRequest.request) === null || _proofRequest$request === void 0 || (_proofRequest$request = _proofRequest$request.input_descriptors) === null || _proofRequest$request === void 0 ? void 0 : _proofRequest$request.length) > 1) {
|
|
675659
|
+
const matchedDescriptors = selectedCredentials.map(credential => findMatchingDescriptor(proofRequest.request.input_descriptors, credential)).filter(Boolean);
|
|
675660
|
+
if (matchedDescriptors.length > 0) {
|
|
675661
|
+
filteredProofRequest = _objectSpread2(_objectSpread2({}, proofRequest), {}, {
|
|
675662
|
+
request: _objectSpread2(_objectSpread2({}, proofRequest.request), {}, {
|
|
675663
|
+
input_descriptors: matchedDescriptors
|
|
675664
|
+
})
|
|
675665
|
+
});
|
|
675666
|
+
}
|
|
675667
|
+
}
|
|
675668
|
+
if (filteredProofRequest && hasProvingKey(filteredProofRequest)) {
|
|
675610
675669
|
const {
|
|
675611
675670
|
provingKey,
|
|
675612
675671
|
provingKeyId
|
|
675613
|
-
} = await fetchProvingKey(
|
|
675672
|
+
} = await fetchProvingKey(filteredProofRequest);
|
|
675614
675673
|
descriptorBounds = applyEnforceBounds$1({
|
|
675615
675674
|
builder: presentation.presBuilder,
|
|
675616
|
-
proofRequest,
|
|
675675
|
+
proofRequest: filteredProofRequest,
|
|
675617
675676
|
provingKey,
|
|
675618
675677
|
provingKeyId,
|
|
675619
675678
|
selectedCredentials
|
|
675620
675679
|
});
|
|
675621
675680
|
}
|
|
675622
675681
|
let pexRequiredAttributes = [];
|
|
675623
|
-
if (
|
|
675624
|
-
pexRequiredAttributes = getPexRequiredAttributes$1(
|
|
675682
|
+
if ((_filteredProofRequest = filteredProofRequest) !== null && _filteredProofRequest !== void 0 && _filteredProofRequest.request) {
|
|
675683
|
+
pexRequiredAttributes = getPexRequiredAttributes$1(filteredProofRequest.request, selectedCredentials);
|
|
675625
675684
|
}
|
|
675626
675685
|
let idx = 0;
|
|
675627
675686
|
for (const {
|
|
@@ -681995,6 +682054,19 @@ async function initialize(_ref) {
|
|
|
681995
682054
|
throw new Error("Failed to retrieve default DID: ".concat(error.message));
|
|
681996
682055
|
}
|
|
681997
682056
|
},
|
|
682057
|
+
/**
|
|
682058
|
+
* Removes a credential from the wallet.
|
|
682059
|
+
*
|
|
682060
|
+
* @async
|
|
682061
|
+
* @param {string} credentialId - The ID of the credential to remove
|
|
682062
|
+
* @returns {Promise<void>}
|
|
682063
|
+
*/
|
|
682064
|
+
removeCredential: async credentialId => {
|
|
682065
|
+
if (!credentialId || typeof credentialId !== 'string') {
|
|
682066
|
+
throw new Error('Invalid credentialId: Must be a non-empty string');
|
|
682067
|
+
}
|
|
682068
|
+
return await credentialProvider.removeCredential(credentialId);
|
|
682069
|
+
},
|
|
681998
682070
|
/**
|
|
681999
682071
|
* Creates a verifiable presentation for a given proof request.
|
|
682000
682072
|
*
|
|
@@ -570658,16 +570658,20 @@ zoo`.split('\n');
|
|
|
570658
570658
|
const shouldSkipAttribute$1 = attributeName => attributesToSkip$1.some(regex => regex.test(attributeName));
|
|
570659
570659
|
function getPexRequiredAttributes$1(pexRequest) {
|
|
570660
570660
|
let selectedCredentials = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : [];
|
|
570661
|
-
|
|
570662
|
-
|
|
570661
|
+
// Match each credential to its best-fitting descriptor by checking which
|
|
570662
|
+
// descriptor's fields exist in the credential, rather than relying on
|
|
570663
|
+
// positional index. This allows credentials to be provided in any order.
|
|
570664
|
+
return selectedCredentials.map((credential, credIdx) => {
|
|
570665
|
+
const matchedDescriptor = findMatchingDescriptor(pexRequest.input_descriptors, credential);
|
|
570666
|
+
if (!matchedDescriptor) {
|
|
570667
|
+
return [];
|
|
570668
|
+
}
|
|
570669
|
+
return matchedDescriptor.constraints.fields.filter(field => {
|
|
570663
570670
|
if (field.filter || field.optional) {
|
|
570664
570671
|
return false;
|
|
570665
570672
|
}
|
|
570666
570673
|
try {
|
|
570667
|
-
|
|
570668
|
-
return false;
|
|
570669
|
-
}
|
|
570670
|
-
const paths = Array.isArray(field.path) ? field.path.flatMap(singlePath => JSONPath.paths(selectedCredentials[index], singlePath)) : JSONPath.paths(selectedCredentials[index], field.path);
|
|
570674
|
+
const paths = Array.isArray(field.path) ? field.path.flatMap(singlePath => JSONPath.paths(credential, singlePath)) : JSONPath.paths(credential, field.path);
|
|
570671
570675
|
return paths.length !== 0;
|
|
570672
570676
|
} catch (error) {
|
|
570673
570677
|
console.error("Error in field ".concat(field.path, ": ").concat(error.message));
|
|
@@ -570676,11 +570680,46 @@ zoo`.split('\n');
|
|
|
570676
570680
|
}).map(field => getAttributeName$1({
|
|
570677
570681
|
field,
|
|
570678
570682
|
selectedCredentials,
|
|
570679
|
-
index
|
|
570683
|
+
index: credIdx
|
|
570680
570684
|
})).filter(attributeName => {
|
|
570681
570685
|
return !shouldSkipAttribute$1(attributeName);
|
|
570682
570686
|
});
|
|
570683
|
-
})
|
|
570687
|
+
});
|
|
570688
|
+
}
|
|
570689
|
+
function findMatchingDescriptor(inputDescriptors, credential) {
|
|
570690
|
+
let bestMatch = null;
|
|
570691
|
+
let bestScore = -1;
|
|
570692
|
+
for (const descriptor of inputDescriptors) {
|
|
570693
|
+
var _descriptor$constrain;
|
|
570694
|
+
const fields = ((_descriptor$constrain = descriptor.constraints) === null || _descriptor$constrain === void 0 ? void 0 : _descriptor$constrain.fields) || [];
|
|
570695
|
+
if (fields.length === 0) {
|
|
570696
|
+
continue;
|
|
570697
|
+
}
|
|
570698
|
+
let matched = 0;
|
|
570699
|
+
for (const field of fields) {
|
|
570700
|
+
try {
|
|
570701
|
+
const fieldPaths = Array.isArray(field.path) ? field.path : [field.path];
|
|
570702
|
+
for (const p of fieldPaths) {
|
|
570703
|
+
const paths = JSONPath.paths(credential, p);
|
|
570704
|
+
if (paths.length > 0) {
|
|
570705
|
+
matched++;
|
|
570706
|
+
break;
|
|
570707
|
+
}
|
|
570708
|
+
}
|
|
570709
|
+
} catch (_unused) {
|
|
570710
|
+
// ignore
|
|
570711
|
+
}
|
|
570712
|
+
}
|
|
570713
|
+
|
|
570714
|
+
// Use match ratio so descriptors where all fields match score higher
|
|
570715
|
+
// than descriptors where only generic fields (e.g. issuer) match
|
|
570716
|
+
const score = matched / fields.length;
|
|
570717
|
+
if (score > bestScore) {
|
|
570718
|
+
bestScore = score;
|
|
570719
|
+
bestMatch = descriptor;
|
|
570720
|
+
}
|
|
570721
|
+
}
|
|
570722
|
+
return bestMatch;
|
|
570684
570723
|
}
|
|
570685
570724
|
|
|
570686
570725
|
/**
|
|
@@ -672621,7 +672660,7 @@ zoo`.split('\n');
|
|
|
672621
672660
|
}
|
|
672622
672661
|
|
|
672623
672662
|
const blockchainCache = new Map();
|
|
672624
|
-
|
|
672663
|
+
let WITNESS_CACHE_TTL = 120000; // 2 minutes
|
|
672625
672664
|
async function fetchBlockchainData(credential, _membershipWitness) {
|
|
672626
672665
|
let witness = _membershipWitness;
|
|
672627
672666
|
let blockNo;
|
|
@@ -672672,8 +672711,12 @@ zoo`.split('\n');
|
|
|
672672
672711
|
let rawData;
|
|
672673
672712
|
if (cacheKey) {
|
|
672674
672713
|
const cached = blockchainCache.get(cacheKey);
|
|
672675
|
-
if (cached
|
|
672676
|
-
|
|
672714
|
+
if (cached) {
|
|
672715
|
+
if (Date.now() - cached.timestamp < WITNESS_CACHE_TTL) {
|
|
672716
|
+
rawData = cached.data;
|
|
672717
|
+
} else {
|
|
672718
|
+
blockchainCache.delete(cacheKey);
|
|
672719
|
+
}
|
|
672677
672720
|
}
|
|
672678
672721
|
}
|
|
672679
672722
|
if (!rawData) {
|
|
@@ -675592,6 +675635,7 @@ zoo`.split('\n');
|
|
|
675592
675635
|
* });
|
|
675593
675636
|
*/
|
|
675594
675637
|
async deriveVCFromPresentation(params) {
|
|
675638
|
+
var _proofRequest$request, _filteredProofRequest;
|
|
675595
675639
|
validation$5.deriveVCFromPresentation(params);
|
|
675596
675640
|
const {
|
|
675597
675641
|
credentials,
|
|
@@ -675613,22 +675657,37 @@ zoo`.split('\n');
|
|
|
675613
675657
|
resolver: blockchainService.resolver
|
|
675614
675658
|
});
|
|
675615
675659
|
}
|
|
675616
|
-
|
|
675660
|
+
|
|
675661
|
+
// Filter proof request descriptors to only those matching the provided
|
|
675662
|
+
// credentials. This ensures correct mapping when credentials are provided
|
|
675663
|
+
// in a different order than the proof request's input_descriptors.
|
|
675664
|
+
let filteredProofRequest = proofRequest;
|
|
675665
|
+
if ((proofRequest === null || proofRequest === void 0 || (_proofRequest$request = proofRequest.request) === null || _proofRequest$request === void 0 || (_proofRequest$request = _proofRequest$request.input_descriptors) === null || _proofRequest$request === void 0 ? void 0 : _proofRequest$request.length) > 1) {
|
|
675666
|
+
const matchedDescriptors = selectedCredentials.map(credential => findMatchingDescriptor(proofRequest.request.input_descriptors, credential)).filter(Boolean);
|
|
675667
|
+
if (matchedDescriptors.length > 0) {
|
|
675668
|
+
filteredProofRequest = _objectSpread2(_objectSpread2({}, proofRequest), {}, {
|
|
675669
|
+
request: _objectSpread2(_objectSpread2({}, proofRequest.request), {}, {
|
|
675670
|
+
input_descriptors: matchedDescriptors
|
|
675671
|
+
})
|
|
675672
|
+
});
|
|
675673
|
+
}
|
|
675674
|
+
}
|
|
675675
|
+
if (filteredProofRequest && hasProvingKey(filteredProofRequest)) {
|
|
675617
675676
|
const {
|
|
675618
675677
|
provingKey,
|
|
675619
675678
|
provingKeyId
|
|
675620
|
-
} = await fetchProvingKey(
|
|
675679
|
+
} = await fetchProvingKey(filteredProofRequest);
|
|
675621
675680
|
descriptorBounds = applyEnforceBounds$1({
|
|
675622
675681
|
builder: presentation.presBuilder,
|
|
675623
|
-
proofRequest,
|
|
675682
|
+
proofRequest: filteredProofRequest,
|
|
675624
675683
|
provingKey,
|
|
675625
675684
|
provingKeyId,
|
|
675626
675685
|
selectedCredentials
|
|
675627
675686
|
});
|
|
675628
675687
|
}
|
|
675629
675688
|
let pexRequiredAttributes = [];
|
|
675630
|
-
if (
|
|
675631
|
-
pexRequiredAttributes = getPexRequiredAttributes$1(
|
|
675689
|
+
if ((_filteredProofRequest = filteredProofRequest) !== null && _filteredProofRequest !== void 0 && _filteredProofRequest.request) {
|
|
675690
|
+
pexRequiredAttributes = getPexRequiredAttributes$1(filteredProofRequest.request, selectedCredentials);
|
|
675632
675691
|
}
|
|
675633
675692
|
let idx = 0;
|
|
675634
675693
|
for (const {
|
|
@@ -682002,6 +682061,19 @@ zoo`.split('\n');
|
|
|
682002
682061
|
throw new Error("Failed to retrieve default DID: ".concat(error.message));
|
|
682003
682062
|
}
|
|
682004
682063
|
},
|
|
682064
|
+
/**
|
|
682065
|
+
* Removes a credential from the wallet.
|
|
682066
|
+
*
|
|
682067
|
+
* @async
|
|
682068
|
+
* @param {string} credentialId - The ID of the credential to remove
|
|
682069
|
+
* @returns {Promise<void>}
|
|
682070
|
+
*/
|
|
682071
|
+
removeCredential: async credentialId => {
|
|
682072
|
+
if (!credentialId || typeof credentialId !== 'string') {
|
|
682073
|
+
throw new Error('Invalid credentialId: Must be a non-empty string');
|
|
682074
|
+
}
|
|
682075
|
+
return await credentialProvider.removeCredential(credentialId);
|
|
682076
|
+
},
|
|
682005
682077
|
/**
|
|
682006
682078
|
* Creates a verifiable presentation for a given proof request.
|
|
682007
682079
|
*
|