@docknetwork/wallet-sdk-wasm 1.4.0 → 1.5.6
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/lib/{account-3c88155a.js → account-bf00e5c0.js} +5 -5
- package/lib/{account-8f5cbc4d.js → account-e48dc9b6.js} +5 -5
- package/lib/core/polkadot-utils.js +18 -4
- package/lib/core/polkadot-utils.mjs +15 -2
- package/lib/index.js +14 -17
- package/lib/index.mjs +14 -17
- package/lib/modules/account.js +9 -5
- package/lib/modules/account.mjs +9 -5
- package/lib/modules/accounts.js +9 -5
- package/lib/modules/accounts.mjs +9 -5
- package/lib/modules/network-manager.js +4 -2
- package/lib/modules/network-manager.mjs +4 -2
- package/lib/modules/wallet.js +12 -8
- package/lib/modules/wallet.mjs +12 -8
- package/lib/rpc-server.js +14 -17
- package/lib/rpc-server.mjs +14 -17
- package/lib/services/blockchain/configs.js +7 -0
- package/lib/services/blockchain/configs.mjs +3 -0
- package/lib/services/{dock → blockchain}/index.android.js +3 -4
- package/lib/services/{dock → blockchain}/index.android.mjs +3 -4
- package/lib/services/{dock → blockchain}/index.ios.js +3 -4
- package/lib/services/{dock → blockchain}/index.ios.mjs +3 -4
- package/lib/services/blockchain/index.js +30 -0
- package/lib/services/blockchain/index.mjs +22 -0
- package/lib/services/{dock → blockchain}/service-rpc.js +5 -7
- package/lib/services/{dock → blockchain}/service-rpc.mjs +5 -7
- package/lib/services/blockchain/service.js +212 -0
- package/lib/services/blockchain/service.mjs +206 -0
- package/lib/services/credential/bbs-revocation.js +33 -61
- package/lib/services/credential/bbs-revocation.mjs +34 -62
- package/lib/services/credential/bound-check.js +0 -8
- package/lib/services/credential/bound-check.mjs +1 -5
- package/lib/services/credential/index.js +20 -23
- package/lib/services/credential/index.mjs +20 -23
- package/lib/services/credential/pex-helpers.js +134 -34
- package/lib/services/credential/pex-helpers.mjs +133 -35
- package/lib/services/credential/service.js +54 -55
- package/lib/services/credential/service.mjs +43 -41
- package/lib/services/credential/utils.js +12 -18
- package/lib/services/credential/utils.mjs +11 -14
- package/lib/services/dids/config.js +8 -0
- package/lib/services/dids/config.mjs +8 -0
- package/lib/services/dids/index.js +8 -7
- package/lib/services/dids/index.mjs +8 -7
- package/lib/services/dids/service-rpc.js +2 -2
- package/lib/services/dids/service-rpc.mjs +2 -2
- package/lib/services/dids/service.js +22 -32
- package/lib/services/dids/service.mjs +22 -32
- package/lib/services/edv/hmac.js +5 -0
- package/lib/services/edv/hmac.mjs +5 -0
- package/lib/services/edv/index.js +10 -8
- package/lib/services/edv/index.mjs +10 -8
- package/lib/services/edv/service-rpc.js +4 -0
- package/lib/services/edv/service-rpc.mjs +4 -0
- package/lib/services/edv/service.js +26 -10
- package/lib/services/edv/service.mjs +25 -10
- package/lib/services/example/service.js +3 -1
- package/lib/services/example/service.mjs +3 -1
- package/lib/services/index.js +12 -15
- package/lib/services/index.mjs +12 -15
- package/lib/services/keyring/configs.js +12 -0
- package/lib/services/keyring/configs.mjs +12 -0
- package/lib/services/keyring/service.js +5 -0
- package/lib/services/keyring/service.mjs +5 -0
- package/lib/services/pex/service.js +17 -15
- package/lib/services/pex/service.mjs +17 -15
- package/lib/services/substrate/api-utils.js +18 -6
- package/lib/services/substrate/api-utils.mjs +18 -6
- package/lib/services/substrate/index.js +13 -6
- package/lib/services/substrate/index.mjs +13 -6
- package/lib/services/substrate/service.js +16 -9
- package/lib/services/substrate/service.mjs +16 -9
- package/lib/services/test-utils.js +27 -18
- package/lib/services/test-utils.mjs +27 -18
- package/lib/services/trust-registry/index.js +16 -5
- package/lib/services/trust-registry/index.mjs +16 -5
- package/lib/services/trust-registry/service.js +26 -10
- package/lib/services/trust-registry/service.mjs +26 -10
- package/lib/services/util-crypto/configs.js +3 -0
- package/lib/services/util-crypto/configs.mjs +3 -0
- package/lib/services/util-crypto/service-rpc.js +6 -0
- package/lib/services/util-crypto/service-rpc.mjs +6 -0
- package/lib/services/util-crypto/service.js +5 -0
- package/lib/services/util-crypto/service.mjs +6 -1
- package/lib/setup-nodejs.js +14 -17
- package/lib/setup-nodejs.mjs +14 -17
- package/lib/setup-tests.js +14 -17
- package/lib/setup-tests.mjs +14 -17
- package/lib/src/core/polkadot-utils.d.ts +1 -0
- package/lib/src/core/polkadot-utils.d.ts.map +1 -1
- package/lib/src/modules/network-manager.d.ts +1 -0
- package/lib/src/modules/network-manager.d.ts.map +1 -1
- package/lib/src/services/blockchain/configs.d.ts +8 -0
- package/lib/src/services/blockchain/configs.d.ts.map +1 -0
- package/lib/src/services/blockchain/index.d.ts +2 -0
- package/lib/src/services/blockchain/index.d.ts.map +1 -0
- package/lib/src/services/{dock → blockchain}/service.d.ts +12 -11
- package/lib/src/services/blockchain/service.d.ts.map +1 -0
- package/lib/src/services/credential/bbs-revocation.d.ts.map +1 -1
- package/lib/src/services/credential/bound-check.d.ts +0 -4
- package/lib/src/services/credential/bound-check.d.ts.map +1 -1
- package/lib/src/services/credential/index.d.ts +2 -7
- package/lib/src/services/credential/index.d.ts.map +1 -1
- package/lib/src/services/credential/pex-helpers.d.ts +5 -3
- package/lib/src/services/credential/pex-helpers.d.ts.map +1 -1
- package/lib/src/services/credential/service.d.ts +2 -7
- package/lib/src/services/credential/service.d.ts.map +1 -1
- package/lib/src/services/credential/utils.d.ts.map +1 -1
- package/lib/src/services/dids/config.d.ts +5 -0
- package/lib/src/services/dids/config.d.ts.map +1 -1
- package/lib/src/services/dids/service-rpc.d.ts +1 -1
- package/lib/src/services/dids/service-rpc.d.ts.map +1 -1
- package/lib/src/services/dids/service.d.ts +9 -7
- package/lib/src/services/dids/service.d.ts.map +1 -1
- package/lib/src/services/edv/hmac.d.ts +1 -0
- package/lib/src/services/edv/hmac.d.ts.map +1 -1
- package/lib/src/services/edv/service.d.ts +5 -0
- package/lib/src/services/edv/service.d.ts.map +1 -1
- package/lib/src/services/example/service.d.ts.map +1 -1
- package/lib/src/services/keyring/configs.d.ts +6 -0
- package/lib/src/services/keyring/configs.d.ts.map +1 -1
- package/lib/src/services/pex/service.d.ts.map +1 -1
- package/lib/src/services/trust-registry/service.d.ts.map +1 -1
- package/lib/src/services/util-crypto/configs.d.ts +1 -0
- package/lib/src/services/util-crypto/configs.d.ts.map +1 -1
- package/lib/src/services/util-crypto/service.d.ts +1 -0
- package/lib/src/services/util-crypto/service.d.ts.map +1 -1
- package/lib/test/setup-test-state.js +10 -6
- package/lib/test/setup-test-state.mjs +10 -6
- package/lib/tsconfig.tsbuildinfo +1 -1
- package/package.json +9 -7
- package/src/core/polkadot-utils.js +14 -3
- package/src/modules/network-manager.ts +5 -2
- package/src/modules/wallet.ts +5 -5
- package/src/services/blockchain/configs.ts +11 -0
- package/src/services/blockchain/index.android.js +3 -0
- package/src/services/blockchain/index.ios.js +3 -0
- package/src/services/blockchain/index.js +1 -0
- package/src/services/blockchain/index.test.js +34 -0
- package/src/services/{dock → blockchain}/service-rpc.js +5 -6
- package/src/services/blockchain/service.ts +261 -0
- package/src/services/credential/bbs-revocation.ts +42 -90
- package/src/services/credential/bound-check.test.ts +2 -5
- package/src/services/credential/bound-check.ts +0 -5
- package/src/services/credential/index.test.js +148 -7
- package/src/services/credential/pex-helpers.js +132 -34
- package/src/services/credential/pex-helpers.test.js +284 -27
- package/src/services/credential/service.ts +44 -27
- package/src/services/credential/utils.js +5 -14
- package/src/services/dids/config.ts +15 -0
- package/src/services/dids/index.test.js +5 -46
- package/src/services/dids/service-rpc.ts +2 -2
- package/src/services/dids/service.ts +17 -34
- package/src/services/edv/hmac.ts +13 -0
- package/src/services/edv/index.test.js +22 -0
- package/src/services/edv/service-rpc.js +4 -0
- package/src/services/edv/service.ts +22 -0
- package/src/services/example/service.ts +3 -1
- package/src/services/index.js +2 -2
- package/src/services/keyring/configs.ts +21 -0
- package/src/services/keyring/service.ts +13 -0
- package/src/services/pex/service.ts +29 -18
- package/src/services/pex/tests/pex-service.test.js +163 -6
- package/src/services/substrate/api-utils.test.js +7 -7
- package/src/services/substrate/api-utils.ts +3 -3
- package/src/services/substrate/service.ts +6 -6
- package/src/services/test-utils.js +13 -11
- package/src/services/trust-registry/index.test.js +6 -4
- package/src/services/trust-registry/service.ts +13 -7
- package/src/services/util-crypto/configs.ts +4 -0
- package/src/services/util-crypto/service-rpc.js +6 -0
- package/src/services/util-crypto/service.ts +8 -0
- package/src/test/setup-test-state.js +2 -2
- package/lib/services/dock/configs.js +0 -18
- package/lib/services/dock/configs.mjs +0 -10
- package/lib/services/dock/index.js +0 -18
- package/lib/services/dock/index.mjs +0 -10
- package/lib/services/dock/service.js +0 -136
- package/lib/services/dock/service.mjs +0 -128
- package/lib/src/services/dock/configs.d.ts +0 -7
- package/lib/src/services/dock/configs.d.ts.map +0 -1
- package/lib/src/services/dock/index.d.ts +0 -2
- package/lib/src/services/dock/index.d.ts.map +0 -1
- package/lib/src/services/dock/service.d.ts.map +0 -1
- package/src/services/dock/configs.ts +0 -12
- package/src/services/dock/index.android.js +0 -3
- package/src/services/dock/index.ios.js +0 -3
- package/src/services/dock/index.js +0 -1
- package/src/services/dock/index.test.js +0 -48
- package/src/services/dock/service.ts +0 -159
|
@@ -1,16 +1,13 @@
|
|
|
1
1
|
import {
|
|
2
2
|
applyEnforceBounds,
|
|
3
|
-
MAX_DATE_PLACEHOLDER,
|
|
4
|
-
MIN_DATE_PLACEHOLDER,
|
|
5
|
-
MAX_NUMBER,
|
|
6
3
|
fetchProvingKey,
|
|
7
4
|
isBase64OrDataUrl,
|
|
8
|
-
MIN_INTEGER,
|
|
9
5
|
} from './bound-check';
|
|
10
6
|
import {PresentationBuilder} from '@docknetwork/crypto-wasm-ts/lib';
|
|
11
7
|
import proofRequest from './proof-request.json';
|
|
12
8
|
import { replaceResponseURL } from '@docknetwork/wallet-sdk-core/src/helpers';
|
|
13
9
|
import assert from 'assert';
|
|
10
|
+
import { MAX_DATE_PLACEHOLDER, MAX_NUMBER, MIN_DATE_PLACEHOLDER, MIN_NUMBER } from './pex-helpers';
|
|
14
11
|
|
|
15
12
|
const testAPIURL = process.env.TESTING_API_URL || null;
|
|
16
13
|
|
|
@@ -218,7 +215,7 @@ describe('Bound check', () => {
|
|
|
218
215
|
|
|
219
216
|
const credIdx = 0;
|
|
220
217
|
const attributeName = 'credentialSubject.income';
|
|
221
|
-
const min =
|
|
218
|
+
const min = MIN_NUMBER;
|
|
222
219
|
const max = 20000;
|
|
223
220
|
|
|
224
221
|
expect(builder.enforceBounds).toHaveBeenCalledWith(
|
|
@@ -132,10 +132,5 @@ export async function fetchProvingKey(proofRequest: ProofRequest) {
|
|
|
132
132
|
return {provingKey, provingKeyId: 'key0'};
|
|
133
133
|
}
|
|
134
134
|
|
|
135
|
-
export const MAX_DATE_PLACEHOLDER = 884541351600000;
|
|
136
|
-
export const MIN_DATE_PLACEHOLDER = -17592186044415;
|
|
137
|
-
export const MAX_NUMBER = Math.pow(100, 9);
|
|
138
|
-
export const MIN_INTEGER = -4294967295;
|
|
139
|
-
|
|
140
135
|
export const hasProvingKey = (proofRequest: ProofRequest) =>
|
|
141
136
|
!!proofRequest.boundCheckSnarkKey;
|
|
@@ -1,14 +1,31 @@
|
|
|
1
1
|
import {assertRpcService, getPromiseError} from '../test-utils';
|
|
2
2
|
import {credentialService as service} from './service';
|
|
3
3
|
import {validation} from './config';
|
|
4
|
-
import * as
|
|
4
|
+
import * as credentialUtils from '@docknetwork/credential-sdk/vc';
|
|
5
5
|
import {CredentialServiceRPC} from './service-rpc';
|
|
6
6
|
import {getTestWallet} from '../../test/setup-test-state';
|
|
7
|
-
import
|
|
7
|
+
import {OpenID4VCIClientV1_0_13} from '@sphereon/oid4vci-client';
|
|
8
|
+
import {didService} from '../dids/service';
|
|
8
9
|
|
|
9
10
|
describe('Credential Service', () => {
|
|
10
11
|
beforeAll(async () => {
|
|
11
12
|
await getTestWallet();
|
|
13
|
+
const mockAddCredentialToPresent = jest.fn(() => 0);
|
|
14
|
+
const mockAddAttributeToReveal = jest.fn();
|
|
15
|
+
const mockCreatePresentation = jest.fn();
|
|
16
|
+
const mockDeriveCredentials = jest.fn(() => []);
|
|
17
|
+
|
|
18
|
+
jest.spyOn(credentialUtils, 'Presentation').mockImplementation(() => {
|
|
19
|
+
return {
|
|
20
|
+
addCredentialToPresent: mockAddCredentialToPresent,
|
|
21
|
+
addAttributeToReveal: mockAddAttributeToReveal,
|
|
22
|
+
createPresentation: mockCreatePresentation,
|
|
23
|
+
deriveCredentials: mockDeriveCredentials,
|
|
24
|
+
presBuilder: {
|
|
25
|
+
enforceBounds: jest.fn(),
|
|
26
|
+
},
|
|
27
|
+
};
|
|
28
|
+
});
|
|
12
29
|
});
|
|
13
30
|
it('ServiceRpc', () => {
|
|
14
31
|
assertRpcService(CredentialServiceRPC, service, validation);
|
|
@@ -19,7 +36,7 @@ describe('Credential Service', () => {
|
|
|
19
36
|
});
|
|
20
37
|
it('expect to verify credential', async () => {
|
|
21
38
|
jest
|
|
22
|
-
.spyOn(
|
|
39
|
+
.spyOn(credentialUtils, 'verifyCredential')
|
|
23
40
|
.mockImplementationOnce(async () => ({verified: true}));
|
|
24
41
|
const credential = {
|
|
25
42
|
'@context': [
|
|
@@ -71,7 +88,7 @@ describe('Credential Service', () => {
|
|
|
71
88
|
},
|
|
72
89
|
};
|
|
73
90
|
await service.verifyCredential({credential});
|
|
74
|
-
expect(
|
|
91
|
+
expect(credentialUtils.verifyCredential).toBeCalled();
|
|
75
92
|
});
|
|
76
93
|
it('should create a vc', async () => {
|
|
77
94
|
const subject = {
|
|
@@ -296,7 +313,7 @@ describe('Credential Service', () => {
|
|
|
296
313
|
credentials,
|
|
297
314
|
});
|
|
298
315
|
|
|
299
|
-
const bbsPresentation = new
|
|
316
|
+
const bbsPresentation = new credentialUtils.Presentation();
|
|
300
317
|
expect(bbsPresentation.addCredentialToPresent).toBeCalledWith(
|
|
301
318
|
credential,
|
|
302
319
|
expect.any(Object),
|
|
@@ -366,7 +383,7 @@ describe('Credential Service', () => {
|
|
|
366
383
|
credentials,
|
|
367
384
|
});
|
|
368
385
|
|
|
369
|
-
const bbsPresentation = new
|
|
386
|
+
const bbsPresentation = new credentialUtils.Presentation();
|
|
370
387
|
expect(bbsPresentation.addCredentialToPresent).toBeCalledWith(
|
|
371
388
|
credential,
|
|
372
389
|
expect.any(Object),
|
|
@@ -401,7 +418,7 @@ describe('Credential Service', () => {
|
|
|
401
418
|
},
|
|
402
419
|
}),
|
|
403
420
|
).toBe(
|
|
404
|
-
'0xa632a41f2fbdb681c14b33daae4fcc46af41661b90b35c4ac1545c9bebf0d7cc',
|
|
421
|
+
'dock:accumulator:0xa632a41f2fbdb681c14b33daae4fcc46af41661b90b35c4ac1545c9bebf0d7cc',
|
|
405
422
|
);
|
|
406
423
|
});
|
|
407
424
|
});
|
|
@@ -427,4 +444,128 @@ describe('Credential Service', () => {
|
|
|
427
444
|
}),
|
|
428
445
|
).toBe(true);
|
|
429
446
|
});
|
|
447
|
+
|
|
448
|
+
describe('acquireOIDCredential', () => {
|
|
449
|
+
const mockHolderKeyDocument = {
|
|
450
|
+
id: 'did:example:123#key-1',
|
|
451
|
+
controller: 'did:example:123',
|
|
452
|
+
};
|
|
453
|
+
|
|
454
|
+
const mockCredential = {
|
|
455
|
+
'@context': ['https://www.w3.org/2018/credentials/v1'],
|
|
456
|
+
type: ['VerifiableCredential', 'MyCredential'],
|
|
457
|
+
issuer:
|
|
458
|
+
'https://api-testnet.truvera.io/openid/issuers/7eff516f-69fb-4b9d-94dc-e88308ec0c4c',
|
|
459
|
+
credentialSubject: {
|
|
460
|
+
id: 'did:example:123',
|
|
461
|
+
name: 'John Doe',
|
|
462
|
+
},
|
|
463
|
+
proof: {
|
|
464
|
+
type: 'Ed25519Signature2018',
|
|
465
|
+
created: '2024-03-31T12:00:00Z',
|
|
466
|
+
proofPurpose: 'assertionMethod',
|
|
467
|
+
verificationMethod: 'did:example:123#key-1',
|
|
468
|
+
proofValue: 'mockProofValue',
|
|
469
|
+
},
|
|
470
|
+
};
|
|
471
|
+
|
|
472
|
+
beforeEach(() => {
|
|
473
|
+
jest.clearAllMocks();
|
|
474
|
+
});
|
|
475
|
+
|
|
476
|
+
it('should handle credential_offer parameter', async () => {
|
|
477
|
+
const uri =
|
|
478
|
+
'openid-credential-offer://?credential_offer=%7B%22credential_issuer%22%3A%22https%3A%2F%2Fapi-testnet.truvera.io%2Fopenid%2Fissuers%2F7eff516f-69fb-4b9d-94dc-e88308ec0c4c%22%2C%22credentials%22%3A%5B%22ldp_vc%3AMyCredential%22%5D%2C%22grants%22%3A%7B%22urn%3Aietf%3Aparams%3Aoauth%3Agrant-type%3Apre-authorized_code%22%3A%7B%22pre-authorized_code%22%3A%22AAL4MPpEpWY6daBxVxJ8Q3chxOhvc9qIV3EAyj7dvps%22%2C%22user_pin_required%22%3Afalse%7D%7D%7D';
|
|
479
|
+
|
|
480
|
+
const mockClient = {
|
|
481
|
+
credentialOffer: {
|
|
482
|
+
preAuthorizedCode: 'AAL4MPpEpWY6daBxVxJ8Q3chxOhvc9qIV3EAyj7dvps',
|
|
483
|
+
},
|
|
484
|
+
acquireAccessToken: jest.fn(),
|
|
485
|
+
acquireCredentials: jest
|
|
486
|
+
.fn()
|
|
487
|
+
.mockResolvedValue({credential: mockCredential}),
|
|
488
|
+
getCredentialsSupported: jest
|
|
489
|
+
.fn()
|
|
490
|
+
.mockReturnValue([{scope: 'ldp_vc:MyCredential'}]),
|
|
491
|
+
};
|
|
492
|
+
|
|
493
|
+
jest
|
|
494
|
+
.spyOn(OpenID4VCIClientV1_0_13, 'fromURI')
|
|
495
|
+
.mockResolvedValue(mockClient);
|
|
496
|
+
jest
|
|
497
|
+
.spyOn(didService, 'createSignedJWT')
|
|
498
|
+
.mockResolvedValue('mock.jwt.token');
|
|
499
|
+
|
|
500
|
+
const result = await service.acquireOIDCredential({
|
|
501
|
+
uri,
|
|
502
|
+
holderKeyDocument: mockHolderKeyDocument,
|
|
503
|
+
});
|
|
504
|
+
|
|
505
|
+
expect(result).toEqual({
|
|
506
|
+
credential: mockCredential,
|
|
507
|
+
});
|
|
508
|
+
});
|
|
509
|
+
|
|
510
|
+
it('should handle credential_offer_uri parameter', async () => {
|
|
511
|
+
const uri =
|
|
512
|
+
'openid-credential-offer://?credential_offer_uri=https://api.truvera.io/openid/credential-offers/6783b6ff-b84d-4e6a-850d-f3828e2c1526';
|
|
513
|
+
|
|
514
|
+
// Mock OpenID4VCIClientV1_0_13
|
|
515
|
+
const mockClient = {
|
|
516
|
+
credentialOffer: {
|
|
517
|
+
preAuthorizedCode: 'AAL4MPpEpWY6daBxVxJ8Q3chxOhvc9qIV3EAyj7dvps',
|
|
518
|
+
},
|
|
519
|
+
acquireAccessToken: jest.fn(),
|
|
520
|
+
acquireCredentials: jest
|
|
521
|
+
.fn()
|
|
522
|
+
.mockResolvedValue({credential: mockCredential}),
|
|
523
|
+
getCredentialsSupported: jest
|
|
524
|
+
.fn()
|
|
525
|
+
.mockReturnValue([{scope: 'ldp_vc:MyCredential'}]),
|
|
526
|
+
};
|
|
527
|
+
|
|
528
|
+
jest
|
|
529
|
+
.spyOn(OpenID4VCIClientV1_0_13, 'fromURI')
|
|
530
|
+
.mockResolvedValue(mockClient);
|
|
531
|
+
jest
|
|
532
|
+
.spyOn(didService, 'createSignedJWT')
|
|
533
|
+
.mockResolvedValue('mock.jwt.token');
|
|
534
|
+
|
|
535
|
+
const result = await service.acquireOIDCredential({
|
|
536
|
+
uri,
|
|
537
|
+
holderKeyDocument: mockHolderKeyDocument,
|
|
538
|
+
});
|
|
539
|
+
|
|
540
|
+
expect(result).toEqual({
|
|
541
|
+
credential: mockCredential,
|
|
542
|
+
});
|
|
543
|
+
});
|
|
544
|
+
|
|
545
|
+
it('should return authorization URL when no pre-authorized code is available', async () => {
|
|
546
|
+
const uri =
|
|
547
|
+
'openid-credential-offer://?credential_offer=%7B%22credential_issuer%22%3A%22https%3A%2F%2Fapi-testnet.truvera.io%2Fopenid%2Fissuers%2F7eff516f-69fb-4b9d-94dc-e88308ec0c4c%22%2C%22credentials%22%3A%5B%22ldp_vc%3AMyCredential%22%5D%7D';
|
|
548
|
+
const mockClient = {
|
|
549
|
+
credentialOffer: {},
|
|
550
|
+
authorizationURL:
|
|
551
|
+
'https://api-testnet.truvera.io/openid/authorize?response_type=code&client_id=dock.wallet&redirect_uri=dock-wallet%3A%2F%2Fcredentials%2Fcallback&scope=ldp_vc%3AMyCredential',
|
|
552
|
+
getCredentialsSupported: jest
|
|
553
|
+
.fn()
|
|
554
|
+
.mockReturnValue([{scope: 'ldp_vc:MyCredential'}]),
|
|
555
|
+
};
|
|
556
|
+
|
|
557
|
+
jest
|
|
558
|
+
.spyOn(OpenID4VCIClientV1_0_13, 'fromURI')
|
|
559
|
+
.mockResolvedValue(mockClient);
|
|
560
|
+
|
|
561
|
+
const result = await service.acquireOIDCredential({
|
|
562
|
+
uri,
|
|
563
|
+
holderKeyDocument: mockHolderKeyDocument,
|
|
564
|
+
});
|
|
565
|
+
|
|
566
|
+
expect(result).toEqual({
|
|
567
|
+
authorizationURL: mockClient.authorizationURL,
|
|
568
|
+
});
|
|
569
|
+
});
|
|
570
|
+
});
|
|
430
571
|
});
|
|
@@ -1,12 +1,14 @@
|
|
|
1
1
|
import {JSONPath} from '@astronautlabs/jsonpath';
|
|
2
2
|
|
|
3
|
-
export const EPSILON_NUMBER = 0.
|
|
3
|
+
export const EPSILON_NUMBER = 0.001;
|
|
4
4
|
export const EPSILON_INT = 1;
|
|
5
5
|
|
|
6
6
|
export const MAX_DATE_PLACEHOLDER = 884541351600000;
|
|
7
7
|
export const MIN_DATE_PLACEHOLDER = -17592186044415;
|
|
8
|
-
export const
|
|
9
|
-
export const
|
|
8
|
+
export const MAX_INTEGER = 100 ** 9;
|
|
9
|
+
export const MIN_INTEGER = -4294967295;
|
|
10
|
+
export const MAX_NUMBER = 100 ** 5;
|
|
11
|
+
export const MIN_NUMBER = -4294967294;
|
|
10
12
|
|
|
11
13
|
/*
|
|
12
14
|
PEX Filter rules:
|
|
@@ -21,6 +23,15 @@ function correctFieldPath(path) {
|
|
|
21
23
|
return path.replace('$.', '');
|
|
22
24
|
}
|
|
23
25
|
|
|
26
|
+
function getNumDecimalPlaces(n) {
|
|
27
|
+
const parts = n.toString().split('.');
|
|
28
|
+
return parts.length > 1 && parts[1].length;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
function toMaxDecimalPlaces(n, maxDecimalPlaces) {
|
|
32
|
+
return +n.toFixed(maxDecimalPlaces);
|
|
33
|
+
}
|
|
34
|
+
|
|
24
35
|
function getAttributeName({field, selectedCredentials, index}) {
|
|
25
36
|
let attributeName;
|
|
26
37
|
if (Array.isArray(field.path) && field.path.length > 1) {
|
|
@@ -52,18 +63,40 @@ function getAttributeName({field, selectedCredentials, index}) {
|
|
|
52
63
|
export function pexToBounds(
|
|
53
64
|
pexRequest,
|
|
54
65
|
selectedCredentials = [],
|
|
55
|
-
|
|
66
|
+
removeFromRequest = false,
|
|
56
67
|
) {
|
|
57
68
|
const descriptorBounds = [];
|
|
58
|
-
const
|
|
59
|
-
MIN_DATE_PLACEHOLDER,
|
|
60
|
-
MAX_DATE_PLACEHOLDER,
|
|
61
|
-
MIN_NUMBER,
|
|
62
|
-
MAX_NUMBER,
|
|
63
|
-
].map(value => (isRawBoundies ? undefined : value));
|
|
69
|
+
const fieldsToRemove = [];
|
|
64
70
|
|
|
65
71
|
// One list of bounds per descriptor/credential
|
|
66
72
|
pexRequest.input_descriptors.forEach((inputDescriptor, index) => {
|
|
73
|
+
const selectedCredential = selectedCredentials[index];
|
|
74
|
+
if (!selectedCredential) {
|
|
75
|
+
return;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
// Get embedded schema if existing
|
|
79
|
+
let decodedSchema = {};
|
|
80
|
+
if (selectedCredential.credentialSchema) {
|
|
81
|
+
const schemaStartStr = 'data:application/json;charset=utf-8,';
|
|
82
|
+
|
|
83
|
+
if (selectedCredential.credentialSchema.details) {
|
|
84
|
+
decodedSchema =
|
|
85
|
+
JSON.parse(selectedCredential.credentialSchema.details).jsonSchema ||
|
|
86
|
+
{};
|
|
87
|
+
} else if (
|
|
88
|
+
selectedCredential.credentialSchema.id &&
|
|
89
|
+
selectedCredential.credentialSchema.id.startsWith(schemaStartStr)
|
|
90
|
+
) {
|
|
91
|
+
// LEGACY embedded schema handling
|
|
92
|
+
decodedSchema = JSON.parse(
|
|
93
|
+
decodeURIComponent(
|
|
94
|
+
selectedCredential.credentialSchema.id.split(schemaStartStr)[1],
|
|
95
|
+
),
|
|
96
|
+
);
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
|
|
67
100
|
const bounds = [];
|
|
68
101
|
inputDescriptor.constraints.fields.forEach(field => {
|
|
69
102
|
const {
|
|
@@ -77,6 +110,44 @@ export function pexToBounds(
|
|
|
77
110
|
type,
|
|
78
111
|
} = field.filter || {};
|
|
79
112
|
|
|
113
|
+
if (!field.path || field.path.length === 0) {
|
|
114
|
+
throw new Error(
|
|
115
|
+
'Missing or empty field "path" property, expected array or string',
|
|
116
|
+
);
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
let attributeName;
|
|
120
|
+
if (Array.isArray(field.path) && field.path.length > 1) {
|
|
121
|
+
// Must find a path that matches in selectedcredential, and choose that for bounds
|
|
122
|
+
const pathCount = field.path.length;
|
|
123
|
+
for (let i = 0; i < pathCount; i++) {
|
|
124
|
+
const path = field.path[i];
|
|
125
|
+
const paths = JSONPath.paths(selectedCredential, path);
|
|
126
|
+
if (paths.length) {
|
|
127
|
+
// First come first served
|
|
128
|
+
attributeName = correctFieldPath(JSONPath.stringify(paths[0]));
|
|
129
|
+
break;
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
} else {
|
|
133
|
+
const path = Array.isArray(field.path) ? field.path[0] : field.path;
|
|
134
|
+
attributeName = correctFieldPath(path);
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
if (!attributeName) {
|
|
138
|
+
return;
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
const schemaPath = `$.properties.${attributeName.replaceAll(
|
|
142
|
+
'.',
|
|
143
|
+
'.properties.',
|
|
144
|
+
)}`;
|
|
145
|
+
const attributeSchema = JSONPath.query(
|
|
146
|
+
decodedSchema,
|
|
147
|
+
schemaPath,
|
|
148
|
+
1,
|
|
149
|
+
)[0] || {type};
|
|
150
|
+
|
|
80
151
|
let max =
|
|
81
152
|
maximum === undefined
|
|
82
153
|
? formatMaximum === undefined
|
|
@@ -95,62 +166,89 @@ export function pexToBounds(
|
|
|
95
166
|
return;
|
|
96
167
|
}
|
|
97
168
|
|
|
169
|
+
const attributeType = attributeSchema.type || type;
|
|
170
|
+
|
|
98
171
|
// Get min/max bounds values, if using exclusive we must apply an epsilon so equality isnt true
|
|
99
172
|
if (format === 'date-time' || format === 'date') {
|
|
100
|
-
max = max === undefined ?
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
173
|
+
max = new Date(max === undefined ? MAX_DATE_PLACEHOLDER : max);
|
|
174
|
+
min = new Date(min === undefined ? MIN_DATE_PLACEHOLDER : min);
|
|
175
|
+
} else if (attributeType === 'number') {
|
|
176
|
+
const epsilon = attributeSchema.multipleOf || EPSILON_NUMBER;
|
|
177
|
+
const attribDecimalPlaces = getNumDecimalPlaces(epsilon);
|
|
178
|
+
|
|
105
179
|
max =
|
|
106
180
|
max === undefined
|
|
107
|
-
?
|
|
108
|
-
|
|
181
|
+
? attributeSchema.maximum === undefined
|
|
182
|
+
? MAX_NUMBER
|
|
183
|
+
: attributeSchema.maximum
|
|
184
|
+
: exclusiveMaximum === undefined
|
|
109
185
|
? max
|
|
110
|
-
: max -
|
|
186
|
+
: max - epsilon;
|
|
111
187
|
min =
|
|
112
188
|
min === undefined
|
|
113
|
-
?
|
|
114
|
-
|
|
189
|
+
? attributeSchema.minimum === undefined
|
|
190
|
+
? MIN_NUMBER
|
|
191
|
+
: attributeSchema.minimum
|
|
192
|
+
: exclusiveMinimum === undefined
|
|
115
193
|
? min
|
|
116
|
-
: min +
|
|
117
|
-
|
|
194
|
+
: min + epsilon;
|
|
195
|
+
|
|
196
|
+
// Because of floating point math sucks, sometimes we can get extra decimal points
|
|
197
|
+
// the bounds must also match the same decimal points as the input
|
|
198
|
+
// for this we read from the embedded schema
|
|
199
|
+
min = toMaxDecimalPlaces(min, attribDecimalPlaces);
|
|
200
|
+
max = toMaxDecimalPlaces(max, attribDecimalPlaces);
|
|
201
|
+
} else if (attributeType === 'integer') {
|
|
118
202
|
max =
|
|
119
203
|
max === undefined
|
|
120
|
-
?
|
|
121
|
-
|
|
204
|
+
? attributeSchema.maximum === undefined
|
|
205
|
+
? MAX_INTEGER
|
|
206
|
+
: attributeSchema.maximum
|
|
207
|
+
: exclusiveMaximum === undefined
|
|
122
208
|
? max
|
|
123
209
|
: max - EPSILON_INT;
|
|
124
210
|
min =
|
|
125
211
|
min === undefined
|
|
126
|
-
?
|
|
127
|
-
|
|
212
|
+
? attributeSchema.minimum === undefined
|
|
213
|
+
? MIN_INTEGER
|
|
214
|
+
: attributeSchema.minimum
|
|
215
|
+
: exclusiveMinimum === undefined
|
|
128
216
|
? min
|
|
129
217
|
: min + EPSILON_INT;
|
|
218
|
+
|
|
219
|
+
// Ensure that input values are not decimals otherwise crypto-wasm-ts will complain
|
|
220
|
+
min = Math.floor(min);
|
|
221
|
+
max = Math.floor(max);
|
|
130
222
|
} else {
|
|
131
223
|
throw new Error(
|
|
132
224
|
`Unsupported format ${format} and type ${type} for enforce bounds`,
|
|
133
225
|
);
|
|
134
226
|
}
|
|
135
227
|
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
228
|
+
if (removeFromRequest) {
|
|
229
|
+
fieldsToRemove.push({
|
|
230
|
+
fields: inputDescriptor.constraints.fields,
|
|
231
|
+
field,
|
|
232
|
+
});
|
|
233
|
+
}
|
|
141
234
|
|
|
142
235
|
bounds.push({
|
|
143
236
|
attributeName,
|
|
144
237
|
min,
|
|
145
238
|
max,
|
|
146
|
-
type,
|
|
147
|
-
format,
|
|
148
239
|
});
|
|
149
240
|
});
|
|
150
241
|
|
|
151
242
|
descriptorBounds.push(bounds);
|
|
152
243
|
});
|
|
153
244
|
|
|
245
|
+
fieldsToRemove.forEach(({fields, field}) => {
|
|
246
|
+
const idx = fields.indexOf(field);
|
|
247
|
+
if (idx !== -1) {
|
|
248
|
+
fields.splice(idx, 1);
|
|
249
|
+
}
|
|
250
|
+
});
|
|
251
|
+
|
|
154
252
|
return descriptorBounds;
|
|
155
253
|
}
|
|
156
254
|
|
|
@@ -170,7 +268,7 @@ export function getPexRequiredAttributes(pexRequest, selectedCredentials = []) {
|
|
|
170
268
|
.map((inputDescriptor, index) => {
|
|
171
269
|
return inputDescriptor.constraints.fields
|
|
172
270
|
.filter(field => {
|
|
173
|
-
if (field.filter) {
|
|
271
|
+
if (field.filter || field.optional) {
|
|
174
272
|
return false;
|
|
175
273
|
}
|
|
176
274
|
|