@storacha/encrypt-upload-client 1.1.56 → 1.1.58
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/config/constants.d.ts +3 -3
- package/dist/config/constants.js +4 -3
- package/dist/config/env.d.ts +9 -6
- package/dist/config/service.d.ts +13 -13
- package/dist/core/client.d.ts +54 -41
- package/dist/core/client.js +68 -56
- package/dist/core/errors.d.ts +6 -6
- package/dist/core/metadata/encrypted-metadata.d.ts +13 -8
- package/dist/core/metadata/kms-metadata.d.ts +68 -36
- package/dist/core/metadata/lit-metadata.d.ts +63 -28
- package/dist/crypto/adapters/kms-crypto-adapter.d.ts +172 -137
- package/dist/crypto/adapters/lit-crypto-adapter.d.ts +107 -86
- package/dist/crypto/factories.browser.d.ts +9 -5
- package/dist/crypto/factories.browser.js +15 -7
- package/dist/crypto/factories.node.d.ts +13 -6
- package/dist/crypto/factories.node.js +19 -13
- package/dist/crypto/index.d.ts +5 -5
- package/dist/crypto/index.js +5 -5
- package/dist/crypto/symmetric/generic-aes-ctr-streaming-crypto.d.ts +58 -54
- package/dist/crypto/symmetric/generic-aes-ctr-streaming-crypto.js +174 -146
- package/dist/crypto/symmetric/node-aes-cbc-crypto.d.ts +36 -32
- package/dist/crypto/symmetric/node-aes-cbc-crypto.js +101 -95
- package/dist/examples/decrypt-test.d.ts +2 -2
- package/dist/examples/decrypt-test.js +78 -69
- package/dist/examples/encrypt-test.d.ts +5 -3
- package/dist/examples/encrypt-test.js +58 -55
- package/dist/handlers/decrypt-handler.d.ts +19 -5
- package/dist/handlers/encrypt-handler.d.ts +9 -3
- package/dist/handlers/encrypt-handler.js +93 -57
- package/dist/index.d.ts +2 -2
- package/dist/index.js +2 -2
- package/dist/protocols/lit.d.ts +33 -9
- package/dist/protocols/lit.js +134 -98
- package/dist/test/cid-verification.spec.d.ts +2 -2
- package/dist/test/cid-verification.spec.js +341 -313
- package/dist/test/crypto-compatibility.spec.d.ts +2 -2
- package/dist/test/crypto-compatibility.spec.js +184 -120
- package/dist/test/crypto-counter-security.spec.d.ts +2 -2
- package/dist/test/crypto-counter-security.spec.js +177 -138
- package/dist/test/crypto-streaming.spec.d.ts +2 -2
- package/dist/test/crypto-streaming.spec.js +208 -126
- package/dist/test/encrypted-metadata.spec.d.ts +2 -2
- package/dist/test/encrypted-metadata.spec.js +89 -62
- package/dist/test/factories.spec.d.ts +2 -2
- package/dist/test/factories.spec.js +275 -139
- package/dist/test/file-metadata.spec.d.ts +2 -2
- package/dist/test/file-metadata.spec.js +472 -416
- package/dist/test/fixtures/test-fixtures.d.ts +25 -20
- package/dist/test/fixtures/test-fixtures.js +61 -53
- package/dist/test/helpers/test-file-utils.d.ts +19 -14
- package/dist/test/helpers/test-file-utils.js +78 -76
- package/dist/test/https-enforcement.spec.d.ts +2 -2
- package/dist/test/https-enforcement.spec.js +278 -124
- package/dist/test/kms-crypto-adapter.spec.d.ts +2 -2
- package/dist/test/kms-crypto-adapter.spec.js +473 -304
- package/dist/test/lit-crypto-adapter.spec.d.ts +2 -2
- package/dist/test/lit-crypto-adapter.spec.js +206 -118
- package/dist/test/memory-efficiency.spec.d.ts +2 -2
- package/dist/test/memory-efficiency.spec.js +100 -87
- package/dist/test/mocks/key-manager.d.ts +71 -38
- package/dist/test/mocks/key-manager.js +129 -113
- package/dist/test/node-crypto-adapter.spec.d.ts +2 -2
- package/dist/test/node-crypto-adapter.spec.js +155 -102
- package/dist/test/node-generic-crypto-adapter.spec.d.ts +2 -2
- package/dist/test/node-generic-crypto-adapter.spec.js +134 -94
- package/dist/test/setup.d.ts +2 -2
- package/dist/test/setup.js +8 -9
- package/dist/tsconfig.spec.tsbuildinfo +1 -1
- package/dist/types.d.ts +219 -181
- package/dist/utils/file-metadata.d.ts +19 -13
- package/dist/utils.d.ts +14 -5
- package/package.json +4 -4
|
@@ -1,129 +1,211 @@
|
|
|
1
|
-
import './setup.js'
|
|
2
|
-
import { test, describe } from 'node:test'
|
|
3
|
-
import assert from 'node:assert'
|
|
4
|
-
import { GenericAesCtrStreamingCrypto } from '../src/crypto/symmetric/generic-aes-ctr-streaming-crypto.js'
|
|
5
|
-
import {
|
|
1
|
+
import './setup.js'
|
|
2
|
+
import { test, describe } from 'node:test'
|
|
3
|
+
import assert from 'node:assert'
|
|
4
|
+
import { GenericAesCtrStreamingCrypto } from '../src/crypto/symmetric/generic-aes-ctr-streaming-crypto.js'
|
|
5
|
+
import {
|
|
6
|
+
createTestFile,
|
|
7
|
+
streamToUint8Array,
|
|
8
|
+
} from './helpers/test-file-utils.js'
|
|
6
9
|
// FIXME (fforbeck) - Remove this skip when ready to run streaming crypto tests. It is failing on CI.
|
|
7
10
|
await describe.skip('Streaming Crypto - Core Functionality', async () => {
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
11
|
+
await test('should encrypt and decrypt small files correctly', async () => {
|
|
12
|
+
const crypto = new GenericAesCtrStreamingCrypto()
|
|
13
|
+
const testFile = createTestFile(0.01) // 10KB (ultra-small for memory safety)
|
|
14
|
+
// Encrypt
|
|
15
|
+
const { key, iv, encryptedStream } = await crypto.encryptStream(testFile)
|
|
16
|
+
assert(key instanceof Uint8Array, 'Key should be Uint8Array')
|
|
17
|
+
assert.strictEqual(key.length, 32, 'Key should be 32 bytes')
|
|
18
|
+
assert(iv instanceof Uint8Array, 'IV should be Uint8Array')
|
|
19
|
+
assert.strictEqual(iv.length, 16, 'IV should be 16 bytes')
|
|
20
|
+
// Convert stream to bytes
|
|
21
|
+
const encryptedBytes = await streamToUint8Array(encryptedStream)
|
|
22
|
+
assert.strictEqual(
|
|
23
|
+
encryptedBytes.length,
|
|
24
|
+
testFile.size,
|
|
25
|
+
'Encrypted size should match original'
|
|
26
|
+
)
|
|
27
|
+
// Decrypt
|
|
28
|
+
const encryptedForDecrypt = new ReadableStream({
|
|
29
|
+
start(controller) {
|
|
30
|
+
controller.enqueue(encryptedBytes)
|
|
31
|
+
controller.close()
|
|
32
|
+
},
|
|
33
|
+
})
|
|
34
|
+
const decryptedStream = await crypto.decryptStream(
|
|
35
|
+
encryptedForDecrypt,
|
|
36
|
+
key,
|
|
37
|
+
iv
|
|
38
|
+
)
|
|
39
|
+
const decryptedBytes = await streamToUint8Array(decryptedStream)
|
|
40
|
+
// Verify round-trip
|
|
41
|
+
const originalBytes = new Uint8Array(await testFile.arrayBuffer())
|
|
42
|
+
assert.deepStrictEqual(
|
|
43
|
+
decryptedBytes,
|
|
44
|
+
originalBytes,
|
|
45
|
+
'Decrypted should match original'
|
|
46
|
+
)
|
|
47
|
+
console.log(`✓ Successfully encrypted/decrypted ${testFile.size} bytes`)
|
|
48
|
+
})
|
|
49
|
+
await test('should handle edge cases', async () => {
|
|
50
|
+
const crypto = new GenericAesCtrStreamingCrypto()
|
|
51
|
+
// Empty file
|
|
52
|
+
const emptyFile = new Blob([])
|
|
53
|
+
const { encryptedStream: emptyEncrypted } = await crypto.encryptStream(
|
|
54
|
+
emptyFile
|
|
55
|
+
)
|
|
56
|
+
const emptyBytes = await streamToUint8Array(emptyEncrypted)
|
|
57
|
+
assert.strictEqual(
|
|
58
|
+
emptyBytes.length,
|
|
59
|
+
0,
|
|
60
|
+
'Empty file should produce empty encrypted data'
|
|
61
|
+
)
|
|
62
|
+
// Single byte
|
|
63
|
+
const singleByteFile = new Blob([new Uint8Array([42])])
|
|
64
|
+
const { key, iv, encryptedStream } = await crypto.encryptStream(
|
|
65
|
+
singleByteFile
|
|
66
|
+
)
|
|
67
|
+
const encryptedBytes = await streamToUint8Array(encryptedStream)
|
|
68
|
+
assert.strictEqual(
|
|
69
|
+
encryptedBytes.length,
|
|
70
|
+
1,
|
|
71
|
+
'Single byte should produce single encrypted byte'
|
|
72
|
+
)
|
|
73
|
+
// Decrypt single byte
|
|
74
|
+
const encryptedForDecrypt = new ReadableStream({
|
|
75
|
+
start(controller) {
|
|
76
|
+
controller.enqueue(encryptedBytes)
|
|
77
|
+
controller.close()
|
|
78
|
+
},
|
|
79
|
+
})
|
|
80
|
+
const decryptedStream = await crypto.decryptStream(
|
|
81
|
+
encryptedForDecrypt,
|
|
82
|
+
key,
|
|
83
|
+
iv
|
|
84
|
+
)
|
|
85
|
+
const decryptedBytes = await streamToUint8Array(decryptedStream)
|
|
86
|
+
assert.deepStrictEqual(
|
|
87
|
+
decryptedBytes,
|
|
88
|
+
new Uint8Array([42]),
|
|
89
|
+
'Should decrypt to original byte'
|
|
90
|
+
)
|
|
91
|
+
console.log('✓ Edge cases handled correctly')
|
|
92
|
+
})
|
|
93
|
+
await test('should handle medium-sized files without issues', async () => {
|
|
94
|
+
try {
|
|
95
|
+
const crypto = new GenericAesCtrStreamingCrypto()
|
|
96
|
+
// Test with progressively larger files to show streaming works consistently
|
|
97
|
+
// Reduced sizes for CI stability while still testing streaming functionality
|
|
98
|
+
const testSizes = [0.5, 1, 2] // MB
|
|
99
|
+
for (const sizeMB of testSizes) {
|
|
100
|
+
console.log(`Testing ${sizeMB}MB file...`)
|
|
101
|
+
const testFile = createTestFile(sizeMB)
|
|
102
|
+
const { key, iv, encryptedStream } = await crypto.encryptStream(
|
|
103
|
+
testFile
|
|
104
|
+
)
|
|
105
|
+
// Convert encrypted stream to bytes first
|
|
106
|
+
const encryptedBytes = await streamToUint8Array(encryptedStream)
|
|
107
|
+
// Create a new stream from the encrypted bytes for decryption
|
|
21
108
|
const encryptedForDecrypt = new ReadableStream({
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
})
|
|
27
|
-
const decryptedStream = await crypto.decryptStream(
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
assert.deepStrictEqual(splitIV, iv, 'Split IV should match original');
|
|
126
|
-
console.log('Complete interface implemented correctly');
|
|
127
|
-
});
|
|
128
|
-
});
|
|
129
|
-
//# sourceMappingURL=crypto-streaming.spec.js.map
|
|
109
|
+
start(controller) {
|
|
110
|
+
controller.enqueue(encryptedBytes)
|
|
111
|
+
controller.close()
|
|
112
|
+
},
|
|
113
|
+
})
|
|
114
|
+
const decryptedStream = await crypto.decryptStream(
|
|
115
|
+
encryptedForDecrypt,
|
|
116
|
+
key,
|
|
117
|
+
iv
|
|
118
|
+
)
|
|
119
|
+
const decryptedBytes = await streamToUint8Array(decryptedStream)
|
|
120
|
+
assert.strictEqual(
|
|
121
|
+
decryptedBytes.length,
|
|
122
|
+
sizeMB * 1024 * 1024,
|
|
123
|
+
`Decrypted file size mismatch for ${sizeMB}MB`
|
|
124
|
+
)
|
|
125
|
+
console.log(`✓ ${sizeMB}MB file encrypted and decrypted successfully`)
|
|
126
|
+
}
|
|
127
|
+
console.log('✓ Medium-sized files handled without issues')
|
|
128
|
+
} catch (err) {
|
|
129
|
+
console.error(
|
|
130
|
+
'Test error (type):',
|
|
131
|
+
typeof err,
|
|
132
|
+
err && err.constructor && err.constructor.name
|
|
133
|
+
)
|
|
134
|
+
console.error('Test error (keys):', err && Object.keys(err))
|
|
135
|
+
console.error('Test error (string):', String(err))
|
|
136
|
+
console.log(err)
|
|
137
|
+
assert.fail('Unable to test medium-sized files')
|
|
138
|
+
}
|
|
139
|
+
})
|
|
140
|
+
await test('should use proper counter arithmetic', async () => {
|
|
141
|
+
const crypto = new GenericAesCtrStreamingCrypto()
|
|
142
|
+
// Test counter increment function directly
|
|
143
|
+
const baseCounter = new Uint8Array([
|
|
144
|
+
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
|
145
|
+
])
|
|
146
|
+
// Increment by 1
|
|
147
|
+
const counter1 = crypto.incrementCounter(baseCounter, 1)
|
|
148
|
+
assert.deepStrictEqual(
|
|
149
|
+
counter1,
|
|
150
|
+
new Uint8Array([0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1]),
|
|
151
|
+
'Should increment last byte by 1'
|
|
152
|
+
)
|
|
153
|
+
// Increment by 255
|
|
154
|
+
const counter255 = crypto.incrementCounter(baseCounter, 255)
|
|
155
|
+
assert.deepStrictEqual(
|
|
156
|
+
counter255,
|
|
157
|
+
new Uint8Array([0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 255]),
|
|
158
|
+
'Should increment last byte by 255'
|
|
159
|
+
)
|
|
160
|
+
// Increment by 256 (should carry)
|
|
161
|
+
const counter256 = crypto.incrementCounter(baseCounter, 256)
|
|
162
|
+
assert.deepStrictEqual(
|
|
163
|
+
counter256,
|
|
164
|
+
new Uint8Array([0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0]),
|
|
165
|
+
'Should carry to second-to-last byte'
|
|
166
|
+
)
|
|
167
|
+
console.log('✓ Counter arithmetic works correctly')
|
|
168
|
+
})
|
|
169
|
+
await test('should implement complete interface', async () => {
|
|
170
|
+
const crypto = new GenericAesCtrStreamingCrypto()
|
|
171
|
+
// Check all required methods exist
|
|
172
|
+
assert(
|
|
173
|
+
typeof crypto.generateKey === 'function',
|
|
174
|
+
'Should have generateKey method'
|
|
175
|
+
)
|
|
176
|
+
assert(
|
|
177
|
+
typeof crypto.encryptStream === 'function',
|
|
178
|
+
'Should have encryptStream method'
|
|
179
|
+
)
|
|
180
|
+
assert(
|
|
181
|
+
typeof crypto.decryptStream === 'function',
|
|
182
|
+
'Should have decryptStream method'
|
|
183
|
+
)
|
|
184
|
+
assert(
|
|
185
|
+
typeof crypto.combineKeyAndIV === 'function',
|
|
186
|
+
'Should have combineKeyAndIV method'
|
|
187
|
+
)
|
|
188
|
+
assert(
|
|
189
|
+
typeof crypto.splitKeyAndIV === 'function',
|
|
190
|
+
'Should have splitKeyAndIV method'
|
|
191
|
+
)
|
|
192
|
+
assert(
|
|
193
|
+
typeof crypto.incrementCounter === 'function',
|
|
194
|
+
'Should have incrementCounter method'
|
|
195
|
+
)
|
|
196
|
+
// Test combine/split methods
|
|
197
|
+
const key = await crypto.generateKey()
|
|
198
|
+
const iv = globalThis.crypto.getRandomValues(new Uint8Array(16))
|
|
199
|
+
const combined = crypto.combineKeyAndIV(key, iv)
|
|
200
|
+
assert.strictEqual(
|
|
201
|
+
combined.length,
|
|
202
|
+
48,
|
|
203
|
+
'Combined should be 48 bytes (32 key + 16 IV)'
|
|
204
|
+
)
|
|
205
|
+
const { key: splitKey, iv: splitIV } = crypto.splitKeyAndIV(combined)
|
|
206
|
+
assert.deepStrictEqual(splitKey, key, 'Split key should match original')
|
|
207
|
+
assert.deepStrictEqual(splitIV, iv, 'Split IV should match original')
|
|
208
|
+
console.log('Complete interface implemented correctly')
|
|
209
|
+
})
|
|
210
|
+
})
|
|
211
|
+
//# sourceMappingURL=crypto-streaming.spec.js.map
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export {}
|
|
2
|
-
//# sourceMappingURL=encrypted-metadata.spec.d.ts.map
|
|
1
|
+
export {}
|
|
2
|
+
//# sourceMappingURL=encrypted-metadata.spec.d.ts.map
|
|
@@ -1,68 +1,95 @@
|
|
|
1
|
-
import assert from 'node:assert'
|
|
2
|
-
import { describe, it } from 'node:test'
|
|
3
|
-
import * as Result from '@storacha/client/result'
|
|
4
|
-
import * as Types from '../src/types.js'
|
|
5
|
-
import { create, extract } from '../src/core/metadata/encrypted-metadata.js'
|
|
6
|
-
import { CID } from 'multiformats'
|
|
1
|
+
import assert from 'node:assert'
|
|
2
|
+
import { describe, it } from 'node:test'
|
|
3
|
+
import * as Result from '@storacha/client/result'
|
|
4
|
+
import * as Types from '../src/types.js'
|
|
5
|
+
import { create, extract } from '../src/core/metadata/encrypted-metadata.js'
|
|
6
|
+
import { CID } from 'multiformats'
|
|
7
7
|
/** @type {Types.LitMetadataInput} */
|
|
8
8
|
const encryptedMetadataInput = {
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
}
|
|
9
|
+
encryptedDataCID:
|
|
10
|
+
'bafkreids275u5ex6xfw7d4k67afej43c6rhm2kzdox2z6or4jxrndgevae',
|
|
11
|
+
identityBoundCiphertext:
|
|
12
|
+
'mF3OPa9dQ0wO4B1/XylmAV/eaHhLtM3JUPIbS175bvmqGaJUYroyDbsytV29q0cLD4XCpCRfCinntASNg9s730FIM7f4Mw2hVWeJ5g4akFA6BoZoaKgDC5Ln6MOQK5Ymb1y6No7um7Bn4uIIJTYNuUukDQvVxzY8LcRBc2ySR1Md+VSGzmyEgyvHtAI=',
|
|
13
|
+
plaintextKeyHash:
|
|
14
|
+
'15f39e9a977cca43f16f3cd25237d711cd8130ff9763197b29df52a198607206',
|
|
15
|
+
accessControlConditions: [
|
|
16
|
+
{
|
|
17
|
+
contractAddress: '',
|
|
18
|
+
standardContractType: '',
|
|
19
|
+
chain: 'ethereum',
|
|
20
|
+
method: '',
|
|
21
|
+
parameters: [
|
|
22
|
+
':currentActionIpfsId',
|
|
23
|
+
'did:key:z6MktfnQz8Kcz5nsC65oyXWFXhbbAZQavjg6LYuHgv4YbxzN',
|
|
24
|
+
],
|
|
25
|
+
returnValueTest: {
|
|
26
|
+
comparator: '=',
|
|
27
|
+
value: 'QmPFrQGo5RAtdSTZ4bkaeDHVGrmy2TeEUwTu4LuVAPHiMd',
|
|
28
|
+
},
|
|
29
|
+
},
|
|
30
|
+
],
|
|
31
|
+
}
|
|
29
32
|
/** @type {Types.KMSMetadata} */
|
|
30
33
|
const kmsMetadataInput = {
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
34
|
+
encryptedDataCID: CID.parse(
|
|
35
|
+
'bafkreihdwdcefgh4dqkjv67uzcmw7ojee6xedzdetojuzjevtenxquvyku'
|
|
36
|
+
),
|
|
37
|
+
encryptedSymmetricKey: 'bXlLTVNLZXlCeXRlcw==', // 'myKMSKeyBytes' in base64 for example
|
|
38
|
+
space: 'did:key:z6MktfnQz8Kcz5nsC65oyXWFXhbbAZQavjg6LYuHgv4YbxzN',
|
|
39
|
+
kms: {
|
|
40
|
+
provider: 'google-kms',
|
|
41
|
+
keyId: 'test-key',
|
|
42
|
+
algorithm: 'RSA-OAEP-2048-SHA256',
|
|
43
|
+
},
|
|
44
|
+
}
|
|
40
45
|
await describe('LitEncrypted Metadata', async () => {
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
46
|
+
await it('should create a valid block content', async () => {
|
|
47
|
+
const encryptedMetadata = create('lit', encryptedMetadataInput)
|
|
48
|
+
const block = await encryptedMetadata.archiveBlock()
|
|
49
|
+
// Encode the block into a CAR file
|
|
50
|
+
const car = await import('@ucanto/core').then((m) =>
|
|
51
|
+
m.CAR.encode({ roots: [block] })
|
|
52
|
+
)
|
|
53
|
+
// Use the extract function to get the JSON object
|
|
54
|
+
const extractedData = Result.unwrap(extract(car))
|
|
55
|
+
const extractedDataJson = extractedData.toJSON()
|
|
56
|
+
assert.equal(
|
|
57
|
+
extractedDataJson.identityBoundCiphertext,
|
|
58
|
+
encryptedMetadataInput.identityBoundCiphertext
|
|
59
|
+
)
|
|
60
|
+
assert.equal(
|
|
61
|
+
extractedDataJson.plaintextKeyHash,
|
|
62
|
+
encryptedMetadataInput.plaintextKeyHash
|
|
63
|
+
)
|
|
64
|
+
assert.equal(
|
|
65
|
+
extractedDataJson.encryptedDataCID,
|
|
66
|
+
encryptedMetadataInput.encryptedDataCID
|
|
67
|
+
)
|
|
68
|
+
assert.deepEqual(
|
|
69
|
+
extractedDataJson.accessControlConditions,
|
|
70
|
+
encryptedMetadataInput.accessControlConditions
|
|
71
|
+
)
|
|
72
|
+
})
|
|
73
|
+
})
|
|
55
74
|
await describe('KMS Encrypted Metadata', async () => {
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
75
|
+
await it('should create a valid block content', async () => {
|
|
76
|
+
const kmsMetadata = create('kms', kmsMetadataInput)
|
|
77
|
+
const block = await kmsMetadata.archiveBlock()
|
|
78
|
+
const car = await import('@ucanto/core').then((m) =>
|
|
79
|
+
m.CAR.encode({ roots: [block] })
|
|
80
|
+
)
|
|
81
|
+
const extractedData = Result.unwrap(extract(car))
|
|
82
|
+
const extractedDataJson = extractedData.toJSON()
|
|
83
|
+
assert.equal(
|
|
84
|
+
extractedDataJson.encryptedSymmetricKey,
|
|
85
|
+
kmsMetadataInput.encryptedSymmetricKey
|
|
86
|
+
)
|
|
87
|
+
assert.equal(
|
|
88
|
+
extractedDataJson.encryptedDataCID,
|
|
89
|
+
kmsMetadataInput.encryptedDataCID
|
|
90
|
+
)
|
|
91
|
+
assert.equal(extractedDataJson.space, kmsMetadataInput.space)
|
|
92
|
+
assert.deepEqual(extractedDataJson.kms, kmsMetadataInput.kms)
|
|
93
|
+
})
|
|
94
|
+
})
|
|
95
|
+
//# sourceMappingURL=encrypted-metadata.spec.js.map
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export {}
|
|
2
|
-
//# sourceMappingURL=factories.spec.d.ts.map
|
|
1
|
+
export {}
|
|
2
|
+
//# sourceMappingURL=factories.spec.d.ts.map
|