@enbox/dwn-sdk-js 0.4.9 → 0.4.10
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.mjs +1 -1
- package/dist/browser.mjs.map +4 -4
- package/dist/esm/generated/precompiled-validators.js +1262 -3888
- package/dist/esm/generated/precompiled-validators.js.map +1 -1
- package/dist/esm/src/core/constants.js +0 -26
- package/dist/esm/src/core/constants.js.map +1 -1
- package/dist/esm/src/core/encryption-control.js +0 -10
- package/dist/esm/src/core/encryption-control.js.map +1 -1
- package/dist/esm/src/core/replication-apply.js.map +1 -1
- package/dist/esm/src/index.js +1 -1
- package/dist/esm/src/index.js.map +1 -1
- package/dist/esm/src/interfaces/records-write.js +0 -9
- package/dist/esm/src/interfaces/records-write.js.map +1 -1
- package/dist/esm/src/utils/encryption.js +2 -7
- package/dist/esm/src/utils/encryption.js.map +1 -1
- package/dist/esm/src/utils/hd-key.js +0 -27
- package/dist/esm/src/utils/hd-key.js.map +1 -1
- package/dist/esm/src/utils/protocols.js +23 -51
- package/dist/esm/src/utils/protocols.js.map +1 -1
- package/dist/esm/src/utils/records.js +17 -31
- package/dist/esm/src/utils/records.js.map +1 -1
- package/dist/esm/tests/core/constants.spec.js +1 -11
- package/dist/esm/tests/core/constants.spec.js.map +1 -1
- package/dist/esm/tests/core/validation-read-closure.spec.js +1 -1
- package/dist/esm/tests/core/validation-read-closure.spec.js.map +1 -1
- package/dist/esm/tests/features/protocol-composition.spec.js +15 -60
- package/dist/esm/tests/features/protocol-composition.spec.js.map +1 -1
- package/dist/esm/tests/handlers/records-delete.spec.js +1 -1
- package/dist/esm/tests/handlers/records-delete.spec.js.map +1 -1
- package/dist/esm/tests/handlers/records-read.spec.js +15 -13
- package/dist/esm/tests/handlers/records-read.spec.js.map +1 -1
- package/dist/esm/tests/handlers/records-write.spec.js +10 -10
- package/dist/esm/tests/handlers/records-write.spec.js.map +1 -1
- package/dist/esm/tests/interfaces/protocols-configure.spec.js +5 -5
- package/dist/esm/tests/interfaces/protocols-configure.spec.js.map +1 -1
- package/dist/esm/tests/interfaces/records-write.spec.js +5 -51
- package/dist/esm/tests/interfaces/records-write.spec.js.map +1 -1
- package/dist/esm/tests/scenarios/end-to-end-tests.spec.js +2 -2
- package/dist/esm/tests/scenarios/end-to-end-tests.spec.js.map +1 -1
- package/dist/esm/tests/utils/encryption-callbacks.spec.js +18 -30
- package/dist/esm/tests/utils/encryption-callbacks.spec.js.map +1 -1
- package/dist/esm/tests/utils/encryption-control-test-utils.js +1 -1
- package/dist/esm/tests/utils/encryption-control-test-utils.js.map +1 -1
- package/dist/esm/tests/utils/encryption.spec.js +30 -33
- package/dist/esm/tests/utils/encryption.spec.js.map +1 -1
- package/dist/esm/tests/utils/test-data-generator.js +76 -24
- package/dist/esm/tests/utils/test-data-generator.js.map +1 -1
- package/dist/esm/tests/validation/json-schemas/protocols/protocols-configure.spec.js +1 -1
- package/dist/esm/tests/validation/json-schemas/protocols/protocols-configure.spec.js.map +1 -1
- package/dist/types/generated/precompiled-validators.d.ts +88 -120
- package/dist/types/generated/precompiled-validators.d.ts.map +1 -1
- package/dist/types/src/core/constants.d.ts +0 -13
- package/dist/types/src/core/constants.d.ts.map +1 -1
- package/dist/types/src/core/encryption-control.d.ts +0 -1
- package/dist/types/src/core/encryption-control.d.ts.map +1 -1
- package/dist/types/src/core/replication-apply.d.ts +0 -7
- package/dist/types/src/core/replication-apply.d.ts.map +1 -1
- package/dist/types/src/index.d.ts +1 -1
- package/dist/types/src/index.d.ts.map +1 -1
- package/dist/types/src/interfaces/records-write.d.ts +0 -4
- package/dist/types/src/interfaces/records-write.d.ts.map +1 -1
- package/dist/types/src/utils/encryption.d.ts +0 -3
- package/dist/types/src/utils/encryption.d.ts.map +1 -1
- package/dist/types/src/utils/hd-key.d.ts +1 -11
- package/dist/types/src/utils/hd-key.d.ts.map +1 -1
- package/dist/types/src/utils/protocols.d.ts +2 -7
- package/dist/types/src/utils/protocols.d.ts.map +1 -1
- package/dist/types/src/utils/records.d.ts +1 -8
- package/dist/types/src/utils/records.d.ts.map +1 -1
- package/dist/types/tests/features/protocol-composition.spec.d.ts.map +1 -1
- package/dist/types/tests/handlers/records-read.spec.d.ts.map +1 -1
- package/dist/types/tests/scenarios/end-to-end-tests.spec.d.ts.map +1 -1
- package/dist/types/tests/utils/test-data-generator.d.ts +17 -1
- package/dist/types/tests/utils/test-data-generator.d.ts.map +1 -1
- package/package.json +3 -3
- package/src/core/constants.ts +0 -30
- package/src/core/encryption-control.ts +1 -17
- package/src/core/replication-apply.ts +0 -8
- package/src/index.ts +0 -1
- package/src/interfaces/records-write.ts +0 -13
- package/src/utils/encryption.ts +2 -15
- package/src/utils/hd-key.ts +1 -32
- package/src/utils/protocols.ts +15 -78
- package/src/utils/records.ts +15 -57
- package/dist/esm/tests/validation/json-schemas/encryption/delivery.spec.js +0 -47
- package/dist/esm/tests/validation/json-schemas/encryption/delivery.spec.js.map +0 -1
- package/dist/esm/tests/validation/json-schemas/encryption/grant-key.spec.js +0 -72
- package/dist/esm/tests/validation/json-schemas/encryption/grant-key.spec.js.map +0 -1
- package/dist/types/tests/validation/json-schemas/encryption/delivery.spec.d.ts +0 -2
- package/dist/types/tests/validation/json-schemas/encryption/delivery.spec.d.ts.map +0 -1
- package/dist/types/tests/validation/json-schemas/encryption/grant-key.spec.d.ts +0 -2
- package/dist/types/tests/validation/json-schemas/encryption/grant-key.spec.d.ts.map +0 -1
package/src/utils/protocols.ts
CHANGED
|
@@ -1,10 +1,7 @@
|
|
|
1
|
-
import type { DerivedPrivateJwk } from '../utils/hd-key.js';
|
|
2
1
|
import type { EncryptionKeyDeriver } from '../types/encryption-types.js';
|
|
3
|
-
import type { PrivateKeyJwk, PublicKeyJwk } from '../types/jose-types.js';
|
|
4
2
|
import type { ProtocolDefinition, ProtocolRuleSet } from '../types/protocols-types.js';
|
|
5
3
|
|
|
6
|
-
import {
|
|
7
|
-
import { HdKey, KeyDerivationScheme } from '../utils/hd-key.js';
|
|
4
|
+
import { KeyDerivationScheme } from '../utils/hd-key.js';
|
|
8
5
|
|
|
9
6
|
/**
|
|
10
7
|
* Result of parsing a cross-protocol reference in `alias:path` format.
|
|
@@ -116,104 +113,44 @@ export class Protocols {
|
|
|
116
113
|
* because their records belong to the referenced protocol, whose own encryption keys govern them.
|
|
117
114
|
* Children of `$ref` nodes are still processed because they belong to the composing protocol.
|
|
118
115
|
*
|
|
119
|
-
*
|
|
120
|
-
*
|
|
116
|
+
* Accepts an EncryptionKeyDeriver that performs key derivation internally.
|
|
117
|
+
* The private key never leaves the caller's boundary.
|
|
121
118
|
*/
|
|
122
119
|
public static async deriveAndInjectPublicEncryptionKeys(
|
|
123
120
|
protocolDefinition: ProtocolDefinition,
|
|
124
121
|
keyDeriver: EncryptionKeyDeriver,
|
|
125
|
-
): Promise<ProtocolDefinition>;
|
|
126
|
-
|
|
127
|
-
/**
|
|
128
|
-
* Overload 2 (raw-key): Takes rootKeyId and raw PrivateKeyJwk directly.
|
|
129
|
-
*/
|
|
130
|
-
public static async deriveAndInjectPublicEncryptionKeys(
|
|
131
|
-
protocolDefinition: ProtocolDefinition,
|
|
132
|
-
rootKeyId: string,
|
|
133
|
-
privateJwk: PrivateKeyJwk,
|
|
134
|
-
): Promise<ProtocolDefinition>;
|
|
135
|
-
|
|
136
|
-
// Implementation dispatches based on argument type.
|
|
137
|
-
public static async deriveAndInjectPublicEncryptionKeys(
|
|
138
|
-
protocolDefinition: ProtocolDefinition,
|
|
139
|
-
rootKeyIdOrKeyDeriver: string | EncryptionKeyDeriver,
|
|
140
|
-
privateJwk?: PrivateKeyJwk,
|
|
141
122
|
): Promise<ProtocolDefinition> {
|
|
142
123
|
// clone before modify
|
|
143
124
|
const clone = JSON.parse(JSON.stringify(protocolDefinition)) as ProtocolDefinition;
|
|
144
125
|
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
clone.$keyAgreement = {
|
|
150
|
-
publicKeyJwk: await keyDeriver.derivePublicKey(basePath),
|
|
151
|
-
};
|
|
152
|
-
|
|
153
|
-
async function injectKeysViaCallback(
|
|
154
|
-
ruleSet: ProtocolRuleSet, parentPath: string[],
|
|
155
|
-
): Promise<void> {
|
|
156
|
-
for (const key in ruleSet) {
|
|
157
|
-
if (!key.startsWith('$')) {
|
|
158
|
-
const currentPath = [...parentPath, key];
|
|
159
|
-
const childRuleSet = ruleSet[key] as ProtocolRuleSet;
|
|
160
|
-
|
|
161
|
-
// Skip $ref nodes — they are governed by the referenced protocol's encryption keys.
|
|
162
|
-
// Still recurse into children, which belong to the composing protocol.
|
|
163
|
-
if (childRuleSet.$ref !== undefined) {
|
|
164
|
-
await injectKeysViaCallback(childRuleSet, currentPath);
|
|
165
|
-
continue;
|
|
166
|
-
}
|
|
167
|
-
|
|
168
|
-
const publicKeyJwk = await keyDeriver.derivePublicKey(currentPath);
|
|
169
|
-
childRuleSet.$keyAgreement = { publicKeyJwk };
|
|
170
|
-
await injectKeysViaCallback(childRuleSet, currentPath);
|
|
171
|
-
}
|
|
172
|
-
}
|
|
173
|
-
}
|
|
174
|
-
|
|
175
|
-
await injectKeysViaCallback(clone.structure as ProtocolRuleSet, basePath);
|
|
176
|
-
return clone;
|
|
177
|
-
}
|
|
178
|
-
|
|
179
|
-
// Raw-key path
|
|
180
|
-
const rootKeyId = rootKeyIdOrKeyDeriver;
|
|
126
|
+
const basePath = [KeyDerivationScheme.ProtocolPath, protocolDefinition.protocol];
|
|
127
|
+
clone.$keyAgreement = {
|
|
128
|
+
publicKeyJwk: await keyDeriver.derivePublicKey(basePath),
|
|
129
|
+
};
|
|
181
130
|
|
|
182
|
-
|
|
183
|
-
|
|
131
|
+
async function injectKeys(
|
|
132
|
+
ruleSet: ProtocolRuleSet, parentPath: string[],
|
|
133
|
+
): Promise<void> {
|
|
184
134
|
for (const key in ruleSet) {
|
|
185
|
-
// if we encounter a nested rule set (a property name that doesn't begin with '$'), recursively inject the `$keyAgreement` property
|
|
186
135
|
if (!key.startsWith('$')) {
|
|
187
|
-
const
|
|
136
|
+
const currentPath = [...parentPath, key];
|
|
188
137
|
const childRuleSet = ruleSet[key] as ProtocolRuleSet;
|
|
189
138
|
|
|
190
139
|
// Skip $ref nodes — they are governed by the referenced protocol's encryption keys.
|
|
191
140
|
// Still recurse into children, which belong to the composing protocol.
|
|
192
141
|
if (childRuleSet.$ref !== undefined) {
|
|
193
|
-
await
|
|
142
|
+
await injectKeys(childRuleSet, currentPath);
|
|
194
143
|
continue;
|
|
195
144
|
}
|
|
196
145
|
|
|
197
|
-
const publicKeyJwk = await
|
|
198
|
-
|
|
146
|
+
const publicKeyJwk = await keyDeriver.derivePublicKey(currentPath);
|
|
199
147
|
childRuleSet.$keyAgreement = { publicKeyJwk };
|
|
200
|
-
await
|
|
148
|
+
await injectKeys(childRuleSet, currentPath);
|
|
201
149
|
}
|
|
202
150
|
}
|
|
203
151
|
}
|
|
204
152
|
|
|
205
|
-
|
|
206
|
-
const rootKey: DerivedPrivateJwk = {
|
|
207
|
-
derivationScheme : KeyDerivationScheme.ProtocolPath,
|
|
208
|
-
derivedPrivateKey : privateJwk!,
|
|
209
|
-
rootKeyId
|
|
210
|
-
};
|
|
211
|
-
const protocolLevelDerivedKey = await HdKey.derivePrivateKey(rootKey, [KeyDerivationScheme.ProtocolPath, protocolDefinition.protocol]);
|
|
212
|
-
clone.$keyAgreement = {
|
|
213
|
-
publicKeyJwk: await X25519.getPublicKey({ key: protocolLevelDerivedKey.derivedPrivateKey }) as PublicKeyJwk,
|
|
214
|
-
};
|
|
215
|
-
await addEncryptionProperty(clone.structure as ProtocolRuleSet, protocolLevelDerivedKey);
|
|
216
|
-
|
|
153
|
+
await injectKeys(clone.structure as ProtocolRuleSet, basePath);
|
|
217
154
|
return clone;
|
|
218
155
|
}
|
|
219
156
|
}
|
package/src/utils/records.ts
CHANGED
|
@@ -1,7 +1,5 @@
|
|
|
1
1
|
import type { DerivedPrivateJwk } from './hd-key.js';
|
|
2
|
-
import type { Jwk } from '@enbox/crypto';
|
|
3
2
|
import type { KeyDecrypter } from '../types/encryption-types.js';
|
|
4
|
-
import type { PublicKeyJwk } from '../types/jose-types.js';
|
|
5
3
|
import type { X25519KeyEncryption } from './encryption.js';
|
|
6
4
|
import type { Filter, KeyValues, StartsWithFilter } from '../types/query-types.js';
|
|
7
5
|
import type { GenericMessage, GenericSignaturePayload, MessageSort } from '../types/message-types.js';
|
|
@@ -63,31 +61,12 @@ export class Records {
|
|
|
63
61
|
|
|
64
62
|
/**
|
|
65
63
|
* Decrypts the encrypted data in a message reply.
|
|
66
|
-
*
|
|
67
|
-
* Overload 1 (callback-based): Accepts a KeyDecrypter that performs
|
|
68
|
-
* X25519-HKDF key agreement + AES Key Unwrap internally.
|
|
64
|
+
* Accepts a KeyDecrypter that performs X25519-HKDF key agreement + AES Key Unwrap internally.
|
|
69
65
|
*/
|
|
70
66
|
public static async decrypt(
|
|
71
67
|
recordsWrite: RecordsWriteMessage,
|
|
72
68
|
keyDecrypter: KeyDecrypter,
|
|
73
69
|
cipherStream: ReadableStream<Uint8Array>,
|
|
74
|
-
): Promise<ReadableStream<Uint8Array>>;
|
|
75
|
-
|
|
76
|
-
/**
|
|
77
|
-
* Overload 2 (raw-key): Takes DerivedPrivateJwk directly.
|
|
78
|
-
* @param ancestorPrivateKey Any ancestor private key in the key derivation path.
|
|
79
|
-
*/
|
|
80
|
-
public static async decrypt(
|
|
81
|
-
recordsWrite: RecordsWriteMessage,
|
|
82
|
-
ancestorPrivateKey: DerivedPrivateJwk,
|
|
83
|
-
cipherStream: ReadableStream<Uint8Array>,
|
|
84
|
-
): Promise<ReadableStream<Uint8Array>>;
|
|
85
|
-
|
|
86
|
-
// Implementation dispatches based on argument type.
|
|
87
|
-
public static async decrypt(
|
|
88
|
-
recordsWrite: RecordsWriteMessage,
|
|
89
|
-
keyOrDecrypter: DerivedPrivateJwk | KeyDecrypter,
|
|
90
|
-
cipherStream: ReadableStream<Uint8Array>,
|
|
91
70
|
): Promise<ReadableStream<Uint8Array>> {
|
|
92
71
|
const { encryption } = recordsWrite;
|
|
93
72
|
if (encryption === undefined) {
|
|
@@ -101,27 +80,21 @@ export class Records {
|
|
|
101
80
|
const actualDataCid = await Cid.computeDagPbCidFromBytes(ciphertext);
|
|
102
81
|
Records.validateEncryptedDataIntegrity(recordsWrite, actualDataCid, ciphertext.byteLength);
|
|
103
82
|
|
|
104
|
-
const { fullDerivationPath,
|
|
105
|
-
await Records.findMatchingKeyEncryption(recordsWrite,
|
|
83
|
+
const { fullDerivationPath, matchingKeyEncryption } =
|
|
84
|
+
await Records.findMatchingKeyEncryption(recordsWrite, keyDecrypter);
|
|
106
85
|
|
|
107
86
|
if (matchingKeyEncryption === undefined) {
|
|
108
87
|
throw new DwnError(
|
|
109
88
|
DwnErrorCode.RecordsDecryptNoMatchingKeyEncryptedFound,
|
|
110
|
-
`Unable to find a matching key encryption entry for '${
|
|
89
|
+
`Unable to find a matching key encryption entry for '${keyDecrypter.rootKeyId}' and '${keyDecrypter.derivationScheme}'.`
|
|
111
90
|
);
|
|
112
91
|
}
|
|
113
92
|
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
ephemeralPublicKey : matchingKeyEncryption.ephemeralPublicKey,
|
|
120
|
-
keyEncryption : matchingKeyEncryption,
|
|
121
|
-
});
|
|
122
|
-
} else {
|
|
123
|
-
cek = await Encryption.unwrapKey(leafPrivateKey!, matchingKeyEncryption);
|
|
124
|
-
}
|
|
93
|
+
const cek = await keyDecrypter.decrypt(fullDerivationPath, {
|
|
94
|
+
encryptedKey : Encoder.base64UrlToBytes(matchingKeyEncryption.encryptedKey),
|
|
95
|
+
ephemeralPublicKey : matchingKeyEncryption.ephemeralPublicKey,
|
|
96
|
+
keyEncryption : matchingKeyEncryption,
|
|
97
|
+
});
|
|
125
98
|
|
|
126
99
|
const iv = Encoder.base64UrlToBytes(encryption.initializationVector);
|
|
127
100
|
const plaintext = await Encryption.decrypt(encryption.algorithm, cek, iv, ciphertext);
|
|
@@ -132,33 +105,18 @@ export class Records {
|
|
|
132
105
|
|
|
133
106
|
private static async findMatchingKeyEncryption(
|
|
134
107
|
recordsWrite: RecordsWriteMessage,
|
|
135
|
-
|
|
136
|
-
): Promise<{ fullDerivationPath: string[];
|
|
108
|
+
keyDecrypter: KeyDecrypter,
|
|
109
|
+
): Promise<{ fullDerivationPath: string[]; matchingKeyEncryption?: X25519KeyEncryption }> {
|
|
137
110
|
const { encryption } = recordsWrite;
|
|
138
|
-
const fullDerivationPath = Records.constructKeyDerivationPath(
|
|
139
|
-
|
|
140
|
-
if ('decrypt' in keyOrDecrypter) {
|
|
141
|
-
const publicKey = await keyOrDecrypter.derivePublicKey(fullDerivationPath);
|
|
142
|
-
const keyId = await Encryption.getKeyId(publicKey);
|
|
143
|
-
return {
|
|
144
|
-
fullDerivationPath,
|
|
145
|
-
matchingKeyEncryption: encryption!.keyEncryption.find((entry): boolean =>
|
|
146
|
-
entry.derivationScheme === keyOrDecrypter.derivationScheme && entry.keyId === keyId
|
|
147
|
-
),
|
|
148
|
-
};
|
|
149
|
-
}
|
|
150
|
-
|
|
151
|
-
const leafPrivateKeyBytes = await Records.derivePrivateKey(keyOrDecrypter, fullDerivationPath);
|
|
152
|
-
const leafPrivateKey = await X25519.bytesToPrivateKey({ privateKeyBytes: leafPrivateKeyBytes });
|
|
111
|
+
const fullDerivationPath = Records.constructKeyDerivationPath(keyDecrypter.derivationScheme, recordsWrite);
|
|
153
112
|
|
|
154
|
-
const publicKey = await
|
|
155
|
-
const keyId =
|
|
113
|
+
const publicKey = await keyDecrypter.derivePublicKey(fullDerivationPath);
|
|
114
|
+
const keyId = await Encryption.getKeyId(publicKey);
|
|
156
115
|
|
|
157
116
|
return {
|
|
158
117
|
fullDerivationPath,
|
|
159
|
-
leafPrivateKey,
|
|
160
118
|
matchingKeyEncryption: encryption!.keyEncryption.find((entry): boolean =>
|
|
161
|
-
entry.derivationScheme ===
|
|
119
|
+
entry.derivationScheme === keyDecrypter.derivationScheme && entry.keyId === keyId
|
|
162
120
|
),
|
|
163
121
|
};
|
|
164
122
|
}
|
|
@@ -1,47 +0,0 @@
|
|
|
1
|
-
import { validateJsonSchema } from '../../../../src/schema-validator.js';
|
|
2
|
-
import { describe, expect, it } from 'bun:test';
|
|
3
|
-
const delivery = {
|
|
4
|
-
contextId: 'thread-1',
|
|
5
|
-
keyId: 'abcdefghijklmnopqrstuvwxyz0123456789ABCDEFG',
|
|
6
|
-
keyMaterial: {
|
|
7
|
-
algorithm: 'X25519-HKDF-SHA256+A256KW',
|
|
8
|
-
derivationScheme: 'roleAudience',
|
|
9
|
-
keyId: 'abcdefghijklmnopqrstuvwxyz0123456789ABCDEFG',
|
|
10
|
-
privateKeyJwk: {
|
|
11
|
-
crv: 'X25519',
|
|
12
|
-
d: 'private-key',
|
|
13
|
-
kty: 'OKP',
|
|
14
|
-
x: 'public-key',
|
|
15
|
-
},
|
|
16
|
-
publicKeyJwk: {
|
|
17
|
-
crv: 'X25519',
|
|
18
|
-
kty: 'OKP',
|
|
19
|
-
x: 'public-key',
|
|
20
|
-
},
|
|
21
|
-
},
|
|
22
|
-
protocol: 'https://example.com/protocol',
|
|
23
|
-
rolePath: 'thread/participant',
|
|
24
|
-
};
|
|
25
|
-
describe('Delivery Schema', () => {
|
|
26
|
-
it('should accept a roleAudience key delivery payload', () => {
|
|
27
|
-
expect(() => validateJsonSchema('Delivery', delivery)).not.toThrow();
|
|
28
|
-
});
|
|
29
|
-
it('should reject legacy epoch fields', () => {
|
|
30
|
-
const invalidDelivery = {
|
|
31
|
-
...structuredClone(delivery),
|
|
32
|
-
epoch: 1,
|
|
33
|
-
};
|
|
34
|
-
expect(() => validateJsonSchema('Delivery', invalidDelivery)).toThrow();
|
|
35
|
-
});
|
|
36
|
-
it('should reject non-roleAudience key material', () => {
|
|
37
|
-
const invalidDelivery = structuredClone(delivery);
|
|
38
|
-
invalidDelivery.keyMaterial.derivationScheme = 'protocolPath';
|
|
39
|
-
expect(() => validateJsonSchema('Delivery', invalidDelivery)).toThrow();
|
|
40
|
-
});
|
|
41
|
-
it('should reject key IDs that are not base64url thumbprints', () => {
|
|
42
|
-
const invalidDelivery = structuredClone(delivery);
|
|
43
|
-
invalidDelivery.keyMaterial.keyId = 'abcdefghijklmnopqrstuvwxyz0123456789ABCDEF!';
|
|
44
|
-
expect(() => validateJsonSchema('Delivery', invalidDelivery)).toThrow();
|
|
45
|
-
});
|
|
46
|
-
});
|
|
47
|
-
//# sourceMappingURL=delivery.spec.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"delivery.spec.js","sourceRoot":"","sources":["../../../../../../tests/validation/json-schemas/encryption/delivery.spec.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAE,MAAM,qCAAqC,CAAC;AACzE,OAAO,EAAE,QAAQ,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,UAAU,CAAC;AAEhD,MAAM,QAAQ,GAAG;IACf,SAAS,EAAK,UAAU;IACxB,KAAK,EAAS,6CAA6C;IAC3D,WAAW,EAAG;QACZ,SAAS,EAAU,2BAA2B;QAC9C,gBAAgB,EAAG,cAAc;QACjC,KAAK,EAAc,6CAA6C;QAChE,aAAa,EAAM;YACjB,GAAG,EAAG,QAAQ;YACd,CAAC,EAAK,aAAa;YACnB,GAAG,EAAG,KAAK;YACX,CAAC,EAAK,YAAY;SACnB;QACD,YAAY,EAAE;YACZ,GAAG,EAAG,QAAQ;YACd,GAAG,EAAG,KAAK;YACX,CAAC,EAAK,YAAY;SACnB;KACF;IACD,QAAQ,EAAG,8BAA8B;IACzC,QAAQ,EAAG,oBAAoB;CAChC,CAAC;AAEF,QAAQ,CAAC,iBAAiB,EAAE,GAAG,EAAE;IAC/B,EAAE,CAAC,mDAAmD,EAAE,GAAG,EAAE;QAC3D,MAAM,CACJ,GAAG,EAAE,CAAC,kBAAkB,CAAC,UAAU,EAAE,QAAQ,CAAC,CAC/C,CAAC,GAAG,CAAC,OAAO,EAAE,CAAC;IAClB,CAAC,CAAC,CAAC;IAEH,EAAE,CAAC,mCAAmC,EAAE,GAAG,EAAE;QAC3C,MAAM,eAAe,GAAG;YACtB,GAAG,eAAe,CAAC,QAAQ,CAAC;YAC5B,KAAK,EAAE,CAAC;SACT,CAAC;QAEF,MAAM,CACJ,GAAG,EAAE,CAAC,kBAAkB,CAAC,UAAU,EAAE,eAAe,CAAC,CACtD,CAAC,OAAO,EAAE,CAAC;IACd,CAAC,CAAC,CAAC;IAEH,EAAE,CAAC,6CAA6C,EAAE,GAAG,EAAE;QACrD,MAAM,eAAe,GAAG,eAAe,CAAC,QAAQ,CAAC,CAAC;QAClD,eAAe,CAAC,WAAW,CAAC,gBAAgB,GAAG,cAAc,CAAC;QAE9D,MAAM,CACJ,GAAG,EAAE,CAAC,kBAAkB,CAAC,UAAU,EAAE,eAAe,CAAC,CACtD,CAAC,OAAO,EAAE,CAAC;IACd,CAAC,CAAC,CAAC;IAEH,EAAE,CAAC,0DAA0D,EAAE,GAAG,EAAE;QAClE,MAAM,eAAe,GAAG,eAAe,CAAC,QAAQ,CAAC,CAAC;QAClD,eAAe,CAAC,WAAW,CAAC,KAAK,GAAG,6CAA6C,CAAC;QAElF,MAAM,CACJ,GAAG,EAAE,CAAC,kBAAkB,CAAC,UAAU,EAAE,eAAe,CAAC,CACtD,CAAC,OAAO,EAAE,CAAC;IACd,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"}
|
|
@@ -1,72 +0,0 @@
|
|
|
1
|
-
import { validateJsonSchema } from '../../../../src/schema-validator.js';
|
|
2
|
-
import { describe, expect, it } from 'bun:test';
|
|
3
|
-
const grantKey = {
|
|
4
|
-
grantId: 'grant-id',
|
|
5
|
-
keyMaterial: {
|
|
6
|
-
algorithm: 'X25519-HKDF-SHA256+A256KW',
|
|
7
|
-
derivationPath: ['protocolPath', 'https://example.com/protocol', 'message'],
|
|
8
|
-
derivationScheme: 'protocolPath',
|
|
9
|
-
keyId: 'abcdefghijklmnopqrstuvwxyz0123456789ABCDEFG',
|
|
10
|
-
privateKeyJwk: {
|
|
11
|
-
crv: 'X25519',
|
|
12
|
-
d: 'private-key',
|
|
13
|
-
kty: 'OKP',
|
|
14
|
-
x: 'public-key',
|
|
15
|
-
},
|
|
16
|
-
publicKeyJwk: {
|
|
17
|
-
crv: 'X25519',
|
|
18
|
-
kty: 'OKP',
|
|
19
|
-
x: 'public-key',
|
|
20
|
-
},
|
|
21
|
-
},
|
|
22
|
-
scope: {
|
|
23
|
-
protocol: 'https://example.com/protocol',
|
|
24
|
-
protocolPath: 'message',
|
|
25
|
-
scheme: 'protocolPath',
|
|
26
|
-
},
|
|
27
|
-
};
|
|
28
|
-
describe('GrantKey Schema', () => {
|
|
29
|
-
it('should accept protocolPath derivation paths', () => {
|
|
30
|
-
expect(() => validateJsonSchema('GrantKey', grantKey)).not.toThrow();
|
|
31
|
-
});
|
|
32
|
-
it('should reject derivation paths that do not start with protocolPath', () => {
|
|
33
|
-
const invalidGrantKey = structuredClone(grantKey);
|
|
34
|
-
invalidGrantKey.keyMaterial.derivationPath[0] = 'unsupported';
|
|
35
|
-
expect(() => validateJsonSchema('GrantKey', invalidGrantKey)).toThrow();
|
|
36
|
-
});
|
|
37
|
-
it('should reject empty derivation path segments', () => {
|
|
38
|
-
const invalidGrantKey = structuredClone(grantKey);
|
|
39
|
-
invalidGrantKey.keyMaterial.derivationPath[2] = '';
|
|
40
|
-
expect(() => validateJsonSchema('GrantKey', invalidGrantKey)).toThrow();
|
|
41
|
-
});
|
|
42
|
-
it('should reject derivation paths with too many segments', () => {
|
|
43
|
-
const invalidGrantKey = structuredClone(grantKey);
|
|
44
|
-
invalidGrantKey.keyMaterial.derivationPath = [
|
|
45
|
-
'protocolPath',
|
|
46
|
-
'https://example.com/protocol',
|
|
47
|
-
'a',
|
|
48
|
-
'b',
|
|
49
|
-
'c',
|
|
50
|
-
'd',
|
|
51
|
-
'e',
|
|
52
|
-
'f',
|
|
53
|
-
'g',
|
|
54
|
-
'h',
|
|
55
|
-
'i',
|
|
56
|
-
'j',
|
|
57
|
-
'k',
|
|
58
|
-
];
|
|
59
|
-
expect(() => validateJsonSchema('GrantKey', invalidGrantKey)).toThrow();
|
|
60
|
-
});
|
|
61
|
-
it('should reject key IDs that are not base64url thumbprints', () => {
|
|
62
|
-
const invalidGrantKey = structuredClone(grantKey);
|
|
63
|
-
invalidGrantKey.keyMaterial.keyId = 'abcdefghijklmnopqrstuvwxyz0123456789ABCDEF!';
|
|
64
|
-
expect(() => validateJsonSchema('GrantKey', invalidGrantKey)).toThrow();
|
|
65
|
-
});
|
|
66
|
-
it('should reject unsupported key material algorithms', () => {
|
|
67
|
-
const invalidGrantKey = structuredClone(grantKey);
|
|
68
|
-
invalidGrantKey.keyMaterial.algorithm = 'unsupported';
|
|
69
|
-
expect(() => validateJsonSchema('GrantKey', invalidGrantKey)).toThrow();
|
|
70
|
-
});
|
|
71
|
-
});
|
|
72
|
-
//# sourceMappingURL=grant-key.spec.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"grant-key.spec.js","sourceRoot":"","sources":["../../../../../../tests/validation/json-schemas/encryption/grant-key.spec.ts"],"names":[],"mappings":"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"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"delivery.spec.d.ts","sourceRoot":"","sources":["../../../../../../tests/validation/json-schemas/encryption/delivery.spec.ts"],"names":[],"mappings":""}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"grant-key.spec.d.ts","sourceRoot":"","sources":["../../../../../../tests/validation/json-schemas/encryption/grant-key.spec.ts"],"names":[],"mappings":""}
|