@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,7 +1,7 @@
|
|
|
1
|
-
import { CARWriterStream } from 'carstream'
|
|
2
|
-
import { createFileEncoderStream } from '@storacha/upload-client/unixfs'
|
|
3
|
-
import * as Type from '../types.js'
|
|
4
|
-
import { createFileWithMetadata } from '../utils/file-metadata.js'
|
|
1
|
+
import { CARWriterStream } from 'carstream'
|
|
2
|
+
import { createFileEncoderStream } from '@storacha/upload-client/unixfs'
|
|
3
|
+
import * as Type from '../types.js'
|
|
4
|
+
import { createFileWithMetadata } from '../utils/file-metadata.js'
|
|
5
5
|
/**
|
|
6
6
|
* Encrypt and upload a file to the Storacha network
|
|
7
7
|
*
|
|
@@ -13,17 +13,31 @@ import { createFileWithMetadata } from '../utils/file-metadata.js';
|
|
|
13
13
|
* @param {Type.UploadOptions} [uploadOptions] - User-provided upload options
|
|
14
14
|
* @returns {Promise<Type.AnyLink>} - The link to the uploaded file
|
|
15
15
|
*/
|
|
16
|
-
export const encryptAndUpload = async (
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
16
|
+
export const encryptAndUpload = async (
|
|
17
|
+
storachaClient,
|
|
18
|
+
cryptoAdapter,
|
|
19
|
+
file,
|
|
20
|
+
encryptionConfig,
|
|
21
|
+
uploadOptions = {}
|
|
22
|
+
) => {
|
|
23
|
+
// Step 1: Validate required configuration
|
|
24
|
+
if (!encryptionConfig.spaceDID) throw new Error('No space selected!')
|
|
25
|
+
// Step 2: Encrypt the file using the crypto adapter
|
|
26
|
+
const encryptedPayload = await encryptFile(
|
|
27
|
+
cryptoAdapter,
|
|
28
|
+
file,
|
|
29
|
+
encryptionConfig
|
|
30
|
+
)
|
|
31
|
+
// Step 3: Build and upload the encrypted metadata to the Storacha network
|
|
32
|
+
const rootCid = await buildAndUploadEncryptedMetadata(
|
|
33
|
+
storachaClient,
|
|
34
|
+
encryptedPayload,
|
|
35
|
+
cryptoAdapter,
|
|
36
|
+
uploadOptions
|
|
37
|
+
)
|
|
38
|
+
// Step 4: Return the root CID of the encrypted metadata
|
|
39
|
+
return rootCid
|
|
40
|
+
}
|
|
27
41
|
/**
|
|
28
42
|
* Upload encrypted metadata to the Storacha network
|
|
29
43
|
*
|
|
@@ -33,33 +47,46 @@ export const encryptAndUpload = async (storachaClient, cryptoAdapter, file, encr
|
|
|
33
47
|
* @param {Type.UploadOptions} [uploadOptions] - The upload options
|
|
34
48
|
* @returns {Promise<Type.AnyLink>} - The link to the uploaded metadata
|
|
35
49
|
*/
|
|
36
|
-
const buildAndUploadEncryptedMetadata = async (
|
|
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
|
-
}
|
|
50
|
+
const buildAndUploadEncryptedMetadata = async (
|
|
51
|
+
storachaClient,
|
|
52
|
+
encryptedPayload,
|
|
53
|
+
cryptoAdapter,
|
|
54
|
+
uploadOptions
|
|
55
|
+
) => {
|
|
56
|
+
const { encryptedKey, metadata, encryptedBlobLike } = encryptedPayload
|
|
57
|
+
return storachaClient.uploadCAR(
|
|
58
|
+
{
|
|
59
|
+
stream() {
|
|
60
|
+
/** @type {any} */
|
|
61
|
+
let root
|
|
62
|
+
return createFileEncoderStream(encryptedBlobLike)
|
|
63
|
+
.pipeThrough(
|
|
64
|
+
new TransformStream({
|
|
65
|
+
transform(block, controller) {
|
|
66
|
+
root = block
|
|
67
|
+
controller.enqueue(block)
|
|
68
|
+
},
|
|
69
|
+
async flush(controller) {
|
|
70
|
+
if (!root) throw new Error('missing root block')
|
|
71
|
+
const { cid, bytes } = await cryptoAdapter.encodeMetadata(
|
|
72
|
+
root.cid.toString(),
|
|
73
|
+
encryptedKey,
|
|
74
|
+
metadata
|
|
75
|
+
)
|
|
76
|
+
controller.enqueue({ cid, bytes })
|
|
77
|
+
},
|
|
78
|
+
})
|
|
79
|
+
)
|
|
80
|
+
.pipeThrough(new CARWriterStream())
|
|
81
|
+
},
|
|
82
|
+
},
|
|
83
|
+
{
|
|
84
|
+
...uploadOptions,
|
|
85
|
+
// the encrypted data won't be published to Filecoin, so we need to set pieceHasher to undefined
|
|
86
|
+
pieceHasher: undefined,
|
|
87
|
+
}
|
|
88
|
+
)
|
|
89
|
+
}
|
|
63
90
|
/**
|
|
64
91
|
* Encrypt a file with embedded metadata using the crypto adapter and return the encrypted payload.
|
|
65
92
|
* The encrypted payload contains the encrypted file, the encrypted symmetric key, and the metadata.
|
|
@@ -71,18 +98,27 @@ const buildAndUploadEncryptedMetadata = async (storachaClient, encryptedPayload,
|
|
|
71
98
|
* @returns {Promise<Type.EncryptionPayload>} - The encrypted file
|
|
72
99
|
*/
|
|
73
100
|
const encryptFile = async (cryptoAdapter, file, encryptionConfig) => {
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
101
|
+
// Step 1: Embed metadata in file content if provided
|
|
102
|
+
const fileWithMetadata = createFileWithMetadata(
|
|
103
|
+
file,
|
|
104
|
+
encryptionConfig.fileMetadata
|
|
105
|
+
)
|
|
106
|
+
// Step 2: Encrypt the file (with embedded metadata) using the crypto adapter
|
|
107
|
+
const { key, iv, encryptedStream } = await cryptoAdapter.encryptStream(
|
|
108
|
+
fileWithMetadata
|
|
109
|
+
)
|
|
110
|
+
// Step 3: Use crypto adapter to encrypt the symmetric key
|
|
111
|
+
const keyResult = await cryptoAdapter.encryptSymmetricKey(
|
|
112
|
+
key,
|
|
113
|
+
iv,
|
|
114
|
+
encryptionConfig
|
|
115
|
+
)
|
|
116
|
+
// Step 4: Return the encrypted payload (no separate metadata needed)
|
|
117
|
+
return {
|
|
118
|
+
strategy: keyResult.strategy,
|
|
119
|
+
encryptedKey: keyResult.encryptedKey,
|
|
120
|
+
metadata: keyResult.metadata,
|
|
121
|
+
encryptedBlobLike: { stream: () => encryptedStream },
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
//# sourceMappingURL=encrypt-handler.js.map
|
package/dist/index.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export { create } from
|
|
2
|
-
//# sourceMappingURL=index.d.ts.map
|
|
1
|
+
export { create } from './core/client.js'
|
|
2
|
+
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export { create } from './core/client.js'
|
|
2
|
-
//# sourceMappingURL=index.js.map
|
|
1
|
+
export { create } from './core/client.js'
|
|
2
|
+
//# sourceMappingURL=index.js.map
|
package/dist/protocols/lit.d.ts
CHANGED
|
@@ -1,13 +1,22 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Get a LitClient instance.
|
|
3
3
|
*/
|
|
4
|
-
export function getLitClient(): Promise<LitNodeClient
|
|
4
|
+
export function getLitClient(): Promise<LitNodeClient>
|
|
5
5
|
/**
|
|
6
6
|
* @param {LitNodeClient} litClient
|
|
7
7
|
* @param {Type.SessionSignatureOptions} param0
|
|
8
8
|
* @returns {Promise<import('@lit-protocol/types').SessionSigsMap>}
|
|
9
9
|
*/
|
|
10
|
-
export function getSessionSigs(
|
|
10
|
+
export function getSessionSigs(
|
|
11
|
+
litClient: LitNodeClient,
|
|
12
|
+
{
|
|
13
|
+
wallet,
|
|
14
|
+
accessControlConditions,
|
|
15
|
+
dataToEncryptHash,
|
|
16
|
+
expiration,
|
|
17
|
+
capabilityAuthSigs,
|
|
18
|
+
}: Type.SessionSignatureOptions
|
|
19
|
+
): Promise<import('@lit-protocol/types').SessionSigsMap>
|
|
11
20
|
/**
|
|
12
21
|
* Get session signatures for a PKP key and auth method.
|
|
13
22
|
* There is not need to execute the auth callback for this function, because the auth method provided.
|
|
@@ -16,10 +25,25 @@ export function getSessionSigs(litClient: LitNodeClient, { wallet, accessControl
|
|
|
16
25
|
* @param {Type.PkpSessionSignatureOptions} options
|
|
17
26
|
* @returns {Promise<import('@lit-protocol/types').SessionSigsMap>}
|
|
18
27
|
*/
|
|
19
|
-
export function getPkpSessionSigs(
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
28
|
+
export function getPkpSessionSigs(
|
|
29
|
+
litClient: LitNodeClient,
|
|
30
|
+
{
|
|
31
|
+
pkpPublicKey,
|
|
32
|
+
authMethod,
|
|
33
|
+
accessControlConditions,
|
|
34
|
+
dataToEncryptHash,
|
|
35
|
+
expiration,
|
|
36
|
+
capabilityAuthSigs,
|
|
37
|
+
}: Type.PkpSessionSignatureOptions
|
|
38
|
+
): Promise<import('@lit-protocol/types').SessionSigsMap>
|
|
39
|
+
export { encryptString } from '@lit-protocol/encryption'
|
|
40
|
+
export function getAccessControlConditions(
|
|
41
|
+
spaceDID: Type.SpaceDID
|
|
42
|
+
): import('@lit-protocol/types').AccessControlConditions
|
|
43
|
+
export function executeUcanValidationAction(
|
|
44
|
+
litClient: LitNodeClient,
|
|
45
|
+
options: Type.ExecuteUcanValidationOptions
|
|
46
|
+
): Promise<any>
|
|
47
|
+
import { LitNodeClient } from '@lit-protocol/lit-node-client'
|
|
48
|
+
import * as Type from '../types.js'
|
|
49
|
+
//# sourceMappingURL=lit.d.ts.map
|
package/dist/protocols/lit.js
CHANGED
|
@@ -1,10 +1,15 @@
|
|
|
1
|
-
import { LitNodeClient } from '@lit-protocol/lit-node-client'
|
|
2
|
-
import { LIT_ABILITY } from '@lit-protocol/constants'
|
|
3
|
-
import {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
1
|
+
import { LitNodeClient } from '@lit-protocol/lit-node-client'
|
|
2
|
+
import { LIT_ABILITY } from '@lit-protocol/constants'
|
|
3
|
+
import {
|
|
4
|
+
generateAuthSig,
|
|
5
|
+
LitActionResource,
|
|
6
|
+
createSiweMessage,
|
|
7
|
+
LitAccessControlConditionResource,
|
|
8
|
+
} from '@lit-protocol/auth-helpers'
|
|
9
|
+
import env from '../config/env.js'
|
|
10
|
+
import * as Type from '../types.js'
|
|
11
|
+
import { STORACHA_LIT_ACTION_CID } from '../config/constants.js'
|
|
12
|
+
export { encryptString } from '@lit-protocol/encryption'
|
|
8
13
|
/**
|
|
9
14
|
* Create access control conditions required to use Lit Protocol.
|
|
10
15
|
* This ensures that the Storacha Lit Action is used to validate decryption permissions for the specified space DID.
|
|
@@ -13,68 +18,85 @@ export { encryptString } from '@lit-protocol/encryption';
|
|
|
13
18
|
* @returns {import('@lit-protocol/types').AccessControlConditions} - The access control conditions
|
|
14
19
|
*/
|
|
15
20
|
export const getAccessControlConditions = (spaceDID) => {
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
}
|
|
21
|
+
return [
|
|
22
|
+
{
|
|
23
|
+
contractAddress: '',
|
|
24
|
+
standardContractType: '',
|
|
25
|
+
chain: 'ethereum',
|
|
26
|
+
method: '',
|
|
27
|
+
parameters: [':currentActionIpfsId', spaceDID],
|
|
28
|
+
returnValueTest: {
|
|
29
|
+
comparator: '=',
|
|
30
|
+
value: STORACHA_LIT_ACTION_CID,
|
|
31
|
+
},
|
|
32
|
+
},
|
|
33
|
+
]
|
|
34
|
+
}
|
|
30
35
|
/**
|
|
31
36
|
* Get a LitClient instance.
|
|
32
37
|
*/
|
|
33
38
|
export async function getLitClient() {
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
39
|
+
const litNodeClient = new LitNodeClient({
|
|
40
|
+
litNetwork: env.LIT_NETWORK,
|
|
41
|
+
debug: env.LIT_DEBUG,
|
|
42
|
+
})
|
|
43
|
+
await litNodeClient.connect()
|
|
44
|
+
return litNodeClient
|
|
40
45
|
}
|
|
41
46
|
/**
|
|
42
47
|
* @param {LitNodeClient} litClient
|
|
43
48
|
* @param {Type.SessionSignatureOptions} param0
|
|
44
49
|
* @returns {Promise<import('@lit-protocol/types').SessionSigsMap>}
|
|
45
50
|
*/
|
|
46
|
-
export async function getSessionSigs(
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
+
export async function getSessionSigs(
|
|
52
|
+
litClient,
|
|
53
|
+
{
|
|
54
|
+
wallet,
|
|
55
|
+
accessControlConditions,
|
|
56
|
+
dataToEncryptHash,
|
|
57
|
+
expiration,
|
|
58
|
+
capabilityAuthSigs,
|
|
59
|
+
}
|
|
60
|
+
) {
|
|
61
|
+
const accsResourceString =
|
|
62
|
+
await LitAccessControlConditionResource.generateResourceString(
|
|
63
|
+
accessControlConditions,
|
|
64
|
+
dataToEncryptHash
|
|
65
|
+
)
|
|
66
|
+
const sessionSigs = await litClient.getSessionSigs({
|
|
67
|
+
chain: 'ethereum',
|
|
68
|
+
capabilityAuthSigs,
|
|
69
|
+
expiration,
|
|
70
|
+
resourceAbilityRequests: [
|
|
71
|
+
{
|
|
72
|
+
resource: new LitAccessControlConditionResource(accsResourceString),
|
|
73
|
+
ability: LIT_ABILITY.AccessControlConditionDecryption,
|
|
74
|
+
},
|
|
75
|
+
{
|
|
76
|
+
resource: new LitActionResource('*'),
|
|
77
|
+
ability: LIT_ABILITY.LitActionExecution,
|
|
78
|
+
},
|
|
79
|
+
],
|
|
80
|
+
authNeededCallback: async ({
|
|
81
|
+
uri,
|
|
82
|
+
expiration,
|
|
83
|
+
resourceAbilityRequests,
|
|
84
|
+
}) => {
|
|
85
|
+
const toSign = await createSiweMessage({
|
|
86
|
+
uri,
|
|
51
87
|
expiration,
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
uri,
|
|
65
|
-
expiration,
|
|
66
|
-
resources: resourceAbilityRequests,
|
|
67
|
-
walletAddress: wallet.address,
|
|
68
|
-
nonce: await litClient.getLatestBlockhash(),
|
|
69
|
-
litNodeClient: litClient,
|
|
70
|
-
});
|
|
71
|
-
return await generateAuthSig({
|
|
72
|
-
signer: wallet,
|
|
73
|
-
toSign,
|
|
74
|
-
});
|
|
75
|
-
},
|
|
76
|
-
});
|
|
77
|
-
return sessionSigs;
|
|
88
|
+
resources: resourceAbilityRequests,
|
|
89
|
+
walletAddress: wallet.address,
|
|
90
|
+
nonce: await litClient.getLatestBlockhash(),
|
|
91
|
+
litNodeClient: litClient,
|
|
92
|
+
})
|
|
93
|
+
return await generateAuthSig({
|
|
94
|
+
signer: wallet,
|
|
95
|
+
toSign,
|
|
96
|
+
})
|
|
97
|
+
},
|
|
98
|
+
})
|
|
99
|
+
return sessionSigs
|
|
78
100
|
}
|
|
79
101
|
/**
|
|
80
102
|
* Get session signatures for a PKP key and auth method.
|
|
@@ -84,25 +106,39 @@ export async function getSessionSigs(litClient, { wallet, accessControlCondition
|
|
|
84
106
|
* @param {Type.PkpSessionSignatureOptions} options
|
|
85
107
|
* @returns {Promise<import('@lit-protocol/types').SessionSigsMap>}
|
|
86
108
|
*/
|
|
87
|
-
export async function getPkpSessionSigs(
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
109
|
+
export async function getPkpSessionSigs(
|
|
110
|
+
litClient,
|
|
111
|
+
{
|
|
112
|
+
pkpPublicKey,
|
|
113
|
+
authMethod,
|
|
114
|
+
accessControlConditions,
|
|
115
|
+
dataToEncryptHash,
|
|
116
|
+
expiration,
|
|
117
|
+
capabilityAuthSigs,
|
|
118
|
+
}
|
|
119
|
+
) {
|
|
120
|
+
const accsResourceString =
|
|
121
|
+
await LitAccessControlConditionResource.generateResourceString(
|
|
122
|
+
accessControlConditions,
|
|
123
|
+
dataToEncryptHash
|
|
124
|
+
)
|
|
125
|
+
const sessionSigs = await litClient.getPkpSessionSigs({
|
|
126
|
+
pkpPublicKey,
|
|
127
|
+
authMethods: [authMethod],
|
|
128
|
+
resourceAbilityRequests: [
|
|
129
|
+
{
|
|
130
|
+
resource: new LitAccessControlConditionResource(accsResourceString),
|
|
131
|
+
ability: LIT_ABILITY.AccessControlConditionDecryption,
|
|
132
|
+
},
|
|
133
|
+
{
|
|
134
|
+
resource: new LitActionResource('*'),
|
|
135
|
+
ability: LIT_ABILITY.LitActionExecution,
|
|
136
|
+
},
|
|
137
|
+
],
|
|
138
|
+
expiration,
|
|
139
|
+
capabilityAuthSigs,
|
|
140
|
+
})
|
|
141
|
+
return sessionSigs
|
|
106
142
|
}
|
|
107
143
|
/**
|
|
108
144
|
*
|
|
@@ -111,24 +147,24 @@ export async function getPkpSessionSigs(litClient, { pkpPublicKey, authMethod, a
|
|
|
111
147
|
* @returns
|
|
112
148
|
*/
|
|
113
149
|
export const executeUcanValidationAction = async (litClient, options) => {
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
/** @type string*/ (litActionResponse.response)
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
}
|
|
134
|
-
//# sourceMappingURL=lit.js.map
|
|
150
|
+
const { sessionSigs, ...jsParams } = options
|
|
151
|
+
const litActionResponse = await litClient.executeJs({
|
|
152
|
+
ipfsId: STORACHA_LIT_ACTION_CID,
|
|
153
|
+
sessionSigs,
|
|
154
|
+
jsParams,
|
|
155
|
+
})
|
|
156
|
+
if (!litActionResponse.response) {
|
|
157
|
+
throw new Error('Error getting lit action response.')
|
|
158
|
+
}
|
|
159
|
+
const parsedResponse = JSON.parse(
|
|
160
|
+
/** @type string*/ (litActionResponse.response)
|
|
161
|
+
)
|
|
162
|
+
const decryptedData = parsedResponse.decryptedString
|
|
163
|
+
if (!decryptedData) {
|
|
164
|
+
let errorMsg
|
|
165
|
+
if (parsedResponse.error) errorMsg = parsedResponse.error
|
|
166
|
+
throw new Error(`Decrypted data does not exist! Error message: ${errorMsg}`)
|
|
167
|
+
}
|
|
168
|
+
return decryptedData
|
|
169
|
+
}
|
|
170
|
+
//# sourceMappingURL=lit.js.map
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export {}
|
|
2
|
-
//# sourceMappingURL=cid-verification.spec.d.ts.map
|
|
1
|
+
export {}
|
|
2
|
+
//# sourceMappingURL=cid-verification.spec.d.ts.map
|