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