@nucypher/taco 0.1.0-rc.5 → 0.1.0-rc.7
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 +63 -1
- package/dist/cjs/conditions/base/contract.d.ts +17 -12
- package/dist/cjs/conditions/base/contract.js +17 -3
- package/dist/cjs/conditions/base/contract.js.map +1 -1
- package/dist/cjs/conditions/base/index.d.ts +3 -21
- package/dist/cjs/conditions/base/index.js +27 -37
- package/dist/cjs/conditions/base/index.js.map +1 -1
- package/dist/cjs/conditions/base/rpc.d.ts +16 -11
- package/dist/cjs/conditions/base/rpc.js +16 -6
- package/dist/cjs/conditions/base/rpc.js.map +1 -1
- package/dist/cjs/conditions/base/time.d.ts +10 -5
- package/dist/cjs/conditions/base/time.js +11 -1
- package/dist/cjs/conditions/base/time.js.map +1 -1
- package/dist/cjs/conditions/compound-condition.d.ts +10 -0
- package/dist/cjs/conditions/compound-condition.js +52 -5
- package/dist/cjs/conditions/compound-condition.js.map +1 -1
- package/dist/cjs/conditions/condition-expr.js +2 -2
- package/dist/cjs/conditions/condition-expr.js.map +1 -1
- package/dist/cjs/conditions/condition-factory.d.ts +4 -0
- package/dist/cjs/conditions/condition-factory.js +26 -0
- package/dist/cjs/conditions/condition-factory.js.map +1 -0
- package/dist/cjs/conditions/condition.d.ts +0 -1
- package/dist/cjs/conditions/condition.js +0 -22
- package/dist/cjs/conditions/condition.js.map +1 -1
- package/dist/cjs/conditions/const.d.ts +3 -0
- package/dist/cjs/conditions/const.js +6 -1
- package/dist/cjs/conditions/const.js.map +1 -1
- package/dist/cjs/conditions/context/context.d.ts +0 -2
- package/dist/cjs/conditions/context/context.js +8 -11
- package/dist/cjs/conditions/context/context.js.map +1 -1
- package/dist/cjs/conditions/index.d.ts +5 -6
- package/dist/cjs/conditions/index.js +7 -14
- package/dist/cjs/conditions/index.js.map +1 -1
- package/dist/cjs/conditions/predefined/erc721.d.ts +2 -2
- package/dist/cjs/conditions/predefined/erc721.js +5 -11
- package/dist/cjs/conditions/predefined/erc721.js.map +1 -1
- package/dist/cjs/conditions/predefined/index.d.ts +1 -1
- package/dist/cjs/conditions/predefined/index.js +25 -4
- package/dist/cjs/conditions/predefined/index.js.map +1 -1
- package/dist/cjs/conditions/{base/shared.d.ts → shared.d.ts} +7 -3
- package/dist/cjs/conditions/shared.js +31 -0
- package/dist/cjs/conditions/shared.js.map +1 -0
- package/dist/cjs/dkg.d.ts +1 -1
- package/dist/cjs/dkg.js +6 -4
- package/dist/cjs/dkg.js.map +1 -1
- package/dist/cjs/index.d.ts +1 -1
- package/dist/cjs/index.js +3 -3
- package/dist/cjs/index.js.map +1 -1
- package/dist/cjs/taco.d.ts +70 -1
- package/dist/cjs/taco.js +72 -4
- package/dist/cjs/taco.js.map +1 -1
- package/dist/cjs/tdec.d.ts +2 -1
- package/dist/cjs/tdec.js +6 -4
- package/dist/cjs/tdec.js.map +1 -1
- package/dist/es/conditions/base/contract.d.ts +17 -12
- package/dist/es/conditions/base/contract.js +15 -2
- package/dist/es/conditions/base/contract.js.map +1 -1
- package/dist/es/conditions/base/index.d.ts +3 -21
- package/dist/es/conditions/base/index.js +3 -28
- package/dist/es/conditions/base/index.js.map +1 -1
- package/dist/es/conditions/base/rpc.d.ts +16 -11
- package/dist/es/conditions/base/rpc.js +14 -5
- package/dist/es/conditions/base/rpc.js.map +1 -1
- package/dist/es/conditions/base/time.d.ts +10 -5
- package/dist/es/conditions/base/time.js +9 -0
- package/dist/es/conditions/base/time.js.map +1 -1
- package/dist/es/conditions/compound-condition.d.ts +10 -0
- package/dist/es/conditions/compound-condition.js +50 -4
- package/dist/es/conditions/compound-condition.js.map +1 -1
- package/dist/es/conditions/condition-expr.js +2 -2
- package/dist/es/conditions/condition-expr.js.map +1 -1
- package/dist/es/conditions/condition-factory.d.ts +4 -0
- package/dist/es/conditions/condition-factory.js +22 -0
- package/dist/es/conditions/condition-factory.js.map +1 -0
- package/dist/es/conditions/condition.d.ts +0 -1
- package/dist/es/conditions/condition.js +0 -22
- package/dist/es/conditions/condition.js.map +1 -1
- package/dist/es/conditions/const.d.ts +3 -0
- package/dist/es/conditions/const.js +5 -0
- package/dist/es/conditions/const.js.map +1 -1
- package/dist/es/conditions/context/context.d.ts +0 -2
- package/dist/es/conditions/context/context.js +4 -7
- package/dist/es/conditions/context/context.js.map +1 -1
- package/dist/es/conditions/index.d.ts +5 -6
- package/dist/es/conditions/index.js +5 -6
- package/dist/es/conditions/index.js.map +1 -1
- package/dist/es/conditions/predefined/erc721.d.ts +2 -2
- package/dist/es/conditions/predefined/erc721.js +1 -7
- package/dist/es/conditions/predefined/erc721.js.map +1 -1
- package/dist/es/conditions/predefined/index.d.ts +1 -1
- package/dist/es/conditions/predefined/index.js +1 -1
- package/dist/es/conditions/predefined/index.js.map +1 -1
- package/dist/es/conditions/{base/shared.d.ts → shared.d.ts} +7 -3
- package/dist/es/conditions/shared.js +28 -0
- package/dist/es/conditions/shared.js.map +1 -0
- package/dist/es/dkg.d.ts +1 -1
- package/dist/es/dkg.js +6 -4
- package/dist/es/dkg.js.map +1 -1
- package/dist/es/index.d.ts +1 -1
- package/dist/es/index.js +1 -1
- package/dist/es/index.js.map +1 -1
- package/dist/es/taco.d.ts +70 -1
- package/dist/es/taco.js +71 -3
- package/dist/es/taco.js.map +1 -1
- package/dist/es/tdec.d.ts +2 -1
- package/dist/es/tdec.js +5 -3
- package/dist/es/tdec.js.map +1 -1
- package/dist/tsconfig.cjs.tsbuildinfo +1 -1
- package/dist/tsconfig.es.tsbuildinfo +1 -1
- package/package.json +7 -6
- package/dist/cjs/conditions/base/shared.js +0 -17
- package/dist/cjs/conditions/base/shared.js.map +0 -1
- package/dist/es/conditions/base/shared.js +0 -14
- package/dist/es/conditions/base/shared.js.map +0 -1
package/dist/es/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
export { DkgPublicKey, ThresholdMessageKit } from '@nucypher/nucypher-core';
|
|
2
|
-
export {
|
|
2
|
+
export { Domain, domains, fromBytes, getPorterUri, initialize, toBytes, toHexString, } from '@nucypher/shared';
|
|
3
3
|
export * as conditions from './conditions';
|
|
4
4
|
export { decrypt, encrypt, encryptWithPublicKey, isAuthorized } from './taco';
|
package/dist/es/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
export { DkgPublicKey, ThresholdMessageKit } from '@nucypher/nucypher-core';
|
|
2
|
-
export { fromBytes, initialize, toBytes, toHexString,
|
|
2
|
+
export { domains, fromBytes, getPorterUri, initialize, toBytes, toHexString, } from '@nucypher/shared';
|
|
3
3
|
export * as conditions from './conditions';
|
|
4
4
|
// Expose registerEncrypters from taco API (#324)
|
|
5
5
|
export { decrypt, encrypt, encryptWithPublicKey, isAuthorized } from './taco';
|
package/dist/es/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,mBAAmB,EAAE,MAAM,yBAAyB,CAAC;AAC5E,OAAO,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,mBAAmB,EAAE,MAAM,yBAAyB,CAAC;AAC5E,OAAO,EAEL,OAAO,EACP,SAAS,EACT,YAAY,EACZ,UAAU,EACV,OAAO,EACP,WAAW,GACZ,MAAM,kBAAkB,CAAC;AAE1B,OAAO,KAAK,UAAU,MAAM,cAAc,CAAC;AAC3C,iDAAiD;AACjD,OAAO,EAAE,OAAO,EAAE,OAAO,EAAE,oBAAoB,EAAE,YAAY,EAAE,MAAM,QAAQ,CAAC"}
|
package/dist/es/taco.d.ts
CHANGED
|
@@ -1,9 +1,78 @@
|
|
|
1
1
|
import { DkgPublicKey, ThresholdMessageKit } from '@nucypher/nucypher-core';
|
|
2
2
|
import { ChecksumAddress, Domain } from '@nucypher/shared';
|
|
3
3
|
import { ethers } from 'ethers';
|
|
4
|
-
import { Condition
|
|
4
|
+
import { Condition } from './conditions/condition';
|
|
5
|
+
import { CustomContextParam } from './conditions/context';
|
|
6
|
+
/**
|
|
7
|
+
* Encrypts a message under given conditions using a public key from an active DKG ritual.
|
|
8
|
+
*
|
|
9
|
+
* @export
|
|
10
|
+
* @param {ethers.providers.Provider} provider - Instance of ethers provider which is used to interact with
|
|
11
|
+
* your selected network.
|
|
12
|
+
* @param {Domain} domain - Represents the logical network in which the encryption will be performed.
|
|
13
|
+
* Must match the `ritualId`.
|
|
14
|
+
* @param {Uint8Array | string} message - The message to be encrypted.
|
|
15
|
+
* @param {Condition} condition - Condition under which the message will be encrypted. Those conditions must be
|
|
16
|
+
* satisfied in order to decrypt the message.
|
|
17
|
+
* @param {number} ritualId - The ID of the DKG Ritual to be used for encryption. The message will be encrypted
|
|
18
|
+
* under the public key of this ritual.
|
|
19
|
+
* @param {ethers.Signer} authSigner - The signer that will be used to sign the encrypter authorization.
|
|
20
|
+
*
|
|
21
|
+
* @returns {Promise<ThresholdMessageKit>} Returns Promise that resolves with an instance of ThresholdMessageKit.
|
|
22
|
+
* It represents the encrypted message.
|
|
23
|
+
*
|
|
24
|
+
* @throws {Error} If the active DKG Ritual cannot be retrieved an error is thrown.
|
|
25
|
+
*/
|
|
5
26
|
export declare const encrypt: (provider: ethers.providers.Provider, domain: Domain, message: Uint8Array | string, condition: Condition, ritualId: number, authSigner: ethers.Signer) => Promise<ThresholdMessageKit>;
|
|
27
|
+
/**
|
|
28
|
+
* Encrypts a message with the given DKG public key under a specified condition.
|
|
29
|
+
*
|
|
30
|
+
* @export
|
|
31
|
+
* @param {Uint8Array | string} message - The message to be encrypted.
|
|
32
|
+
* @param {Condition} condition - Condition under which the message will be encrypted. Those conditions must be
|
|
33
|
+
* satisfied in order to decrypt the message.
|
|
34
|
+
* @param {DkgPublicKey} dkgPublicKey - The public key of an active DKG Ritual to be used for encryption
|
|
35
|
+
* @param {ethers.Signer} authSigner - The signer that will be used to sign the encrypter authorization.
|
|
36
|
+
*
|
|
37
|
+
* @returns {Promise<ThresholdMessageKit>} Returns Promise that resolves with an instance of ThresholdMessageKit.
|
|
38
|
+
* It represents the encrypted message.
|
|
39
|
+
*
|
|
40
|
+
* @throws {Error} If the encryption process throws an error, an error is thrown.
|
|
41
|
+
*/
|
|
6
42
|
export declare const encryptWithPublicKey: (message: Uint8Array | string, condition: Condition, dkgPublicKey: DkgPublicKey, authSigner: ethers.Signer) => Promise<ThresholdMessageKit>;
|
|
43
|
+
/**
|
|
44
|
+
* Decrypts an encrypted message.
|
|
45
|
+
*
|
|
46
|
+
* @export
|
|
47
|
+
* @param {ethers.providers.Provider} provider - Instance of ethers provider which is used to interact with
|
|
48
|
+
* your selected network.
|
|
49
|
+
* @param {Domain} domain - Represents the logical network in which the decryption will be performed.
|
|
50
|
+
* Must match the `ritualId`.
|
|
51
|
+
* @param {ThresholdMessageKit} messageKit - The kit containing the message to be decrypted
|
|
52
|
+
* @param {string} [porterUri] - The URI for the Porter service. If not provided, a value will be obtained
|
|
53
|
+
* from the Domain
|
|
54
|
+
* @param {ethers.Signer} [signer] - An optional signer for the decryption
|
|
55
|
+
* @param {Record<string, CustomContextParam>} [customParameters] - Optional custom parameters that may be required
|
|
56
|
+
* depending on the condition used
|
|
57
|
+
*
|
|
58
|
+
* @returns {Promise<Uint8Array>} Returns Promise that resolves with a decrypted message
|
|
59
|
+
*
|
|
60
|
+
* @throws {Error} If the active DKG Ritual cannot be retrieved or decryption process throws an error,
|
|
61
|
+
* an error is thrown.
|
|
62
|
+
*/
|
|
7
63
|
export declare const decrypt: (provider: ethers.providers.Provider, domain: Domain, messageKit: ThresholdMessageKit, porterUri?: string, signer?: ethers.Signer, customParameters?: Record<string, CustomContextParam>) => Promise<Uint8Array>;
|
|
64
|
+
/**
|
|
65
|
+
* Checks if the encryption from the provided messageKit is authorized for the specified ritual.
|
|
66
|
+
*
|
|
67
|
+
* @export
|
|
68
|
+
* @param {ethers.providers.Provider} provider - Instance of ethers provider which is used to interact with
|
|
69
|
+
* your selected network.
|
|
70
|
+
* @param {Domain} domain - The domain which was used to encrypt the network. Must match the `ritualId`.
|
|
71
|
+
* @param {ThresholdMessageKit} messageKit - The encrypted message kit to be checked.
|
|
72
|
+
* @param {number} ritualId - The ID of the DKG Ritual under which the messageKit was supposedly encrypted.
|
|
73
|
+
*
|
|
74
|
+
* @returns {Promise<boolean>} Returns a Promise that resolves with the authorization status.
|
|
75
|
+
* True if authorized, false otherwise
|
|
76
|
+
*/
|
|
8
77
|
export declare const isAuthorized: (provider: ethers.providers.Provider, domain: Domain, messageKit: ThresholdMessageKit, ritualId: number) => Promise<boolean>;
|
|
9
78
|
export declare const registerEncrypters: (provider: ethers.providers.Provider, signer: ethers.Signer, domain: Domain, ritualId: number, encrypters: ChecksumAddress[]) => Promise<void>;
|
package/dist/es/taco.js
CHANGED
|
@@ -1,9 +1,29 @@
|
|
|
1
1
|
import { AccessControlPolicy, encryptForDkg, ThresholdMessageKit, } from '@nucypher/nucypher-core';
|
|
2
2
|
import { DkgCoordinatorAgent, fromHexString, getPorterUri, GlobalAllowListAgent, toBytes, } from '@nucypher/shared';
|
|
3
3
|
import { keccak256 } from 'ethers/lib/utils';
|
|
4
|
-
import { ConditionExpression } from './conditions';
|
|
4
|
+
import { ConditionExpression } from './conditions/condition-expr';
|
|
5
5
|
import { DkgClient } from './dkg';
|
|
6
6
|
import { retrieveAndDecrypt } from './tdec';
|
|
7
|
+
/**
|
|
8
|
+
* Encrypts a message under given conditions using a public key from an active DKG ritual.
|
|
9
|
+
*
|
|
10
|
+
* @export
|
|
11
|
+
* @param {ethers.providers.Provider} provider - Instance of ethers provider which is used to interact with
|
|
12
|
+
* your selected network.
|
|
13
|
+
* @param {Domain} domain - Represents the logical network in which the encryption will be performed.
|
|
14
|
+
* Must match the `ritualId`.
|
|
15
|
+
* @param {Uint8Array | string} message - The message to be encrypted.
|
|
16
|
+
* @param {Condition} condition - Condition under which the message will be encrypted. Those conditions must be
|
|
17
|
+
* satisfied in order to decrypt the message.
|
|
18
|
+
* @param {number} ritualId - The ID of the DKG Ritual to be used for encryption. The message will be encrypted
|
|
19
|
+
* under the public key of this ritual.
|
|
20
|
+
* @param {ethers.Signer} authSigner - The signer that will be used to sign the encrypter authorization.
|
|
21
|
+
*
|
|
22
|
+
* @returns {Promise<ThresholdMessageKit>} Returns Promise that resolves with an instance of ThresholdMessageKit.
|
|
23
|
+
* It represents the encrypted message.
|
|
24
|
+
*
|
|
25
|
+
* @throws {Error} If the active DKG Ritual cannot be retrieved an error is thrown.
|
|
26
|
+
*/
|
|
7
27
|
export const encrypt = async (provider, domain, message, condition, ritualId, authSigner) => {
|
|
8
28
|
// TODO(#264): Enable ritual initialization
|
|
9
29
|
// if (ritualId === undefined) {
|
|
@@ -17,9 +37,24 @@ export const encrypt = async (provider, domain, message, condition, ritualId, au
|
|
|
17
37
|
// // Given that we just initialized the ritual, this should never happen
|
|
18
38
|
// throw new Error('Ritual ID is undefined');
|
|
19
39
|
// }
|
|
20
|
-
const dkgRitual = await DkgClient.
|
|
40
|
+
const dkgRitual = await DkgClient.getActiveRitual(provider, domain, ritualId);
|
|
21
41
|
return await encryptWithPublicKey(message, condition, dkgRitual.dkgPublicKey, authSigner);
|
|
22
42
|
};
|
|
43
|
+
/**
|
|
44
|
+
* Encrypts a message with the given DKG public key under a specified condition.
|
|
45
|
+
*
|
|
46
|
+
* @export
|
|
47
|
+
* @param {Uint8Array | string} message - The message to be encrypted.
|
|
48
|
+
* @param {Condition} condition - Condition under which the message will be encrypted. Those conditions must be
|
|
49
|
+
* satisfied in order to decrypt the message.
|
|
50
|
+
* @param {DkgPublicKey} dkgPublicKey - The public key of an active DKG Ritual to be used for encryption
|
|
51
|
+
* @param {ethers.Signer} authSigner - The signer that will be used to sign the encrypter authorization.
|
|
52
|
+
*
|
|
53
|
+
* @returns {Promise<ThresholdMessageKit>} Returns Promise that resolves with an instance of ThresholdMessageKit.
|
|
54
|
+
* It represents the encrypted message.
|
|
55
|
+
*
|
|
56
|
+
* @throws {Error} If the encryption process throws an error, an error is thrown.
|
|
57
|
+
*/
|
|
23
58
|
export const encryptWithPublicKey = async (message, condition, dkgPublicKey, authSigner) => {
|
|
24
59
|
if (typeof message === 'string') {
|
|
25
60
|
message = toBytes(message);
|
|
@@ -31,14 +66,47 @@ export const encryptWithPublicKey = async (message, condition, dkgPublicKey, aut
|
|
|
31
66
|
const acp = new AccessControlPolicy(authenticatedData, fromHexString(authorization));
|
|
32
67
|
return new ThresholdMessageKit(ciphertext, acp);
|
|
33
68
|
};
|
|
69
|
+
/**
|
|
70
|
+
* Decrypts an encrypted message.
|
|
71
|
+
*
|
|
72
|
+
* @export
|
|
73
|
+
* @param {ethers.providers.Provider} provider - Instance of ethers provider which is used to interact with
|
|
74
|
+
* your selected network.
|
|
75
|
+
* @param {Domain} domain - Represents the logical network in which the decryption will be performed.
|
|
76
|
+
* Must match the `ritualId`.
|
|
77
|
+
* @param {ThresholdMessageKit} messageKit - The kit containing the message to be decrypted
|
|
78
|
+
* @param {string} [porterUri] - The URI for the Porter service. If not provided, a value will be obtained
|
|
79
|
+
* from the Domain
|
|
80
|
+
* @param {ethers.Signer} [signer] - An optional signer for the decryption
|
|
81
|
+
* @param {Record<string, CustomContextParam>} [customParameters] - Optional custom parameters that may be required
|
|
82
|
+
* depending on the condition used
|
|
83
|
+
*
|
|
84
|
+
* @returns {Promise<Uint8Array>} Returns Promise that resolves with a decrypted message
|
|
85
|
+
*
|
|
86
|
+
* @throws {Error} If the active DKG Ritual cannot be retrieved or decryption process throws an error,
|
|
87
|
+
* an error is thrown.
|
|
88
|
+
*/
|
|
34
89
|
export const decrypt = async (provider, domain, messageKit, porterUri, signer, customParameters) => {
|
|
35
90
|
if (!porterUri) {
|
|
36
91
|
porterUri = getPorterUri(domain);
|
|
37
92
|
}
|
|
38
93
|
const ritualId = await DkgCoordinatorAgent.getRitualIdFromPublicKey(provider, domain, messageKit.acp.publicKey);
|
|
39
|
-
const ritual = await DkgClient.
|
|
94
|
+
const ritual = await DkgClient.getActiveRitual(provider, domain, ritualId);
|
|
40
95
|
return retrieveAndDecrypt(provider, domain, porterUri, messageKit, ritualId, ritual.threshold, signer, customParameters);
|
|
41
96
|
};
|
|
97
|
+
/**
|
|
98
|
+
* Checks if the encryption from the provided messageKit is authorized for the specified ritual.
|
|
99
|
+
*
|
|
100
|
+
* @export
|
|
101
|
+
* @param {ethers.providers.Provider} provider - Instance of ethers provider which is used to interact with
|
|
102
|
+
* your selected network.
|
|
103
|
+
* @param {Domain} domain - The domain which was used to encrypt the network. Must match the `ritualId`.
|
|
104
|
+
* @param {ThresholdMessageKit} messageKit - The encrypted message kit to be checked.
|
|
105
|
+
* @param {number} ritualId - The ID of the DKG Ritual under which the messageKit was supposedly encrypted.
|
|
106
|
+
*
|
|
107
|
+
* @returns {Promise<boolean>} Returns a Promise that resolves with the authorization status.
|
|
108
|
+
* True if authorized, false otherwise
|
|
109
|
+
*/
|
|
42
110
|
export const isAuthorized = async (provider, domain, messageKit, ritualId) => DkgCoordinatorAgent.isEncryptionAuthorized(provider, domain, ritualId, messageKit);
|
|
43
111
|
export const registerEncrypters = async (provider, signer, domain, ritualId, encrypters) => {
|
|
44
112
|
await GlobalAllowListAgent.registerEncrypters(provider, signer, domain, ritualId, encrypters);
|
package/dist/es/taco.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"taco.js","sourceRoot":"","sources":["../../src/taco.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,mBAAmB,EAEnB,aAAa,EACb,mBAAmB,GACpB,MAAM,yBAAyB,CAAC;AACjC,OAAO,EAEL,mBAAmB,EAEnB,aAAa,EACb,YAAY,EACZ,oBAAoB,EACpB,OAAO,GACR,MAAM,kBAAkB,CAAC;AAE1B,OAAO,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;
|
|
1
|
+
{"version":3,"file":"taco.js","sourceRoot":"","sources":["../../src/taco.ts"],"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QAAgB,EAChB,EAAE,CACF,mBAAmB,CAAC,sBAAsB,CACxC,QAAQ,EACR,MAAM,EACN,QAAQ,EACR,UAAU,CACX,CAAC;AAEJ,MAAM,CAAC,MAAM,kBAAkB,GAAG,KAAK,EACrC,QAAmC,EACnC,MAAqB,EACrB,MAAc,EACd,QAAgB,EAChB,UAA6B,EACd,EAAE;IACjB,MAAM,oBAAoB,CAAC,kBAAkB,CAC3C,QAAQ,EACR,MAAM,EACN,MAAM,EACN,QAAQ,EACR,UAAU,CACX,CAAC;AACJ,CAAC,CAAC"}
|
package/dist/es/tdec.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { DkgPublicKey, ThresholdMessageKit } from '@nucypher/nucypher-core';
|
|
2
2
|
import { Domain } from '@nucypher/shared';
|
|
3
3
|
import { ethers } from 'ethers';
|
|
4
|
-
import { ConditionExpression
|
|
4
|
+
import { ConditionExpression } from './conditions/condition-expr';
|
|
5
|
+
import { CustomContextParam } from './conditions/context';
|
|
5
6
|
export declare const encryptMessage: (plaintext: Uint8Array | string, encryptingKey: DkgPublicKey, conditions: ConditionExpression, authSigner: ethers.Signer) => Promise<ThresholdMessageKit>;
|
|
6
7
|
export declare const retrieveAndDecrypt: (provider: ethers.providers.Provider, domain: Domain, porterUri: string, thresholdMessageKit: ThresholdMessageKit, ritualId: number, threshold: number, signer?: ethers.Signer, customParameters?: Record<string, CustomContextParam>) => Promise<Uint8Array>;
|
package/dist/es/tdec.js
CHANGED
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
import { AccessControlPolicy, combineDecryptionSharesSimple, DecryptionShareSimple, encryptForDkg, FerveoVariant, SessionStaticSecret, ThresholdDecryptionRequest, ThresholdMessageKit, } from '@nucypher/nucypher-core';
|
|
2
2
|
import { DkgCoordinatorAgent, PorterClient, toBytes, } from '@nucypher/shared';
|
|
3
3
|
import { arrayify, keccak256 } from 'ethers/lib/utils';
|
|
4
|
-
import { ConditionContext } from './conditions';
|
|
4
|
+
import { ConditionContext } from './conditions/context';
|
|
5
|
+
const ERR_DECRYPTION_FAILED = (errors) => `Threshold of responses not met; TACo decryption failed with errors: ${JSON.stringify(errors)}`;
|
|
6
|
+
const ERR_RITUAL_ID_MISMATCH = (expectedRitualId, ritualIds) => `Ritual id mismatch. Expected ${expectedRitualId}, got ${ritualIds}`;
|
|
5
7
|
export const encryptMessage = async (plaintext, encryptingKey, conditions, authSigner) => {
|
|
6
8
|
const [ciphertext, authenticatedData] = encryptForDkg(plaintext instanceof Uint8Array ? plaintext : toBytes(plaintext), encryptingKey, conditions.toWASMConditions());
|
|
7
9
|
const headerHash = keccak256(ciphertext.header.toBytes());
|
|
@@ -23,7 +25,7 @@ const retrieve = async (provider, domain, porterUri, thresholdMessageKit, ritual
|
|
|
23
25
|
const porter = new PorterClient(porterUri);
|
|
24
26
|
const { encryptedResponses, errors } = await porter.tacoDecrypt(encryptedRequests, threshold);
|
|
25
27
|
if (Object.keys(encryptedResponses).length < threshold) {
|
|
26
|
-
throw new Error(
|
|
28
|
+
throw new Error(ERR_DECRYPTION_FAILED(errors));
|
|
27
29
|
}
|
|
28
30
|
return makeDecryptionShares(encryptedResponses, sharedSecrets, ritualId);
|
|
29
31
|
};
|
|
@@ -31,7 +33,7 @@ const makeDecryptionShares = (encryptedResponses, sessionSharedSecret, expectedR
|
|
|
31
33
|
const decryptedResponses = Object.entries(encryptedResponses).map(([ursula, response]) => response.decrypt(sessionSharedSecret[ursula]));
|
|
32
34
|
const ritualIds = decryptedResponses.map(({ ritualId }) => ritualId);
|
|
33
35
|
if (ritualIds.some((ritualId) => ritualId !== expectedRitualId)) {
|
|
34
|
-
throw new Error(
|
|
36
|
+
throw new Error(ERR_RITUAL_ID_MISMATCH(expectedRitualId, ritualIds));
|
|
35
37
|
}
|
|
36
38
|
return decryptedResponses.map(({ decryptionShare }) => DecryptionShareSimple.fromBytes(decryptionShare));
|
|
37
39
|
};
|
package/dist/es/tdec.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"tdec.js","sourceRoot":"","sources":["../../src/tdec.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,mBAAmB,EACnB,6BAA6B,EAE7B,qBAAqB,EAIrB,aAAa,EACb,aAAa,EAEb,mBAAmB,EACnB,0BAA0B,EAC1B,mBAAmB,GACpB,MAAM,yBAAyB,CAAC;AACjC,OAAO,EACL,mBAAmB,EAGnB,YAAY,EACZ,OAAO,GACR,MAAM,kBAAkB,CAAC;AAE1B,OAAO,EAAE,QAAQ,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;
|
|
1
|
+
{"version":3,"file":"tdec.js","sourceRoot":"","sources":["../../src/tdec.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,mBAAmB,EACnB,6BAA6B,EAE7B,qBAAqB,EAIrB,aAAa,EACb,aAAa,EAEb,mBAAmB,EACnB,0BAA0B,EAC1B,mBAAmB,GACpB,MAAM,yBAAyB,CAAC;AACjC,OAAO,EACL,mBAAmB,EAGnB,YAAY,EACZ,OAAO,GACR,MAAM,kBAAkB,CAAC;AAE1B,OAAO,EAAE,QAAQ,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AAGvD,OAAO,EAAE,gBAAgB,EAAsB,MAAM,sBAAsB,CAAC;AAE5E,MAAM,qBAAqB,GAAG,CAAC,MAAe,EAAE,EAAE,CAChD,uEAAuE,IAAI,CAAC,SAAS,CACnF,MAAM,CACP,EAAE,CAAC;AACN,MAAM,sBAAsB,GAAG,CAC7B,gBAAwB,EACxB,SAAmB,EACnB,EAAE,CAAC,gCAAgC,gBAAgB,SAAS,SAAS,EAAE,CAAC;AAE1E,MAAM,CAAC,MAAM,cAAc,GAAG,KAAK,EACjC,SAA8B,EAC9B,aAA2B,EAC3B,UAA+B,EAC/B,UAAyB,EACK,EAAE;IAChC,MAAM,CAAC,UAAU,EAAE,iBAAiB,CAAC,GAAG,aAAa,CACnD,SAAS,YAAY,UAAU,CAAC,CAAC,CAAC,SAAS,C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