@learncard/network-brain-service 3.17.0 → 3.19.0
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/.env.example +4 -0
- package/AGENTS.md +177 -159
- package/CHANGELOG.md +148 -0
- package/README.md +26 -8
- package/compose.inbox.yml +7 -0
- package/dist/accesslayer/app-store-listing/relationships/read.d.ts.map +1 -1
- package/dist/accesslayer/auth-grant/read.d.ts +1 -0
- package/dist/accesslayer/auth-grant/read.d.ts.map +1 -1
- package/dist/accesslayer/consentflowcontract/relationships/create.d.ts +3 -2
- package/dist/accesslayer/consentflowcontract/relationships/create.d.ts.map +1 -1
- package/dist/accesslayer/consentflowcontract/relationships/read.d.ts +1 -0
- package/dist/accesslayer/consentflowcontract/relationships/read.d.ts.map +1 -1
- package/dist/accesslayer/consentflowcontract/relationships/update.d.ts +5 -3
- package/dist/accesslayer/consentflowcontract/relationships/update.d.ts.map +1 -1
- package/dist/accesslayer/credential/create.d.ts +2 -1
- package/dist/accesslayer/credential/create.d.ts.map +1 -1
- package/dist/accesslayer/credential/create.test.d.ts +2 -0
- package/dist/accesslayer/credential/create.test.d.ts.map +1 -0
- package/dist/accesslayer/credential/relationships/read.d.ts +1 -0
- package/dist/accesslayer/credential/relationships/read.d.ts.map +1 -1
- package/dist/accesslayer/credential-activity/create.d.ts.map +1 -1
- package/dist/accesslayer/credential-refresh/email-delivery.d.ts +18 -0
- package/dist/accesslayer/credential-refresh/email-delivery.d.ts.map +1 -0
- package/dist/accesslayer/credential-refresh/index.d.ts +1 -0
- package/dist/accesslayer/credential-refresh/index.d.ts.map +1 -1
- package/dist/accesslayer/credential-refresh/read.d.ts.map +1 -1
- package/dist/accesslayer/credential-refresh/update.d.ts.map +1 -1
- package/dist/accesslayer/inbox-batch/store.d.ts +33 -0
- package/dist/accesslayer/inbox-batch/store.d.ts.map +1 -0
- package/dist/accesslayer/inbox-credential/create.d.ts +5 -0
- package/dist/accesslayer/inbox-credential/create.d.ts.map +1 -1
- package/dist/accesslayer/inbox-credential/refresh.d.ts +71 -0
- package/dist/accesslayer/inbox-credential/refresh.d.ts.map +1 -0
- package/dist/accesslayer/inbox-credential/update.d.ts +1 -1
- package/dist/accesslayer/inbox-credential/update.d.ts.map +1 -1
- package/dist/cache/atomic-counter.test-helpers.d.ts +3 -0
- package/dist/cache/atomic-counter.test-helpers.d.ts.map +1 -0
- package/dist/cache/atomic-counter.test.d.ts +2 -0
- package/dist/cache/atomic-counter.test.d.ts.map +1 -0
- package/dist/cache/index.d.ts +1 -1
- package/dist/cache/index.d.ts.map +1 -1
- package/dist/config/environment.d.ts +46 -0
- package/dist/config/environment.d.ts.map +1 -1
- package/dist/credential-refresh.d.ts.map +1 -1
- package/dist/didkit_wasm_bg.wasm +0 -0
- package/dist/helpers/activity.helpers.d.ts +4 -0
- package/dist/helpers/activity.helpers.d.ts.map +1 -1
- package/dist/helpers/boost-storage.helpers.test.d.ts +2 -0
- package/dist/helpers/boost-storage.helpers.test.d.ts.map +1 -0
- package/dist/helpers/boost.helpers.d.ts +3 -7
- package/dist/helpers/boost.helpers.d.ts.map +1 -1
- package/dist/helpers/contact-method.helpers.d.ts.map +1 -1
- package/dist/helpers/contact-method.helpers.test.d.ts +2 -0
- package/dist/helpers/contact-method.helpers.test.d.ts.map +1 -0
- package/dist/helpers/credential-refresh-email-content.helpers.d.ts +44 -0
- package/dist/helpers/credential-refresh-email-content.helpers.d.ts.map +1 -0
- package/dist/helpers/credential-refresh-email-content.helpers.test.d.ts +2 -0
- package/dist/helpers/credential-refresh-email-content.helpers.test.d.ts.map +1 -0
- package/dist/helpers/credential-refresh-email.helpers.d.ts +17 -0
- package/dist/helpers/credential-refresh-email.helpers.d.ts.map +1 -0
- package/dist/helpers/credential-refresh-proof.helpers.d.ts +4 -0
- package/dist/helpers/credential-refresh-proof.helpers.d.ts.map +1 -0
- package/dist/helpers/credential-refresh-proof.helpers.test.d.ts +2 -0
- package/dist/helpers/credential-refresh-proof.helpers.test.d.ts.map +1 -0
- package/dist/helpers/credential-refresh.helpers.d.ts +45 -2
- package/dist/helpers/credential-refresh.helpers.d.ts.map +1 -1
- package/dist/helpers/credential.helpers.d.ts +4 -2
- package/dist/helpers/credential.helpers.d.ts.map +1 -1
- package/dist/helpers/finalize-inbox.helpers.d.ts.map +1 -1
- package/dist/helpers/inbox-batch-http.helpers.d.ts +15 -0
- package/dist/helpers/inbox-batch-http.helpers.d.ts.map +1 -0
- package/dist/helpers/inbox-batch-http.helpers.test.d.ts +2 -0
- package/dist/helpers/inbox-batch-http.helpers.test.d.ts.map +1 -0
- package/dist/helpers/inbox-batch-status.helpers.d.ts +3 -0
- package/dist/helpers/inbox-batch-status.helpers.d.ts.map +1 -0
- package/dist/helpers/inbox-batch.helpers.d.ts +10 -0
- package/dist/helpers/inbox-batch.helpers.d.ts.map +1 -0
- package/dist/helpers/inbox-batch.helpers.test.d.ts +2 -0
- package/dist/helpers/inbox-batch.helpers.test.d.ts.map +1 -0
- package/dist/helpers/inbox-issuance-error.helpers.d.ts +13 -0
- package/dist/helpers/inbox-issuance-error.helpers.d.ts.map +1 -0
- package/dist/helpers/inbox-queue.helpers.d.ts +11 -0
- package/dist/helpers/inbox-queue.helpers.d.ts.map +1 -0
- package/dist/helpers/inbox-queue.helpers.test.d.ts +2 -0
- package/dist/helpers/inbox-queue.helpers.test.d.ts.map +1 -0
- package/dist/helpers/inbox-refresh.helpers.d.ts +186 -0
- package/dist/helpers/inbox-refresh.helpers.d.ts.map +1 -0
- package/dist/helpers/inbox.helpers.d.ts +9 -1
- package/dist/helpers/inbox.helpers.d.ts.map +1 -1
- package/dist/helpers/issuedCredentialStatus.helpers.d.ts +5 -0
- package/dist/helpers/issuedCredentialStatus.helpers.d.ts.map +1 -0
- package/dist/helpers/notifications.helpers.d.ts.map +1 -1
- package/dist/helpers/rateLimit.helpers.d.ts.map +1 -1
- package/dist/helpers/refresh-send-intent.helpers.d.ts +51 -0
- package/dist/helpers/refresh-send-intent.helpers.d.ts.map +1 -0
- package/dist/helpers/shim.d.ts +1 -1
- package/dist/helpers/shim.d.ts.map +1 -1
- package/dist/helpers/signingAuthority.helpers.d.ts +3 -2
- package/dist/helpers/signingAuthority.helpers.d.ts.map +1 -1
- package/dist/helpers/signingAuthority.helpers.test.d.ts +2 -0
- package/dist/helpers/signingAuthority.helpers.test.d.ts.map +1 -0
- package/dist/helpers/status-list.helpers.d.ts.map +1 -1
- package/dist/helpers/status-list.helpers.test.d.ts +2 -0
- package/dist/helpers/status-list.helpers.test.d.ts.map +1 -0
- package/dist/inbox-queue-local.d.ts +2 -0
- package/dist/inbox-queue-local.d.ts.map +1 -0
- package/dist/index.js +2 -2
- package/dist/models/AuthGrant.d.ts.map +1 -1
- package/dist/models/ConsentFlowTerms.d.ts.map +1 -1
- package/dist/models/ConsentFlowTransaction.d.ts.map +1 -1
- package/dist/models/Credential.d.ts +1 -0
- package/dist/models/Credential.d.ts.map +1 -1
- package/dist/models/CredentialActivity.d.ts +1 -0
- package/dist/models/CredentialActivity.d.ts.map +1 -1
- package/dist/models/CredentialRefresh.d.ts +5 -2
- package/dist/models/CredentialRefresh.d.ts.map +1 -1
- package/dist/models/InboxCredential.d.ts +1 -0
- package/dist/models/InboxCredential.d.ts.map +1 -1
- package/dist/models/credential-refresh-constraints.d.ts.map +1 -1
- package/dist/openapi.d.ts.map +1 -1
- package/dist/routes/act-as.test.d.ts +2 -0
- package/dist/routes/act-as.test.d.ts.map +1 -0
- package/dist/routes/activity.d.ts +3 -0
- package/dist/routes/activity.d.ts.map +1 -1
- package/dist/routes/app-store.d.ts.map +1 -1
- package/dist/routes/auth-grants.d.ts +10 -0
- package/dist/routes/auth-grants.d.ts.map +1 -1
- package/dist/routes/boosts.d.ts +506 -12
- package/dist/routes/boosts.d.ts.map +1 -1
- package/dist/routes/contracts.d.ts +48 -2
- package/dist/routes/contracts.d.ts.map +1 -1
- package/dist/routes/credential-refreshes.d.ts +4 -4
- package/dist/routes/credential-refreshes.d.ts.map +1 -1
- package/dist/routes/credentials.d.ts +8 -2
- package/dist/routes/credentials.d.ts.map +1 -1
- package/dist/routes/did-metadata.d.ts +8 -8
- package/dist/routes/federation.d.ts +2 -2
- package/dist/routes/inbox.d.ts +973 -31
- package/dist/routes/inbox.d.ts.map +1 -1
- package/dist/routes/index.d.ts +47 -127
- package/dist/routes/index.d.ts.map +1 -1
- package/dist/routes/presentations.d.ts +6 -6
- package/dist/routes/storage.d.ts +63 -63
- package/dist/routes/test.d.ts +6 -0
- package/dist/routes/test.d.ts.map +1 -1
- package/dist/routes/workflows.d.ts +14 -14
- package/dist/routes/workflows.d.ts.map +1 -1
- package/dist/services/delivery/adapters/postmark.adapter.d.ts.map +1 -1
- package/dist/services/delivery/adapters/postmark.adapter.test.d.ts +2 -0
- package/dist/services/delivery/adapters/postmark.adapter.test.d.ts.map +1 -0
- package/dist/services/registry/registry.factory.d.ts.map +1 -1
- package/dist/types/activity.d.ts +4 -0
- package/dist/types/activity.d.ts.map +1 -1
- package/dist/types/consentflowcontract.d.ts +22 -8
- package/dist/types/consentflowcontract.d.ts.map +1 -1
- package/dist/types/credential-refresh.d.ts +10 -1
- package/dist/types/credential-refresh.d.ts.map +1 -1
- package/dist/types/credential.d.ts +7 -0
- package/dist/types/credential.d.ts.map +1 -1
- package/dist/types/did-metadata.d.ts +2 -2
- package/dist/types/inbox-batch.d.ts +38 -0
- package/dist/types/inbox-batch.d.ts.map +1 -0
- package/inbox-e2e-setup.ts +53 -1
- package/inbox-elasticmq.conf +10 -0
- package/lambda.ts +61 -16
- package/package.json +18 -16
- package/scripts/setup-inbox-queues.ts +60 -0
- package/serverless-local.yml +2 -0
- package/serverless.yml +75 -0
- package/src/accesslayer/app-store-listing/relationships/read.ts +4 -3
- package/src/accesslayer/auth-grant/read.ts +2 -1
- package/src/accesslayer/consentflowcontract/relationships/create.ts +15 -5
- package/src/accesslayer/consentflowcontract/relationships/read.ts +161 -63
- package/src/accesslayer/consentflowcontract/relationships/update.ts +43 -10
- package/src/accesslayer/credential/create.test.ts +141 -0
- package/src/accesslayer/credential/create.ts +27 -3
- package/src/accesslayer/credential-activity/create.ts +1 -0
- package/src/accesslayer/credential-refresh/email-delivery.ts +116 -0
- package/src/accesslayer/credential-refresh/index.ts +1 -0
- package/src/accesslayer/credential-refresh/read.ts +8 -2
- package/src/accesslayer/credential-refresh/update.ts +4 -0
- package/src/accesslayer/inbox-batch/store.ts +469 -0
- package/src/accesslayer/inbox-credential/create.ts +51 -19
- package/src/accesslayer/inbox-credential/refresh.ts +221 -0
- package/src/accesslayer/inbox-credential/update.ts +1 -1
- package/src/cache/atomic-counter.test-helpers.ts +27 -0
- package/src/cache/atomic-counter.test.ts +6 -0
- package/src/cache/index.ts +25 -13
- package/src/config/environment.ts +26 -0
- package/src/credential-refresh.ts +5 -1
- package/src/docker-entry.ts +8 -0
- package/src/helpers/activity.helpers.ts +4 -0
- package/src/helpers/app-counter.helpers.ts +1 -1
- package/src/helpers/boost-storage.helpers.test.ts +242 -0
- package/src/helpers/boost.helpers.ts +58 -437
- package/src/helpers/contact-method.helpers.test.ts +43 -0
- package/src/helpers/contact-method.helpers.ts +3 -4
- package/src/helpers/credential-refresh-email-content.helpers.test.ts +222 -0
- package/src/helpers/credential-refresh-email-content.helpers.ts +155 -0
- package/src/helpers/credential-refresh-email.helpers.ts +201 -0
- package/src/helpers/credential-refresh-proof.helpers.test.ts +103 -0
- package/src/helpers/credential-refresh-proof.helpers.ts +43 -0
- package/src/helpers/credential-refresh.helpers.ts +385 -107
- package/src/helpers/credential.helpers.ts +6 -2
- package/src/helpers/finalize-inbox.helpers.ts +39 -22
- package/src/helpers/inbox-batch-http.helpers.test.ts +188 -0
- package/src/helpers/inbox-batch-http.helpers.ts +150 -0
- package/src/helpers/inbox-batch-status.helpers.ts +11 -0
- package/src/helpers/inbox-batch.helpers.test.ts +668 -0
- package/src/helpers/inbox-batch.helpers.ts +374 -0
- package/src/helpers/inbox-issuance-error.helpers.ts +25 -0
- package/src/helpers/inbox-queue.helpers.test.ts +253 -0
- package/src/helpers/inbox-queue.helpers.ts +372 -0
- package/src/helpers/inbox-refresh.helpers.ts +432 -0
- package/src/helpers/inbox.helpers.ts +301 -50
- package/src/helpers/issuedCredentialStatus.helpers.ts +11 -0
- package/src/helpers/notifications.helpers.ts +4 -2
- package/src/helpers/rateLimit.helpers.ts +2 -5
- package/src/helpers/refresh-send-intent.helpers.ts +273 -0
- package/src/helpers/shim.ts +32 -31
- package/src/helpers/signingAuthority.helpers.test.ts +198 -0
- package/src/helpers/signingAuthority.helpers.ts +41 -18
- package/src/helpers/status-list.helpers.test.ts +77 -0
- package/src/helpers/status-list.helpers.ts +31 -8
- package/src/inbox-queue-local.ts +28 -0
- package/src/models/AuthGrant.ts +1 -0
- package/src/models/ConsentFlowTerms.ts +4 -0
- package/src/models/ConsentFlowTransaction.ts +4 -0
- package/src/models/Credential.ts +1 -0
- package/src/models/CredentialActivity.ts +3 -5
- package/src/models/CredentialRefresh.ts +4 -2
- package/src/models/InboxCredential.ts +2 -0
- package/src/models/credential-refresh-constraints.test.ts +8 -3
- package/src/models/credential-refresh-constraints.ts +5 -0
- package/src/openapi.ts +8 -0
- package/src/routes/act-as.test.ts +239 -0
- package/src/routes/app-store.ts +69 -52
- package/src/routes/auth-grants.ts +13 -11
- package/src/routes/boosts.ts +943 -120
- package/src/routes/contracts.ts +55 -7
- package/src/routes/credential-refreshes.test.ts +8 -2
- package/src/routes/credential-refreshes.ts +4 -1
- package/src/routes/credentials.ts +2 -1
- package/src/routes/inbox.ts +95 -49
- package/src/routes/index.ts +164 -88
- package/src/routes/skills.ts +1 -1
- package/src/routes/workflows.ts +80 -31
- package/src/services/delivery/adapters/postmark.adapter.test.ts +54 -0
- package/src/services/delivery/adapters/postmark.adapter.ts +12 -0
- package/src/services/registry/registry.factory.ts +2 -1
- package/src/types/activity.ts +2 -0
- package/src/types/consentflowcontract.ts +21 -3
- package/src/types/credential-refresh.ts +21 -2
- package/src/types/credential.ts +13 -1
- package/src/types/inbox-batch.ts +46 -0
- package/test/app-store-listing.spec.ts +66 -30
- package/test/atomic-counter.e2e.ts +12 -0
- package/test/auth-grant.spec.ts +21 -21
- package/test/bitstring-status-list.spec.ts +12 -9
- package/test/consentflow.spec.ts +453 -26
- package/test/credential-refresh-email.spec.ts +663 -0
- package/test/credential-refresh-publication.spec.ts +13 -5
- package/test/guardian-gated-routes.spec.ts +337 -180
- package/test/helpers/inbox-e2e-environment.ts +6 -0
- package/test/inbox-batch.spec.ts +1338 -0
- package/test/inbox-refresh.spec.ts +534 -0
- package/test/inbox-security.e2e.ts +48 -3
- package/test/openapi.spec.ts +41 -1
- package/test/refresh-send.spec.ts +1799 -0
- package/test/registry.spec.ts +56 -11
- package/test/revoke-suspend-per-instance.spec.ts +9 -1
- package/vitest.config.ts +13 -0
- package/vitest.inbox-e2e.config.ts +5 -1
- package/vitest.integration.config.ts +2 -0
|
@@ -0,0 +1,242 @@
|
|
|
1
|
+
import { beforeEach, describe, expect, it, vi } from 'vitest';
|
|
2
|
+
import type { JWE, VC } from '@learncard/types';
|
|
3
|
+
|
|
4
|
+
const mocks = vi.hoisted(() => ({
|
|
5
|
+
decrypt: vi.fn(),
|
|
6
|
+
issue: vi.fn(),
|
|
7
|
+
store: vi.fn(async (_credential: unknown) => ({ id: 'stored' })),
|
|
8
|
+
instanceOf: vi.fn(),
|
|
9
|
+
sent: vi.fn(),
|
|
10
|
+
contract: vi.fn(),
|
|
11
|
+
listing: vi.fn(),
|
|
12
|
+
accept: vi.fn(),
|
|
13
|
+
notify: vi.fn(async () => undefined),
|
|
14
|
+
signingAuthority: vi.fn(),
|
|
15
|
+
}));
|
|
16
|
+
|
|
17
|
+
vi.mock('@models', () => ({}));
|
|
18
|
+
vi.mock('@services/skills-provider/inject', () => ({
|
|
19
|
+
injectObv3AlignmentsIntoCredentialForBoost: vi.fn(),
|
|
20
|
+
}));
|
|
21
|
+
vi.mock('@accesslayer/boost/relationships/read', () => ({}));
|
|
22
|
+
vi.mock('./uri.helpers', () => ({
|
|
23
|
+
constructUri: (kind: string, id: string, domain: string) =>
|
|
24
|
+
`lc:network:${domain}/${kind}:${id}`,
|
|
25
|
+
}));
|
|
26
|
+
vi.mock('@accesslayer/credential/create', () => ({ storeCredential: mocks.store }));
|
|
27
|
+
vi.mock('@accesslayer/boost/relationships/create', () => ({
|
|
28
|
+
createBoostInstanceOfRelationship: mocks.instanceOf,
|
|
29
|
+
}));
|
|
30
|
+
vi.mock('@accesslayer/credential/relationships/create', () => ({
|
|
31
|
+
createSentCredentialRelationship: mocks.sent,
|
|
32
|
+
createCredentialIssuedViaContractRelationship: mocks.contract,
|
|
33
|
+
createListingSentCredentialRelationship: mocks.listing,
|
|
34
|
+
}));
|
|
35
|
+
vi.mock('./credential.helpers', () => ({
|
|
36
|
+
acceptCredential: mocks.accept,
|
|
37
|
+
getCredentialUri: (id: string, domain: string) => `lc:network:${domain}/credential:${id}`,
|
|
38
|
+
}));
|
|
39
|
+
vi.mock('./learnCard.helpers', () => ({
|
|
40
|
+
getLearnCard: async () => ({
|
|
41
|
+
id: { did: () => 'did:example:brain', keypair: () => ({}) },
|
|
42
|
+
invoke: {
|
|
43
|
+
decryptDagJwe: mocks.decrypt,
|
|
44
|
+
issueCredential: mocks.issue,
|
|
45
|
+
resolveDid: async () => ({}),
|
|
46
|
+
},
|
|
47
|
+
}),
|
|
48
|
+
}));
|
|
49
|
+
vi.mock('./signingAuthority.helpers', () => ({
|
|
50
|
+
issueCredentialWithSigningAuthority: mocks.signingAuthority,
|
|
51
|
+
}));
|
|
52
|
+
vi.mock('./notifications.helpers', () => ({ addNotificationToQueue: mocks.notify }));
|
|
53
|
+
vi.mock('./notificationMessages', () => ({ getNotificationMessage: () => 'Received' }));
|
|
54
|
+
vi.mock('./getRecipientLocale.helpers', () => ({ resolveRecipientLocale: async () => 'en' }));
|
|
55
|
+
vi.mock('./did.helpers', () => ({
|
|
56
|
+
getDidWeb: (domain: string, id: string) => `did:web:${domain}:users:${id}`,
|
|
57
|
+
}));
|
|
58
|
+
vi.mock('./status-list.helpers', () => ({
|
|
59
|
+
appendBitstringStatusListEntries: async (credential: unknown) => credential,
|
|
60
|
+
}));
|
|
61
|
+
vi.mock('@tracing', () => ({
|
|
62
|
+
trace: async (_kind: string, _name: string, action: () => unknown) => action(),
|
|
63
|
+
traceDb: async (_name: string, action: () => unknown) => action(),
|
|
64
|
+
traceCrypto: async (_name: string, action: () => unknown) => action(),
|
|
65
|
+
traceInternal: async (_name: string, action: () => unknown) => action(),
|
|
66
|
+
}));
|
|
67
|
+
|
|
68
|
+
import { issueClaimLinkBoost, sendBoost } from './boost.helpers';
|
|
69
|
+
|
|
70
|
+
const vc = {
|
|
71
|
+
'@context': ['https://www.w3.org/2018/credentials/v1'],
|
|
72
|
+
type: ['VerifiableCredential', 'BoostCredential'],
|
|
73
|
+
issuer: 'did:example:issuer',
|
|
74
|
+
issuanceDate: '2026-01-01T00:00:00Z',
|
|
75
|
+
credentialSubject: { id: 'did:example:subject' },
|
|
76
|
+
boostId: 'lc:network:network.example/boost:boost',
|
|
77
|
+
proof: {
|
|
78
|
+
type: 'Ed25519Signature2020',
|
|
79
|
+
created: '2026-01-01T00:00:00Z',
|
|
80
|
+
proofPurpose: 'assertionMethod',
|
|
81
|
+
verificationMethod: 'did:example:issuer#key',
|
|
82
|
+
},
|
|
83
|
+
} as VC;
|
|
84
|
+
const jwe: JWE = {
|
|
85
|
+
protected: 'header',
|
|
86
|
+
iv: 'iv',
|
|
87
|
+
ciphertext: 'ciphertext',
|
|
88
|
+
tag: 'tag',
|
|
89
|
+
recipients: [],
|
|
90
|
+
};
|
|
91
|
+
const options = {
|
|
92
|
+
from: { type: 'profile', profile: { profileId: 'org' } },
|
|
93
|
+
to: { profileId: 'student' },
|
|
94
|
+
boost: { dataValues: { id: 'boost', boost: JSON.stringify(vc) } },
|
|
95
|
+
credential: jwe,
|
|
96
|
+
domain: 'network.example',
|
|
97
|
+
autoAcceptCredential: true,
|
|
98
|
+
contractTerms: { id: 'terms' },
|
|
99
|
+
listingId: 'listing',
|
|
100
|
+
metadata: { source: 'test' },
|
|
101
|
+
activityId: 'activity',
|
|
102
|
+
integrationId: 'integration',
|
|
103
|
+
} as unknown as Parameters<typeof sendBoost>[0];
|
|
104
|
+
|
|
105
|
+
describe('boost payload storage', () => {
|
|
106
|
+
beforeEach(() => {
|
|
107
|
+
vi.clearAllMocks();
|
|
108
|
+
mocks.decrypt.mockResolvedValue(vc);
|
|
109
|
+
mocks.issue.mockImplementation(async unsigned => ({ ...unsigned, proof: {} }));
|
|
110
|
+
});
|
|
111
|
+
|
|
112
|
+
it.each([
|
|
113
|
+
['encrypted', jwe],
|
|
114
|
+
['issuer-signed', vc],
|
|
115
|
+
['pre-signed without a Boost claim', { ...vc, boostId: undefined }],
|
|
116
|
+
[
|
|
117
|
+
'ordinary VC without a Boost claim',
|
|
118
|
+
{ ...vc, type: ['VerifiableCredential'], boostId: undefined },
|
|
119
|
+
],
|
|
120
|
+
[
|
|
121
|
+
'serialized issuance result',
|
|
122
|
+
JSON.parse(
|
|
123
|
+
JSON.stringify({ kind: 'issued-credential', credential: jwe, statusEntries: [] })
|
|
124
|
+
),
|
|
125
|
+
],
|
|
126
|
+
] as const)(
|
|
127
|
+
'stores %s payload unchanged and preserves graph, claim, and notification behavior',
|
|
128
|
+
async (_kind, credential) => {
|
|
129
|
+
const uri = await sendBoost({ ...options, credential });
|
|
130
|
+
expect(uri).toBe('lc:network:network.example/credential:stored');
|
|
131
|
+
expect(mocks.store.mock.calls[0]?.[0]).toBe(credential);
|
|
132
|
+
expect(mocks.decrypt).not.toHaveBeenCalled();
|
|
133
|
+
expect(mocks.issue).not.toHaveBeenCalled();
|
|
134
|
+
expect(mocks.instanceOf).toHaveBeenCalledExactlyOnceWith(
|
|
135
|
+
{ id: 'stored' },
|
|
136
|
+
options.boost
|
|
137
|
+
);
|
|
138
|
+
expect(mocks.sent).toHaveBeenCalledExactlyOnceWith(
|
|
139
|
+
options.from,
|
|
140
|
+
options.to,
|
|
141
|
+
{ id: 'stored' },
|
|
142
|
+
options.metadata,
|
|
143
|
+
'activity',
|
|
144
|
+
'integration'
|
|
145
|
+
);
|
|
146
|
+
expect(mocks.contract).toHaveBeenCalledExactlyOnceWith(
|
|
147
|
+
{ id: 'stored' },
|
|
148
|
+
options.contractTerms
|
|
149
|
+
);
|
|
150
|
+
expect(mocks.listing).toHaveBeenCalledExactlyOnceWith(
|
|
151
|
+
'listing',
|
|
152
|
+
options.to,
|
|
153
|
+
{ id: 'stored' },
|
|
154
|
+
options.metadata,
|
|
155
|
+
'activity',
|
|
156
|
+
'integration'
|
|
157
|
+
);
|
|
158
|
+
expect(mocks.accept).toHaveBeenCalledExactlyOnceWith(options.to, uri, {
|
|
159
|
+
skipNotification: false,
|
|
160
|
+
});
|
|
161
|
+
expect(mocks.notify).toHaveBeenCalledOnce();
|
|
162
|
+
}
|
|
163
|
+
);
|
|
164
|
+
|
|
165
|
+
it('does not inspect template-derived fields or add a network signature', async () => {
|
|
166
|
+
const credential = { ...vc, display: { backgroundColor: '#bad' } };
|
|
167
|
+
await sendBoost({ ...options, credential });
|
|
168
|
+
expect(mocks.store.mock.calls[0]?.[0]).toBe(credential);
|
|
169
|
+
expect(mocks.decrypt).not.toHaveBeenCalled();
|
|
170
|
+
expect(mocks.issue).not.toHaveBeenCalled();
|
|
171
|
+
});
|
|
172
|
+
|
|
173
|
+
it.each(['lc:network:network.example/boost:other', '', null])(
|
|
174
|
+
'rejects a plaintext credential with an explicit conflicting boostId (%s) before storage',
|
|
175
|
+
async boostId => {
|
|
176
|
+
await expect(
|
|
177
|
+
sendBoost({ ...options, credential: { ...vc, boostId } })
|
|
178
|
+
).rejects.toMatchObject({
|
|
179
|
+
code: 'BAD_REQUEST',
|
|
180
|
+
});
|
|
181
|
+
expect(mocks.store).not.toHaveBeenCalled();
|
|
182
|
+
expect(mocks.instanceOf).not.toHaveBeenCalled();
|
|
183
|
+
expect(mocks.sent).not.toHaveBeenCalled();
|
|
184
|
+
}
|
|
185
|
+
);
|
|
186
|
+
|
|
187
|
+
it.each([
|
|
188
|
+
['Boost', ['VerifiableCredential', 'BoostCredential']],
|
|
189
|
+
['OBv3', ['VerifiableCredential', 'OpenBadgeCredential']],
|
|
190
|
+
['VC', ['VerifiableCredential']],
|
|
191
|
+
])(
|
|
192
|
+
'issues a %s claim-link template with only supported Boost metadata',
|
|
193
|
+
async (_kind, type) => {
|
|
194
|
+
const issued = { kind: 'issued-credential', credential: jwe, statusEntries: [] };
|
|
195
|
+
mocks.signingAuthority.mockResolvedValue(issued);
|
|
196
|
+
const boost = {
|
|
197
|
+
...options.boost,
|
|
198
|
+
dataValues: {
|
|
199
|
+
id: 'boost',
|
|
200
|
+
boost: JSON.stringify({
|
|
201
|
+
...vc,
|
|
202
|
+
type,
|
|
203
|
+
boostId: undefined,
|
|
204
|
+
credentialSubject: [{ name: 'First' }, { name: 'Second' }],
|
|
205
|
+
}),
|
|
206
|
+
},
|
|
207
|
+
} as Parameters<typeof issueClaimLinkBoost>[0];
|
|
208
|
+
const authority = { relationship: { did: 'did:example:sa' } } as Parameters<
|
|
209
|
+
typeof issueClaimLinkBoost
|
|
210
|
+
>[4];
|
|
211
|
+
await issueClaimLinkBoost(boost, options.domain, options.from, options.to, authority);
|
|
212
|
+
expect(mocks.signingAuthority.mock.calls[0]![1].credentialSubject).toEqual([
|
|
213
|
+
{ name: 'First', id: 'did:web:network.example:users:student' },
|
|
214
|
+
{ name: 'Second', id: 'did:web:network.example:users:student' },
|
|
215
|
+
]);
|
|
216
|
+
const unsigned = mocks.signingAuthority.mock.calls[0]![1];
|
|
217
|
+
if (type.includes('BoostCredential')) {
|
|
218
|
+
expect(unsigned.boostId).toBe('lc:network:network.example/boost:boost');
|
|
219
|
+
} else {
|
|
220
|
+
expect(unsigned).not.toHaveProperty('boostId');
|
|
221
|
+
}
|
|
222
|
+
expect(mocks.store).toHaveBeenCalledWith(issued);
|
|
223
|
+
}
|
|
224
|
+
);
|
|
225
|
+
|
|
226
|
+
it('preserves explicit notification and acceptance opt-outs', async () => {
|
|
227
|
+
await sendBoost({
|
|
228
|
+
...options,
|
|
229
|
+
skipNotification: true,
|
|
230
|
+
autoAcceptCredential: false,
|
|
231
|
+
contractTerms: undefined,
|
|
232
|
+
listingId: undefined,
|
|
233
|
+
});
|
|
234
|
+
expect(mocks.store.mock.calls[0]?.[0]).toBe(jwe);
|
|
235
|
+
expect(mocks.instanceOf).toHaveBeenCalledOnce();
|
|
236
|
+
expect(mocks.sent).toHaveBeenCalledOnce();
|
|
237
|
+
expect(mocks.accept).not.toHaveBeenCalled();
|
|
238
|
+
expect(mocks.notify).not.toHaveBeenCalled();
|
|
239
|
+
expect(mocks.contract).not.toHaveBeenCalled();
|
|
240
|
+
expect(mocks.listing).not.toHaveBeenCalled();
|
|
241
|
+
});
|
|
242
|
+
});
|