@storacha/encrypt-upload-client 1.1.66 → 1.1.67
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/README.md +1 -1
- package/dist/config/constants.d.ts +1 -1
- package/dist/config/constants.d.ts.map +1 -1
- package/dist/config/constants.js +2 -2
- package/dist/config/env.d.ts +0 -1
- package/dist/config/env.d.ts.map +1 -1
- package/dist/config/env.js +0 -7
- package/dist/core/client.js +1 -1
- package/dist/crypto/adapters/lit-crypto-adapter.d.ts +35 -4
- package/dist/crypto/adapters/lit-crypto-adapter.d.ts.map +1 -1
- package/dist/crypto/adapters/lit-crypto-adapter.js +38 -41
- package/dist/crypto/factories.node.d.ts +4 -10
- package/dist/crypto/factories.node.d.ts.map +1 -1
- package/dist/crypto/factories.node.js +6 -16
- package/dist/protocols/lit.d.ts +13 -18
- package/dist/protocols/lit.d.ts.map +1 -1
- package/dist/protocols/lit.js +67 -88
- package/dist/types.d.ts +24 -15
- package/dist/types.d.ts.map +1 -1
- package/dist/utils/file-metadata.d.ts.map +1 -1
- package/dist/utils/file-metadata.js +39 -14
- package/package.json +12 -11
- package/dist/examples/decrypt-test.d.ts +0 -2
- package/dist/examples/decrypt-test.d.ts.map +0 -1
- package/dist/examples/decrypt-test.js +0 -73
- package/dist/examples/encrypt-test.d.ts +0 -4
- package/dist/examples/encrypt-test.d.ts.map +0 -1
- package/dist/examples/encrypt-test.js +0 -61
- package/dist/test/cid-verification.spec.d.ts +0 -2
- package/dist/test/cid-verification.spec.d.ts.map +0 -1
- package/dist/test/cid-verification.spec.js +0 -314
- package/dist/test/crypto-compatibility.spec.d.ts +0 -2
- package/dist/test/crypto-compatibility.spec.d.ts.map +0 -1
- package/dist/test/crypto-compatibility.spec.js +0 -124
- package/dist/test/crypto-counter-security.spec.d.ts +0 -2
- package/dist/test/crypto-counter-security.spec.d.ts.map +0 -1
- package/dist/test/crypto-counter-security.spec.js +0 -147
- package/dist/test/crypto-streaming.spec.d.ts +0 -2
- package/dist/test/crypto-streaming.spec.d.ts.map +0 -1
- package/dist/test/crypto-streaming.spec.js +0 -129
- package/dist/test/encrypted-metadata.spec.d.ts +0 -2
- package/dist/test/encrypted-metadata.spec.d.ts.map +0 -1
- package/dist/test/encrypted-metadata.spec.js +0 -68
- package/dist/test/factories.spec.d.ts +0 -2
- package/dist/test/factories.spec.d.ts.map +0 -1
- package/dist/test/factories.spec.js +0 -142
- package/dist/test/file-metadata.spec.d.ts +0 -2
- package/dist/test/file-metadata.spec.d.ts.map +0 -1
- package/dist/test/file-metadata.spec.js +0 -433
- package/dist/test/fixtures/test-fixtures.d.ts +0 -28
- package/dist/test/fixtures/test-fixtures.d.ts.map +0 -1
- package/dist/test/fixtures/test-fixtures.js +0 -63
- package/dist/test/helpers/test-file-utils.d.ts +0 -60
- package/dist/test/helpers/test-file-utils.d.ts.map +0 -1
- package/dist/test/helpers/test-file-utils.js +0 -139
- package/dist/test/https-enforcement.spec.d.ts +0 -2
- package/dist/test/https-enforcement.spec.d.ts.map +0 -1
- package/dist/test/https-enforcement.spec.js +0 -125
- package/dist/test/kms-crypto-adapter.spec.d.ts +0 -2
- package/dist/test/kms-crypto-adapter.spec.d.ts.map +0 -1
- package/dist/test/kms-crypto-adapter.spec.js +0 -305
- package/dist/test/lit-crypto-adapter.spec.d.ts +0 -2
- package/dist/test/lit-crypto-adapter.spec.d.ts.map +0 -1
- package/dist/test/lit-crypto-adapter.spec.js +0 -120
- package/dist/test/memory-efficiency.spec.d.ts +0 -2
- package/dist/test/memory-efficiency.spec.d.ts.map +0 -1
- package/dist/test/memory-efficiency.spec.js +0 -93
- package/dist/test/mocks/key-manager.d.ts +0 -58
- package/dist/test/mocks/key-manager.d.ts.map +0 -1
- package/dist/test/mocks/key-manager.js +0 -137
- package/dist/test/node-crypto-adapter.spec.d.ts +0 -2
- package/dist/test/node-crypto-adapter.spec.d.ts.map +0 -1
- package/dist/test/node-crypto-adapter.spec.js +0 -103
- package/dist/test/node-generic-crypto-adapter.spec.d.ts +0 -2
- package/dist/test/node-generic-crypto-adapter.spec.d.ts.map +0 -1
- package/dist/test/node-generic-crypto-adapter.spec.js +0 -95
- package/dist/test/setup.d.ts +0 -2
- package/dist/test/setup.d.ts.map +0 -1
- package/dist/test/setup.js +0 -12
- package/dist/tsconfig.spec.tsbuildinfo +0 -1
package/README.md
CHANGED
|
@@ -10,7 +10,7 @@ This library leverages `@storacha/cli` and `@lit-protocol/lit-node-client` to pr
|
|
|
10
10
|
You can add the `@storacha/encrypt-upload-client` package to your JavaScript or TypeScript project with `npm`:
|
|
11
11
|
|
|
12
12
|
```sh
|
|
13
|
-
npm @storacha/encrypt-upload-client
|
|
13
|
+
npm install @storacha/encrypt-upload-client
|
|
14
14
|
```
|
|
15
15
|
|
|
16
16
|
## Usage
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../../src/config/constants.js"],"names":[],"mappings":"AAAA,sCACE,gDAAgD,CAAA;AAClD,
|
|
1
|
+
{"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../../src/config/constants.js"],"names":[],"mappings":"AAAA,sCACE,gDAAgD,CAAA;AAClD,8BAA2D"}
|
package/dist/config/constants.js
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
export const STORACHA_LIT_ACTION_CID = '
|
|
2
|
-
export const GATEWAY_URL = new URL('https://
|
|
1
|
+
export const STORACHA_LIT_ACTION_CID = 'QmPx9EErFABXjzmvRayvJLHcT3pAbJnxxJokvxB4Bq2nTY';
|
|
2
|
+
export const GATEWAY_URL = new URL('https://storacha.link');
|
|
3
3
|
//# sourceMappingURL=constants.js.map
|
package/dist/config/env.d.ts
CHANGED
package/dist/config/env.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"env.d.ts","sourceRoot":"","sources":["../../src/config/env.js"],"names":[],"mappings":";
|
|
1
|
+
{"version":3,"file":"env.d.ts","sourceRoot":"","sources":["../../src/config/env.js"],"names":[],"mappings":";AAiCA;;GAAsC;uBAjCf,cAAc"}
|
package/dist/config/env.js
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { Schema } from '@ucanto/core';
|
|
2
|
-
import { LIT_NETWORK } from '@lit-protocol/constants';
|
|
3
2
|
// Only conditionally load dotenv in Node.js environments to prevent browser bundling issues
|
|
4
3
|
if (typeof window === 'undefined' &&
|
|
5
4
|
typeof process !== 'undefined' &&
|
|
@@ -14,12 +13,6 @@ if (typeof window === 'undefined' &&
|
|
|
14
13
|
}
|
|
15
14
|
}
|
|
16
15
|
const envSchema = Schema.struct({
|
|
17
|
-
LIT_NETWORK: Schema.enum([
|
|
18
|
-
LIT_NETWORK.Custom,
|
|
19
|
-
LIT_NETWORK.Datil,
|
|
20
|
-
LIT_NETWORK.DatilDev,
|
|
21
|
-
LIT_NETWORK.DatilTest,
|
|
22
|
-
]).default(LIT_NETWORK.DatilTest),
|
|
23
16
|
LIT_DEBUG: Schema.boolean().default(false),
|
|
24
17
|
});
|
|
25
18
|
// Safe environment variable access
|
package/dist/core/client.js
CHANGED
|
@@ -54,7 +54,7 @@ export class EncryptedClient {
|
|
|
54
54
|
/**
|
|
55
55
|
* Creates a new EncryptedClient.
|
|
56
56
|
*
|
|
57
|
-
* If no Gateway URL is provided, the default value of 'https://
|
|
57
|
+
* If no Gateway URL is provided, the default value of 'https://storacha.link' will be used.
|
|
58
58
|
*
|
|
59
59
|
* @param {Type.EncryptedClientOptions} options
|
|
60
60
|
*/
|
|
@@ -11,11 +11,42 @@ export class LitCryptoAdapter implements Type.CryptoAdapter {
|
|
|
11
11
|
* Create a new Lit crypto adapter
|
|
12
12
|
*
|
|
13
13
|
* @param {Type.SymmetricCrypto} symmetricCrypto - The symmetric crypto implementation (browser or node)
|
|
14
|
-
* @param {import('@lit-protocol/lit-
|
|
14
|
+
* @param {import('@lit-protocol/lit-client').LitClientType} litClient - The Lit client instance
|
|
15
|
+
* @param {Type.AuthManager} authManager - The Lit Auth Manager instance
|
|
15
16
|
*/
|
|
16
|
-
constructor(symmetricCrypto: Type.SymmetricCrypto, litClient: import("@lit-protocol/lit-
|
|
17
|
+
constructor(symmetricCrypto: Type.SymmetricCrypto, litClient: import("@lit-protocol/lit-client").LitClientType, authManager: Type.AuthManager);
|
|
17
18
|
symmetricCrypto: Type.SymmetricCrypto;
|
|
18
|
-
litClient:
|
|
19
|
+
litClient: {
|
|
20
|
+
encrypt: (params: import("@lit-protocol/types").EncryptSdkParams) => Promise<import("@lit-protocol/types").EncryptResponse>;
|
|
21
|
+
decrypt: (params: import("@lit-protocol/types").DecryptRequest) => Promise<import("@lit-protocol/types").DecryptResponse>;
|
|
22
|
+
getContext: () => Promise</*elided*/ any>; /*... 15 more elided ...*/
|
|
23
|
+
chain: {
|
|
24
|
+
raw: {
|
|
25
|
+
pkpSign: (params: {
|
|
26
|
+
/*elided*/
|
|
27
|
+
} | /*... 1 more elided ...*/ any | {
|
|
28
|
+
/*elided*/
|
|
29
|
+
}) => Promise<import("@lit-protocol/types").LitNodeSignature>;
|
|
30
|
+
};
|
|
31
|
+
ethereum: {
|
|
32
|
+
pkpSign: (params: {
|
|
33
|
+
/*elided*/
|
|
34
|
+
} | /*... 1 more elided ...*/ any | {
|
|
35
|
+
/*elided*/
|
|
36
|
+
}) => Promise<import("@lit-protocol/types").LitNodeSignature>;
|
|
37
|
+
};
|
|
38
|
+
bitcoin: {
|
|
39
|
+
pkpSign: (params: {
|
|
40
|
+
/*elided*/
|
|
41
|
+
} | /*... 1 more elided ...*/ any | {
|
|
42
|
+
/*elided*/
|
|
43
|
+
}) => Promise<import("@lit-protocol/types").LitNodeSignature>;
|
|
44
|
+
};
|
|
45
|
+
};
|
|
46
|
+
};
|
|
47
|
+
authManager: {
|
|
48
|
+
/*elided*/
|
|
49
|
+
};
|
|
19
50
|
/**
|
|
20
51
|
* Encrypt a stream of data using the symmetric crypto implementation
|
|
21
52
|
*
|
|
@@ -45,7 +76,7 @@ export class LitCryptoAdapter implements Type.CryptoAdapter {
|
|
|
45
76
|
* Decrypt a symmetric key using the Lit crypto adapter
|
|
46
77
|
*
|
|
47
78
|
* @param {string} encryptedKey - The encrypted key to decrypt
|
|
48
|
-
* @param {object} configs - The decryption configuration
|
|
79
|
+
* @param {object} configs - The decryption configuration object
|
|
49
80
|
* @param {Type.DecryptionConfig} configs.decryptionConfig - The decryption config
|
|
50
81
|
* @param {Type.ExtractedMetadata} configs.metadata - The extracted metadata
|
|
51
82
|
* @param {import('@ucanto/interface').Proof} configs.decryptDelegation - The delegation that gives permission to decrypt (required for both strategies)
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"lit-crypto-adapter.d.ts","sourceRoot":"","sources":["../../../src/crypto/adapters/lit-crypto-adapter.js"],"names":[],"mappings":"AAMA;;;;;;;GAOG;AACH,yCAFgB,IAAI,CAAC,aAAa;IAGhC
|
|
1
|
+
{"version":3,"file":"lit-crypto-adapter.d.ts","sourceRoot":"","sources":["../../../src/crypto/adapters/lit-crypto-adapter.js"],"names":[],"mappings":"AAMA;;;;;;;GAOG;AACH,yCAFgB,IAAI,CAAC,aAAa;IAGhC;;;;;;OAMG;IACH,6BAJW,IAAI,CAAC,eAAe,aACpB,OAAO,0BAA0B,EAAE,aAAa,eAChD,IAAI,CAAC,WAAW,EAM1B;IAHC,sCAAsC;IACtC;;;;;;;;;;;;;;;;;;;;;;;;;;;MAA0B;IAC1B;;MAA8B;IAGhC;;;;;OAKG;IACH,oBAHW,IAAI,CAAC,QAAQ,GACX,OAAO,CAAC,IAAI,CAAC,aAAa,CAAC,CAIvC;IAED;;;;;;;OAOG;IACH,6BALW,cAAc,OACd,UAAU,MACV,UAAU,GACR,OAAO,CAAC,cAAc,CAAC,CAInC;IAED;;;;;;;OAOG;IACH,yBALW,UAAU,MACV,UAAU,oBACV,IAAI,CAAC,gBAAgB,GACnB,OAAO,CAAC,IAAI,CAAC,kBAAkB,CAAC,CA6B5C;IAED;;;;;;;;;;;;OAYG;IACH,kCAVW,MAAM,WAEd;QAAuC,gBAAgB,EAA/C,IAAI,CAAC,gBAAgB;QACW,QAAQ,EAAxC,IAAI,CAAC,iBAAiB;QACqB,iBAAiB,EAA5D,OAAO,mBAAmB,EAAE,KAAK;QACX,WAAW,EAAjC,IAAI,CAAC,OAAO;QACoH,MAAM,EAAtI,OAAO,wBAAwB,EAAE,MAAM,CAAC,OAAO,wBAAwB,EAAE,GAAG,EAAE,OAAO,wBAAwB,EAAE,MAAM,CAAC;QACxE,QAAQ,EAAtD,OAAO,wBAAwB,EAAE,GAAG;KAC5C,GAAU,OAAO,CAAC;QAAE,GAAG,EAAE,UAAU,CAAC;QAAC,EAAE,EAAE,UAAU,CAAA;KAAE,CAAC,CAgFxD;IAED;;;;;OAKG;IACH,8BAHW,UAAU,GACR,IAAI,CAAC,iBAAiB,CA4BlC;IAED;;;;;OAKG;IACH,0BAHW,IAAI,CAAC,iBAAiB,GACpB,MAAM,CAOlB;IAED;;;;;;;OAOG;IACH,iCALW,MAAM,gBACN,MAAM,YACN,IAAI,CAAC,cAAc,GACjB,OAAO,CAAC;QAAE,GAAG,EAAE,OAAO,+BAA+B,EAAE,OAAO,CAAC;QAAC,KAAK,EAAE,UAAU,CAAA;KAAE,CAAC,CAehG;CACF;sBAxPqB,gBAAgB"}
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { base64 } from 'multiformats/bases/base64';
|
|
2
|
+
import * as Type from '../../types.js';
|
|
2
3
|
import * as Lit from '../../protocols/lit.js';
|
|
3
4
|
import * as EncryptedMetadata from '../../core/metadata/encrypted-metadata.js';
|
|
4
5
|
import { createDecryptWrappedInvocation } from '../../utils.js';
|
|
5
|
-
import * as Type from '../../types.js';
|
|
6
6
|
/**
|
|
7
7
|
* LitCryptoAdapter implements the complete CryptoAdapter interface using Lit Protocol.
|
|
8
8
|
* It uses composition with a SymmetricCrypto implementation for file encryption/decryption
|
|
@@ -16,11 +16,13 @@ export class LitCryptoAdapter {
|
|
|
16
16
|
* Create a new Lit crypto adapter
|
|
17
17
|
*
|
|
18
18
|
* @param {Type.SymmetricCrypto} symmetricCrypto - The symmetric crypto implementation (browser or node)
|
|
19
|
-
* @param {import('@lit-protocol/lit-
|
|
19
|
+
* @param {import('@lit-protocol/lit-client').LitClientType} litClient - The Lit client instance
|
|
20
|
+
* @param {Type.AuthManager} authManager - The Lit Auth Manager instance
|
|
20
21
|
*/
|
|
21
|
-
constructor(symmetricCrypto, litClient) {
|
|
22
|
+
constructor(symmetricCrypto, litClient, authManager) {
|
|
22
23
|
this.symmetricCrypto = symmetricCrypto;
|
|
23
24
|
this.litClient = litClient;
|
|
25
|
+
this.authManager = authManager;
|
|
24
26
|
}
|
|
25
27
|
/**
|
|
26
28
|
* Encrypt a stream of data using the symmetric crypto implementation
|
|
@@ -58,18 +60,18 @@ export class LitCryptoAdapter {
|
|
|
58
60
|
const accessControlConditions = Lit.getAccessControlConditions(spaceDID);
|
|
59
61
|
// Step 3. Encrypt the base64 encoded combined key and IV with Lit
|
|
60
62
|
const dataToEncrypt = base64.encode(combinedKeyAndIV);
|
|
61
|
-
const
|
|
63
|
+
const encryptedData = await this.litClient.encrypt({
|
|
62
64
|
dataToEncrypt,
|
|
63
|
-
accessControlConditions,
|
|
64
|
-
}
|
|
65
|
+
unifiedAccessControlConditions: accessControlConditions,
|
|
66
|
+
});
|
|
65
67
|
// Step 4. Return the encrypted key and metadata
|
|
66
68
|
return {
|
|
67
69
|
strategy: /** @type {'lit'} */ ('lit'),
|
|
68
|
-
encryptedKey: ciphertext,
|
|
70
|
+
encryptedKey: encryptedData.ciphertext,
|
|
69
71
|
metadata: {
|
|
70
|
-
plaintextKeyHash: dataToEncryptHash,
|
|
72
|
+
plaintextKeyHash: encryptedData.dataToEncryptHash,
|
|
71
73
|
accessControlConditions:
|
|
72
|
-
/** @type {import('@lit-protocol/
|
|
74
|
+
/** @type {import('@lit-protocol/access-control-conditions').AccessControlConditions} */ (accessControlConditions),
|
|
73
75
|
},
|
|
74
76
|
};
|
|
75
77
|
}
|
|
@@ -77,7 +79,7 @@ export class LitCryptoAdapter {
|
|
|
77
79
|
* Decrypt a symmetric key using the Lit crypto adapter
|
|
78
80
|
*
|
|
79
81
|
* @param {string} encryptedKey - The encrypted key to decrypt
|
|
80
|
-
* @param {object} configs - The decryption configuration
|
|
82
|
+
* @param {object} configs - The decryption configuration object
|
|
81
83
|
* @param {Type.DecryptionConfig} configs.decryptionConfig - The decryption config
|
|
82
84
|
* @param {Type.ExtractedMetadata} configs.metadata - The extracted metadata
|
|
83
85
|
* @param {import('@ucanto/interface').Proof} configs.decryptDelegation - The delegation that gives permission to decrypt (required for both strategies)
|
|
@@ -94,36 +96,31 @@ export class LitCryptoAdapter {
|
|
|
94
96
|
}
|
|
95
97
|
const { plaintextKeyHash, accessControlConditions } = metadata;
|
|
96
98
|
// Step 1. Extract spaceDID from access control conditions
|
|
97
|
-
const spaceDID = /** @type {Type.SpaceDID} */ (
|
|
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
|
-
else {
|
|
125
|
-
throw new Error('Session signatures or signer (wallet/PKP) required for Lit decryption');
|
|
126
|
-
}
|
|
99
|
+
const spaceDID = /** @type {Type.SpaceDID} */ (
|
|
100
|
+
/** @type {import('@lit-protocol/access-control-conditions').EvmBasicAcc} */ (accessControlConditions[0]).parameters[1]);
|
|
101
|
+
const expiration = new Date(Date.now() + 1000 * 60 * 5).toISOString(); // 5 min
|
|
102
|
+
// Step 2. Get Auth Context for decryption
|
|
103
|
+
/** @type {Type.AuthContext} */
|
|
104
|
+
let authContext;
|
|
105
|
+
if (decryptionConfig.wallet) {
|
|
106
|
+
authContext = await Lit.createEoaAuthContext(this.litClient, this.authManager, {
|
|
107
|
+
wallet: decryptionConfig.wallet,
|
|
108
|
+
accessControlConditions,
|
|
109
|
+
dataToEncryptHash: plaintextKeyHash,
|
|
110
|
+
expiration,
|
|
111
|
+
});
|
|
112
|
+
}
|
|
113
|
+
else if (decryptionConfig.pkpPublicKey && decryptionConfig.authData) {
|
|
114
|
+
authContext = await Lit.createPkpAuthContext(this.litClient, this.authManager, {
|
|
115
|
+
pkpPublicKey: decryptionConfig.pkpPublicKey,
|
|
116
|
+
authData: decryptionConfig.authData,
|
|
117
|
+
accessControlConditions,
|
|
118
|
+
dataToEncryptHash: plaintextKeyHash,
|
|
119
|
+
expiration,
|
|
120
|
+
});
|
|
121
|
+
}
|
|
122
|
+
else {
|
|
123
|
+
throw new Error('Either wallet or PKP authData must be provided');
|
|
127
124
|
}
|
|
128
125
|
// Step 3. Create wrapped UCAN invocation
|
|
129
126
|
const wrappedInvocationJSON = await createDecryptWrappedInvocation({
|
|
@@ -136,7 +133,7 @@ export class LitCryptoAdapter {
|
|
|
136
133
|
});
|
|
137
134
|
// Step 4. Execute the Lit Action with all the prepared context to decrypt the symmetric key
|
|
138
135
|
const decryptedString = await Lit.executeUcanValidationAction(this.litClient, {
|
|
139
|
-
|
|
136
|
+
authContext,
|
|
140
137
|
spaceDID,
|
|
141
138
|
identityBoundCiphertext: encryptedKey,
|
|
142
139
|
plaintextKeyHash,
|
|
@@ -6,21 +6,15 @@
|
|
|
6
6
|
* @param {string} keyManagerServiceDID
|
|
7
7
|
*/
|
|
8
8
|
export function createGenericKMSAdapter(keyManagerServiceURL: URL | string, keyManagerServiceDID: string): KMSCryptoAdapter;
|
|
9
|
-
/**
|
|
10
|
-
* Create a Lit crypto adapter for Node.js using AES-CBC (legacy).
|
|
11
|
-
* Compatible with previous versions of the library.
|
|
12
|
-
*
|
|
13
|
-
* @deprecated Use createGenericLitAdapter instead for new uploads.
|
|
14
|
-
* @param {import('@lit-protocol/lit-node-client').LitNodeClient} litClient
|
|
15
|
-
*/
|
|
16
|
-
export function createNodeLitAdapter(litClient: import("@lit-protocol/lit-node-client").LitNodeClient): LitCryptoAdapter;
|
|
17
9
|
/**
|
|
18
10
|
* Create a Lit crypto adapter for Node.js using the generic AES-CTR streaming crypto.
|
|
19
11
|
* Works in Node.js & browser environments.
|
|
20
12
|
*
|
|
21
|
-
* @param {import('@lit-protocol/lit-
|
|
13
|
+
* @param {import('@lit-protocol/lit-client').LitClientType} litClient
|
|
14
|
+
* @param {Type.AuthManager} authManager - The Lit Auth Manager instance
|
|
22
15
|
*/
|
|
23
|
-
export function createGenericLitAdapter(litClient: import("@lit-protocol/lit-
|
|
16
|
+
export function createGenericLitAdapter(litClient: import("@lit-protocol/lit-client").LitClientType, authManager: Type.AuthManager): LitCryptoAdapter;
|
|
24
17
|
import { KMSCryptoAdapter } from './adapters/kms-crypto-adapter.js';
|
|
18
|
+
import * as Type from '../types.js';
|
|
25
19
|
import { LitCryptoAdapter } from './adapters/lit-crypto-adapter.js';
|
|
26
20
|
//# sourceMappingURL=factories.node.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"factories.node.d.ts","sourceRoot":"","sources":["../../src/crypto/factories.node.js"],"names":[],"mappings":"AAKA;;;;;;GAMG;AACH,8DAHW,GAAG,GAAC,MAAM,wBACV,MAAM,oBAYhB;AAED;;;;;;GAMG;AACH,
|
|
1
|
+
{"version":3,"file":"factories.node.d.ts","sourceRoot":"","sources":["../../src/crypto/factories.node.js"],"names":[],"mappings":"AAKA;;;;;;GAMG;AACH,8DAHW,GAAG,GAAC,MAAM,wBACV,MAAM,oBAYhB;AAED;;;;;;GAMG;AACH,mDAHW,OAAO,0BAA0B,EAAE,aAAa,eAChD,IAAI,CAAC,WAAW,oBAK1B;iCAjCgC,kCAAkC;sBAE7C,aAAa;iCADF,kCAAkC"}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { GenericAesCtrStreamingCrypto } from './symmetric/generic-aes-ctr-streaming-crypto.js';
|
|
2
|
-
import { NodeAesCbcCrypto } from './symmetric/node-aes-cbc-crypto.js';
|
|
3
|
-
import { LitCryptoAdapter } from './adapters/lit-crypto-adapter.js';
|
|
4
2
|
import { KMSCryptoAdapter } from './adapters/kms-crypto-adapter.js';
|
|
3
|
+
import { LitCryptoAdapter } from './adapters/lit-crypto-adapter.js';
|
|
4
|
+
import * as Type from '../types.js';
|
|
5
5
|
/**
|
|
6
6
|
* Create a KMS crypto adapter for Node.js using the generic AES-CTR streaming crypto.
|
|
7
7
|
* Works in Node.js & browser environments.
|
|
@@ -14,25 +14,15 @@ export function createGenericKMSAdapter(keyManagerServiceURL, keyManagerServiceD
|
|
|
14
14
|
return new KMSCryptoAdapter(symmetricCrypto, keyManagerServiceURL,
|
|
15
15
|
/** @type {`did:${string}:${string}`} */ (keyManagerServiceDID));
|
|
16
16
|
}
|
|
17
|
-
/**
|
|
18
|
-
* Create a Lit crypto adapter for Node.js using AES-CBC (legacy).
|
|
19
|
-
* Compatible with previous versions of the library.
|
|
20
|
-
*
|
|
21
|
-
* @deprecated Use createGenericLitAdapter instead for new uploads.
|
|
22
|
-
* @param {import('@lit-protocol/lit-node-client').LitNodeClient} litClient
|
|
23
|
-
*/
|
|
24
|
-
export function createNodeLitAdapter(litClient) {
|
|
25
|
-
const symmetricCrypto = new NodeAesCbcCrypto();
|
|
26
|
-
return new LitCryptoAdapter(symmetricCrypto, litClient);
|
|
27
|
-
}
|
|
28
17
|
/**
|
|
29
18
|
* Create a Lit crypto adapter for Node.js using the generic AES-CTR streaming crypto.
|
|
30
19
|
* Works in Node.js & browser environments.
|
|
31
20
|
*
|
|
32
|
-
* @param {import('@lit-protocol/lit-
|
|
21
|
+
* @param {import('@lit-protocol/lit-client').LitClientType} litClient
|
|
22
|
+
* @param {Type.AuthManager} authManager - The Lit Auth Manager instance
|
|
33
23
|
*/
|
|
34
|
-
export function createGenericLitAdapter(litClient) {
|
|
24
|
+
export function createGenericLitAdapter(litClient, authManager) {
|
|
35
25
|
const symmetricCrypto = new GenericAesCtrStreamingCrypto();
|
|
36
|
-
return new LitCryptoAdapter(symmetricCrypto, litClient);
|
|
26
|
+
return new LitCryptoAdapter(symmetricCrypto, litClient, authManager);
|
|
37
27
|
}
|
|
38
28
|
//# sourceMappingURL=factories.node.js.map
|
package/dist/protocols/lit.d.ts
CHANGED
|
@@ -1,25 +1,20 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
2
|
+
* @param {import('@lit-protocol/lit-client').LitClientType} litClient
|
|
3
|
+
* @param {Type.AuthManager} authManager - The Lit Auth Manager instance
|
|
4
|
+
* @param {Type.EoaAuthContextOptions} param0
|
|
5
|
+
* @returns {Promise<Type.EoaAuthContext>}
|
|
3
6
|
*/
|
|
4
|
-
export function
|
|
7
|
+
export function createEoaAuthContext(litClient: import("@lit-protocol/lit-client").LitClientType, authManager: Type.AuthManager, { wallet, accessControlConditions, expiration, dataToEncryptHash, capabilityAuthSigs, }: Type.EoaAuthContextOptions): Promise<Type.EoaAuthContext>;
|
|
5
8
|
/**
|
|
6
|
-
*
|
|
7
|
-
* @param {Type.SessionSignatureOptions} param0
|
|
8
|
-
* @returns {Promise<import('@lit-protocol/types').SessionSigsMap>}
|
|
9
|
-
*/
|
|
10
|
-
export function getSessionSigs(litClient: LitNodeClient, { wallet, accessControlConditions, dataToEncryptHash, expiration, capabilityAuthSigs, }: Type.SessionSignatureOptions): Promise<import("@lit-protocol/types").SessionSigsMap>;
|
|
11
|
-
/**
|
|
12
|
-
* Get session signatures for a PKP key and auth method.
|
|
13
|
-
* There is not need to execute the auth callback for this function, because the auth method provided.
|
|
9
|
+
* Get PKP Auth Context.
|
|
14
10
|
*
|
|
15
|
-
* @param {
|
|
16
|
-
* @param {Type.
|
|
17
|
-
* @
|
|
11
|
+
* @param {import('@lit-protocol/lit-client').LitClientType} litClient
|
|
12
|
+
* @param {Type.AuthManager} authManager - The Lit Auth Manager instance
|
|
13
|
+
* @param {Type.PkpAuthContextOptions} options
|
|
14
|
+
* @returns {Promise<Type.PkpAuthContext>}
|
|
18
15
|
*/
|
|
19
|
-
export function
|
|
20
|
-
export
|
|
21
|
-
export function
|
|
22
|
-
export function executeUcanValidationAction(litClient: LitNodeClient, options: Type.ExecuteUcanValidationOptions): Promise<any>;
|
|
23
|
-
import { LitNodeClient } from '@lit-protocol/lit-node-client';
|
|
16
|
+
export function createPkpAuthContext(litClient: import("@lit-protocol/lit-client").LitClientType, authManager: Type.AuthManager, { pkpPublicKey, authData, accessControlConditions, dataToEncryptHash, expiration, capabilityAuthSigs, }: Type.PkpAuthContextOptions): Promise<Type.PkpAuthContext>;
|
|
17
|
+
export function getAccessControlConditions(spaceDID: Type.SpaceDID): import("@lit-protocol/access-control-conditions").AccessControlConditions;
|
|
18
|
+
export function executeUcanValidationAction(litClient: import("@lit-protocol/lit-client").LitClientType, options: Type.ExecuteUcanValidationActionOptions): Promise<any>;
|
|
24
19
|
import * as Type from '../types.js';
|
|
25
20
|
//# sourceMappingURL=lit.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"lit.d.ts","sourceRoot":"","sources":["../../src/protocols/lit.js"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"lit.d.ts","sourceRoot":"","sources":["../../src/protocols/lit.js"],"names":[],"mappings":"AAmCA;;;;;GAKG;AACH,gDALW,OAAO,0BAA0B,EAAE,aAAa,eAChD,IAAI,CAAC,WAAW,2FAChB,IAAI,CAAC,qBAAqB,GACxB,OAAO,CAAC,IAAI,CAAC,cAAc,CAAC,CAsCxC;AAED;;;;;;;GAOG;AACH,gDALW,OAAO,0BAA0B,EAAE,aAAa,eAChD,IAAI,CAAC,WAAW,2GAChB,IAAI,CAAC,qBAAqB,GACxB,OAAO,CAAC,IAAI,CAAC,cAAc,CAAC,CAuCxC;AA/GM,qDAHI,IAAI,CAAC,QAAQ,GACX,OAAO,yCAAyC,EAAE,uBAAuB,CAsBrF;AAmGM,uDAJI,OAAO,0BAA0B,EAAE,aAAa,WAChD,IAAI,CAAC,kCAAkC,gBA+BjD;sBA7JqB,aAAa"}
|
package/dist/protocols/lit.js
CHANGED
|
@@ -1,122 +1,101 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import { generateAuthSig, LitActionResource, createSiweMessage, LitAccessControlConditionResource, } from '@lit-protocol/auth-helpers';
|
|
4
|
-
import env from '../config/env.js';
|
|
1
|
+
import { LitAccessControlConditionResource } from '@lit-protocol/auth-helpers';
|
|
2
|
+
import { createAccBuilder } from '@lit-protocol/access-control-conditions';
|
|
5
3
|
import * as Type from '../types.js';
|
|
6
4
|
import { STORACHA_LIT_ACTION_CID } from '../config/constants.js';
|
|
7
|
-
export { encryptString } from '@lit-protocol/encryption';
|
|
8
5
|
/**
|
|
9
6
|
* Create access control conditions required to use Lit Protocol.
|
|
10
7
|
* This ensures that the Storacha Lit Action is used to validate decryption permissions for the specified space DID.
|
|
11
8
|
*
|
|
12
9
|
* @param {Type.SpaceDID} spaceDID - The DID of the space
|
|
13
|
-
* @returns {import('@lit-protocol/
|
|
10
|
+
* @returns {import('@lit-protocol/access-control-conditions').AccessControlConditions} - The access control conditions
|
|
14
11
|
*/
|
|
15
12
|
export const getAccessControlConditions = (spaceDID) => {
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
13
|
+
/** @type {import('@lit-protocol/access-control-conditions').UnifiedAccessControlCondition} */
|
|
14
|
+
const rawAcc = {
|
|
15
|
+
conditionType: 'evmBasic',
|
|
16
|
+
contractAddress: '',
|
|
17
|
+
standardContractType: '',
|
|
18
|
+
chain: 'ethereum',
|
|
19
|
+
method: '',
|
|
20
|
+
parameters: [':currentActionIpfsId', spaceDID],
|
|
21
|
+
returnValueTest: {
|
|
22
|
+
comparator: '=',
|
|
23
|
+
value: STORACHA_LIT_ACTION_CID,
|
|
27
24
|
},
|
|
28
|
-
|
|
25
|
+
};
|
|
26
|
+
const acc = createAccBuilder().unifiedAccs(rawAcc).build();
|
|
27
|
+
console.log('Access Control Conditions:\n', acc);
|
|
28
|
+
return acc;
|
|
29
29
|
};
|
|
30
30
|
/**
|
|
31
|
-
*
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
litNetwork: env.LIT_NETWORK,
|
|
36
|
-
debug: env.LIT_DEBUG,
|
|
37
|
-
});
|
|
38
|
-
await litNodeClient.connect();
|
|
39
|
-
return litNodeClient;
|
|
40
|
-
}
|
|
41
|
-
/**
|
|
42
|
-
* @param {LitNodeClient} litClient
|
|
43
|
-
* @param {Type.SessionSignatureOptions} param0
|
|
44
|
-
* @returns {Promise<import('@lit-protocol/types').SessionSigsMap>}
|
|
31
|
+
* @param {import('@lit-protocol/lit-client').LitClientType} litClient
|
|
32
|
+
* @param {Type.AuthManager} authManager - The Lit Auth Manager instance
|
|
33
|
+
* @param {Type.EoaAuthContextOptions} param0
|
|
34
|
+
* @returns {Promise<Type.EoaAuthContext>}
|
|
45
35
|
*/
|
|
46
|
-
export async function
|
|
47
|
-
const accsResourceString = await LitAccessControlConditionResource.generateResourceString(
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
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
|
-
});
|
|
36
|
+
export async function createEoaAuthContext(litClient, authManager, { wallet, accessControlConditions, expiration, dataToEncryptHash, capabilityAuthSigs, }) {
|
|
37
|
+
const accsResourceString = await LitAccessControlConditionResource.generateResourceString(
|
|
38
|
+
/** @type {import('@lit-protocol/types').AccessControlConditions} */ (accessControlConditions), dataToEncryptHash);
|
|
39
|
+
const authContext = await authManager.createEoaAuthContext({
|
|
40
|
+
config: {
|
|
41
|
+
account: wallet,
|
|
75
42
|
},
|
|
43
|
+
authConfig: {
|
|
44
|
+
expiration,
|
|
45
|
+
resources: [
|
|
46
|
+
['access-control-condition-decryption', accsResourceString], // or '*'
|
|
47
|
+
['lit-action-execution', '*'],
|
|
48
|
+
],
|
|
49
|
+
capabilityAuthSigs,
|
|
50
|
+
statement: 'I authorize the Lit Protocol to execute this Lit Action.',
|
|
51
|
+
},
|
|
52
|
+
litClient,
|
|
76
53
|
});
|
|
77
|
-
return
|
|
54
|
+
return authContext;
|
|
78
55
|
}
|
|
79
56
|
/**
|
|
80
|
-
* Get
|
|
81
|
-
* There is not need to execute the auth callback for this function, because the auth method provided.
|
|
57
|
+
* Get PKP Auth Context.
|
|
82
58
|
*
|
|
83
|
-
* @param {
|
|
84
|
-
* @param {Type.
|
|
85
|
-
* @
|
|
59
|
+
* @param {import('@lit-protocol/lit-client').LitClientType} litClient
|
|
60
|
+
* @param {Type.AuthManager} authManager - The Lit Auth Manager instance
|
|
61
|
+
* @param {Type.PkpAuthContextOptions} options
|
|
62
|
+
* @returns {Promise<Type.PkpAuthContext>}
|
|
86
63
|
*/
|
|
87
|
-
export async function
|
|
88
|
-
const accsResourceString = await LitAccessControlConditionResource.generateResourceString(
|
|
89
|
-
|
|
64
|
+
export async function createPkpAuthContext(litClient, authManager, { pkpPublicKey, authData, accessControlConditions, dataToEncryptHash, expiration, capabilityAuthSigs, }) {
|
|
65
|
+
const accsResourceString = await LitAccessControlConditionResource.generateResourceString(
|
|
66
|
+
/** @type {import('@lit-protocol/types').AccessControlConditions} */ (accessControlConditions), dataToEncryptHash);
|
|
67
|
+
const authContext = await authManager.createPkpAuthContext({
|
|
68
|
+
authData,
|
|
90
69
|
pkpPublicKey,
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
expiration,
|
|
103
|
-
capabilityAuthSigs,
|
|
70
|
+
authConfig: {
|
|
71
|
+
resources: [
|
|
72
|
+
['pkp-signing', '*'], // remove it?
|
|
73
|
+
['access-control-condition-decryption', accsResourceString], // or '*'
|
|
74
|
+
['lit-action-execution', '*'],
|
|
75
|
+
],
|
|
76
|
+
capabilityAuthSigs,
|
|
77
|
+
expiration,
|
|
78
|
+
statement: 'I authorize the Lit Protocol to execute this Lit Action.',
|
|
79
|
+
},
|
|
80
|
+
litClient: litClient,
|
|
104
81
|
});
|
|
105
|
-
return
|
|
82
|
+
return authContext;
|
|
106
83
|
}
|
|
107
84
|
/**
|
|
108
85
|
*
|
|
109
|
-
* @param {
|
|
110
|
-
* @param {Type.
|
|
86
|
+
* @param {import('@lit-protocol/lit-client').LitClientType} litClient
|
|
87
|
+
* @param {Type.ExecuteUcanValidationActionOptions} options
|
|
111
88
|
* @returns
|
|
112
89
|
*/
|
|
113
90
|
export const executeUcanValidationAction = async (litClient, options) => {
|
|
114
|
-
const {
|
|
91
|
+
const { authContext, ...jsParams } = options;
|
|
115
92
|
const litActionResponse = await litClient.executeJs({
|
|
116
93
|
ipfsId: STORACHA_LIT_ACTION_CID,
|
|
117
|
-
|
|
94
|
+
authContext,
|
|
118
95
|
jsParams,
|
|
119
96
|
});
|
|
97
|
+
console.log('Lit Action Response: \n');
|
|
98
|
+
console.log(litActionResponse);
|
|
120
99
|
if (!litActionResponse.response) {
|
|
121
100
|
throw new Error('Error getting lit action response.');
|
|
122
101
|
}
|