@zhoujun_aptos/octopus-ts-sdk-min 0.22.7 → 0.23.0
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/common/index.d.ts +55 -45
- package/dist/common/index.js +169 -88
- package/dist/common/index.js.map +1 -1
- package/dist/esm/index.d.mts +55 -45
- package/dist/esm/index.mjs +168 -88
- package/dist/esm/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/common/index.d.ts
CHANGED
|
@@ -150,12 +150,46 @@ declare function keygen$3(schemeId?: number): DecryptionKey$1;
|
|
|
150
150
|
declare function deriveEncryptionKey(dk: DecryptionKey$1): EncryptionKey$1;
|
|
151
151
|
declare function encrypt$3(ek: EncryptionKey$1, msg: Uint8Array): Ciphertext$5;
|
|
152
152
|
declare function encryptWithRandomness$2(ek: EncryptionKey$1, msg: Uint8Array, randomness: Uint8Array): Ciphertext$5;
|
|
153
|
-
declare function decrypt$
|
|
153
|
+
declare function decrypt$2(dk: DecryptionKey$1, ciphertext: Ciphertext$5): Uint8Array | undefined;
|
|
154
154
|
|
|
155
155
|
declare const index$5_SCHEME_SIMPLE_ELGAMAL_RISTRETTO255: typeof SCHEME_SIMPLE_ELGAMAL_RISTRETTO255;
|
|
156
156
|
declare const index$5_deriveEncryptionKey: typeof deriveEncryptionKey;
|
|
157
157
|
declare namespace index$5 {
|
|
158
|
-
export { Ciphertext$5 as Ciphertext, DecryptionKey$1 as DecryptionKey, EncryptionKey$1 as EncryptionKey, index$5_SCHEME_SIMPLE_ELGAMAL_RISTRETTO255 as SCHEME_SIMPLE_ELGAMAL_RISTRETTO255, decrypt$
|
|
158
|
+
export { Ciphertext$5 as Ciphertext, DecryptionKey$1 as DecryptionKey, EncryptionKey$1 as EncryptionKey, index$5_SCHEME_SIMPLE_ELGAMAL_RISTRETTO255 as SCHEME_SIMPLE_ELGAMAL_RISTRETTO255, decrypt$2 as decrypt, index$5_deriveEncryptionKey as deriveEncryptionKey, encrypt$3 as encrypt, encryptWithRandomness$2 as encryptWithRandomness, keygen$3 as keygen };
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
declare class Result<T> {
|
|
162
|
+
isOk: boolean;
|
|
163
|
+
okValue?: T;
|
|
164
|
+
errValue?: any;
|
|
165
|
+
extra?: any;
|
|
166
|
+
private constructor();
|
|
167
|
+
static Ok<T>(args: {
|
|
168
|
+
value: T;
|
|
169
|
+
extra?: any;
|
|
170
|
+
}): Result<T>;
|
|
171
|
+
static Err<T>(args: {
|
|
172
|
+
error: any;
|
|
173
|
+
extra?: any;
|
|
174
|
+
}): Result<T>;
|
|
175
|
+
/**
|
|
176
|
+
* You write a closure that either returns a T or throws, and we wrap it to return a Result<T>.
|
|
177
|
+
* Your closure is also given an `extra` dictionary to record additional context.
|
|
178
|
+
*/
|
|
179
|
+
static capture<T>({ task, recordsExecutionTimeMs }: {
|
|
180
|
+
task: (extra: Record<string, any>) => T;
|
|
181
|
+
recordsExecutionTimeMs: boolean;
|
|
182
|
+
}): Result<T>;
|
|
183
|
+
/**
|
|
184
|
+
* You write an async closure that either returns a T or throws, and we wrap it to return a Result<T>.
|
|
185
|
+
* Your closure is also given an `extra` dictionary to record additional context.
|
|
186
|
+
*/
|
|
187
|
+
static captureAsync<T>({ task, recordsExecutionTimeMs }: {
|
|
188
|
+
task: (extra: Record<string, any>) => Promise<T>;
|
|
189
|
+
recordsExecutionTimeMs: boolean;
|
|
190
|
+
}): Promise<Result<T>>;
|
|
191
|
+
unwrapOrThrow(tothrow: any): T;
|
|
192
|
+
unwrapErrOrThrow(tothrow: any): any | undefined;
|
|
159
193
|
}
|
|
160
194
|
|
|
161
195
|
declare const SCHEME_OTP_HAMC_BONEH_FRANKLIN_BLS12381_SHORT_PK = 0;
|
|
@@ -208,8 +242,12 @@ declare function derivePublicKey(privateKey: MasterPrivateKey): MasterPublicKey;
|
|
|
208
242
|
declare function encrypt$2(publicKey: MasterPublicKey, id: Uint8Array, plaintext: Uint8Array): Ciphertext$4;
|
|
209
243
|
/** Do NOT use this, unless you are a maintainer. Use `encrypt` instead. */
|
|
210
244
|
declare function encryptWithRandomness$1(publicKey: MasterPublicKey, id: Uint8Array, plaintext: Uint8Array, randomness: Uint8Array): Ciphertext$4;
|
|
245
|
+
/** @deprecated Use tryExtract instead */
|
|
211
246
|
declare function extract(privateKey: MasterPrivateKey, id: Uint8Array): IdentityPrivateKey;
|
|
212
|
-
declare function
|
|
247
|
+
declare function tryExtract$1(privateKey: MasterPrivateKey, id: Uint8Array): Result<IdentityPrivateKey>;
|
|
248
|
+
/** @deprecated Use tryDecrypt instead */
|
|
249
|
+
declare function decrypt$1(identityKey: IdentityPrivateKey, ciphertext: Ciphertext$4): Uint8Array | undefined;
|
|
250
|
+
declare function tryDecrypt$2(identityKey: IdentityPrivateKey, ciphertext: Ciphertext$4): Result<Uint8Array>;
|
|
213
251
|
|
|
214
252
|
type index$4_IdentityPrivateKey = IdentityPrivateKey;
|
|
215
253
|
declare const index$4_IdentityPrivateKey: typeof IdentityPrivateKey;
|
|
@@ -221,7 +259,7 @@ declare const index$4_SCHEME_OTP_HAMC_BONEH_FRANKLIN_BLS12381_SHORT_PK: typeof S
|
|
|
221
259
|
declare const index$4_derivePublicKey: typeof derivePublicKey;
|
|
222
260
|
declare const index$4_extract: typeof extract;
|
|
223
261
|
declare namespace index$4 {
|
|
224
|
-
export { Ciphertext$4 as Ciphertext, index$4_IdentityPrivateKey as IdentityPrivateKey, index$4_MasterPrivateKey as MasterPrivateKey, index$4_MasterPublicKey as MasterPublicKey, index$4_SCHEME_OTP_HAMC_BONEH_FRANKLIN_BLS12381_SHORT_PK as SCHEME_OTP_HAMC_BONEH_FRANKLIN_BLS12381_SHORT_PK, decrypt$
|
|
262
|
+
export { Ciphertext$4 as Ciphertext, index$4_IdentityPrivateKey as IdentityPrivateKey, index$4_MasterPrivateKey as MasterPrivateKey, index$4_MasterPublicKey as MasterPublicKey, index$4_SCHEME_OTP_HAMC_BONEH_FRANKLIN_BLS12381_SHORT_PK as SCHEME_OTP_HAMC_BONEH_FRANKLIN_BLS12381_SHORT_PK, decrypt$1 as decrypt, index$4_derivePublicKey as derivePublicKey, encrypt$2 as encrypt, encryptWithRandomness$1 as encryptWithRandomness, index$4_extract as extract, keygen$2 as keygen, tryDecrypt$2 as tryDecrypt, tryExtract$1 as tryExtract };
|
|
225
263
|
}
|
|
226
264
|
|
|
227
265
|
declare class SchnorrRistretto255SigningKey {
|
|
@@ -325,46 +363,17 @@ declare class Ciphertext$3 {
|
|
|
325
363
|
declare function keygen(scheme?: number): Key;
|
|
326
364
|
declare function encrypt$1(key: Key, plaintext: Uint8Array): Ciphertext$3;
|
|
327
365
|
declare function encryptWithRandomness(key: Key, plaintext: Uint8Array, randomness: Uint8Array): Ciphertext$3;
|
|
328
|
-
|
|
366
|
+
/** @deprecated Use tryDecrypt instead */
|
|
367
|
+
declare function decrypt(key: Key, ciphertext: Ciphertext$3): Uint8Array | undefined;
|
|
368
|
+
declare function tryDecrypt$1(key: Key, ciphertext: Ciphertext$3): Result<Uint8Array>;
|
|
329
369
|
|
|
330
370
|
type index$2_Key = Key;
|
|
331
371
|
declare const index$2_Key: typeof Key;
|
|
372
|
+
declare const index$2_decrypt: typeof decrypt;
|
|
332
373
|
declare const index$2_encryptWithRandomness: typeof encryptWithRandomness;
|
|
333
374
|
declare const index$2_keygen: typeof keygen;
|
|
334
375
|
declare namespace index$2 {
|
|
335
|
-
export { Ciphertext$3 as Ciphertext, index$2_Key as Key,
|
|
336
|
-
}
|
|
337
|
-
|
|
338
|
-
declare class Result<T> {
|
|
339
|
-
isOk: boolean;
|
|
340
|
-
okValue?: T;
|
|
341
|
-
errValue?: any;
|
|
342
|
-
extra?: any;
|
|
343
|
-
private constructor();
|
|
344
|
-
static Ok<T>(args: {
|
|
345
|
-
value: T;
|
|
346
|
-
extra?: any;
|
|
347
|
-
}): Result<T>;
|
|
348
|
-
static Err<T>(args: {
|
|
349
|
-
error: any;
|
|
350
|
-
extra?: any;
|
|
351
|
-
}): Result<T>;
|
|
352
|
-
/**
|
|
353
|
-
* You write a closure that either returns a T or throws, and we wrap it to return a Result<T>.
|
|
354
|
-
* Your closure is also given an `extra` dictionary to record additional context.
|
|
355
|
-
*/
|
|
356
|
-
static capture<T>({ task, recordsExecutionTimeMs }: {
|
|
357
|
-
task: (extra: Record<string, any>) => T;
|
|
358
|
-
recordsExecutionTimeMs: boolean;
|
|
359
|
-
}): Result<T>;
|
|
360
|
-
/**
|
|
361
|
-
* You write an async closure that either returns a T or throws, and we wrap it to return a Result<T>.
|
|
362
|
-
* Your closure is also given an `extra` dictionary to record additional context.
|
|
363
|
-
*/
|
|
364
|
-
static captureAsync<T>({ task, recordsExecutionTimeMs }: {
|
|
365
|
-
task: (extra: Record<string, any>) => Promise<T>;
|
|
366
|
-
recordsExecutionTimeMs: boolean;
|
|
367
|
-
}): Promise<Result<T>>;
|
|
376
|
+
export { Ciphertext$3 as Ciphertext, index$2_Key as Key, index$2_decrypt as decrypt, encrypt$1 as encrypt, index$2_encryptWithRandomness as encryptWithRandomness, index$2_keygen as keygen, tryDecrypt$1 as tryDecrypt };
|
|
368
377
|
}
|
|
369
378
|
|
|
370
379
|
declare class WorkerConfig {
|
|
@@ -384,6 +393,7 @@ declare class WorkerConfig {
|
|
|
384
393
|
toPrettyJson(): string;
|
|
385
394
|
}
|
|
386
395
|
declare function view(aptos: Aptos, worker: AccountAddress): Promise<WorkerConfig>;
|
|
396
|
+
/** @deprecated Use getAsync instead */
|
|
387
397
|
declare function get(workerEndpoint: string): Promise<WorkerConfig>;
|
|
388
398
|
declare function getAsync(workerEndpoint: string): Promise<Result<WorkerConfig>>;
|
|
389
399
|
declare function randWorker(): {
|
|
@@ -914,11 +924,11 @@ declare function encrypt({ committee, encryptionKey, contractId, domain, plainte
|
|
|
914
924
|
fullDecryptionDomain: FullDecryptionDomain;
|
|
915
925
|
ciphertext: Ciphertext;
|
|
916
926
|
};
|
|
917
|
-
declare function
|
|
927
|
+
declare function tryDecrypt({ decryptionKey, ciphertext }: {
|
|
918
928
|
decryptionKey: DecryptionKey;
|
|
919
929
|
ciphertext: Ciphertext;
|
|
920
|
-
}): Uint8Array
|
|
921
|
-
declare function
|
|
930
|
+
}): Result<Uint8Array>;
|
|
931
|
+
declare function tryExtract({ ibeMsk, committee, contractId, domain, proof }: {
|
|
922
932
|
ibeMsk: MasterPrivateKey;
|
|
923
933
|
committee: Committee;
|
|
924
934
|
contractId: ContractID;
|
|
@@ -940,11 +950,11 @@ type index_FullDecryptionDomain = FullDecryptionDomain;
|
|
|
940
950
|
declare const index_FullDecryptionDomain: typeof FullDecryptionDomain;
|
|
941
951
|
type index_ProofOfPermission = ProofOfPermission;
|
|
942
952
|
declare const index_ProofOfPermission: typeof ProofOfPermission;
|
|
943
|
-
declare const index_decrypt: typeof decrypt;
|
|
944
953
|
declare const index_encrypt: typeof encrypt;
|
|
945
|
-
declare const
|
|
954
|
+
declare const index_tryDecrypt: typeof tryDecrypt;
|
|
955
|
+
declare const index_tryExtract: typeof tryExtract;
|
|
946
956
|
declare namespace index {
|
|
947
|
-
export { index_Ciphertext as Ciphertext, index_Committee as Committee, index_ContractID as ContractID, index_DecryptionKey as DecryptionKey, index_EncryptionKey as EncryptionKey, index_FullDecryptionDomain as FullDecryptionDomain, index_ProofOfPermission as ProofOfPermission,
|
|
957
|
+
export { index_Ciphertext as Ciphertext, index_Committee as Committee, index_ContractID as ContractID, index_DecryptionKey as DecryptionKey, index_EncryptionKey as EncryptionKey, index_FullDecryptionDomain as FullDecryptionDomain, index_ProofOfPermission as ProofOfPermission, index_encrypt as encrypt, index_tryDecrypt as tryDecrypt, index_tryExtract as tryExtract };
|
|
948
958
|
}
|
|
949
959
|
|
|
950
960
|
declare const CONTRACT_ADDRESS_HEX: string;
|
|
@@ -998,4 +1008,4 @@ declare class WorkerTask {
|
|
|
998
1008
|
};
|
|
999
1009
|
}
|
|
1000
1010
|
|
|
1001
|
-
export { elgamal as ElGamal, index$5 as Enc, group as Group, index$4 as IBE, index$3 as Sig, silent_setup_encryption as SilentSetupEncryption, index$1 as SilentSetupEncryptionXChain, index$2 as Sym, index as ThresholdIbe, utils as Utils, worker_config as WorkerConfig, WorkerTask };
|
|
1011
|
+
export { elgamal as ElGamal, index$5 as Enc, group as Group, index$4 as IBE, Result, index$3 as Sig, silent_setup_encryption as SilentSetupEncryption, index$1 as SilentSetupEncryptionXChain, index$2 as Sym, index as ThresholdIbe, utils as Utils, worker_config as WorkerConfig, WorkerTask };
|
package/dist/common/index.js
CHANGED
|
@@ -34,6 +34,7 @@ __export(index_exports, {
|
|
|
34
34
|
Enc: () => enc_exports,
|
|
35
35
|
Group: () => group_exports,
|
|
36
36
|
IBE: () => ibe_exports,
|
|
37
|
+
Result: () => Result,
|
|
37
38
|
Sig: () => sig_exports,
|
|
38
39
|
SilentSetupEncryption: () => silent_setup_encryption_exports,
|
|
39
40
|
SilentSetupEncryptionXChain: () => silent_setup_encryption_xchain_exports,
|
|
@@ -752,7 +753,9 @@ __export(ibe_exports, {
|
|
|
752
753
|
encrypt: () => encrypt4,
|
|
753
754
|
encryptWithRandomness: () => encryptWithRandomness4,
|
|
754
755
|
extract: () => extract2,
|
|
755
|
-
keygen: () => keygen4
|
|
756
|
+
keygen: () => keygen4,
|
|
757
|
+
tryDecrypt: () => tryDecrypt2,
|
|
758
|
+
tryExtract: () => tryExtract
|
|
756
759
|
});
|
|
757
760
|
var import_ts_sdk6 = require("@aptos-labs/ts-sdk");
|
|
758
761
|
var import_utils9 = require("@noble/curves/abstract/utils");
|
|
@@ -761,6 +764,84 @@ var import_utils9 = require("@noble/curves/abstract/utils");
|
|
|
761
764
|
var import_bls12_381 = require("@noble/curves/bls12-381");
|
|
762
765
|
var import_utils6 = require("@noble/curves/utils");
|
|
763
766
|
var import_utils7 = require("@noble/hashes/utils");
|
|
767
|
+
|
|
768
|
+
// src/result.ts
|
|
769
|
+
var Result = class _Result {
|
|
770
|
+
isOk;
|
|
771
|
+
okValue;
|
|
772
|
+
errValue;
|
|
773
|
+
extra;
|
|
774
|
+
constructor({ isOk, okValue, errValue, extra }) {
|
|
775
|
+
this.isOk = isOk;
|
|
776
|
+
this.okValue = okValue;
|
|
777
|
+
this.errValue = errValue;
|
|
778
|
+
this.extra = extra;
|
|
779
|
+
}
|
|
780
|
+
static Ok(args) {
|
|
781
|
+
return new _Result({ isOk: true, okValue: args.value, extra: args.extra });
|
|
782
|
+
}
|
|
783
|
+
static Err(args) {
|
|
784
|
+
return new _Result({ isOk: false, errValue: args.error, extra: args.extra });
|
|
785
|
+
}
|
|
786
|
+
/**
|
|
787
|
+
* You write a closure that either returns a T or throws, and we wrap it to return a Result<T>.
|
|
788
|
+
* Your closure is also given an `extra` dictionary to record additional context.
|
|
789
|
+
*/
|
|
790
|
+
static capture({ task, recordsExecutionTimeMs = false }) {
|
|
791
|
+
const start = performance.now();
|
|
792
|
+
var extra = {};
|
|
793
|
+
var error;
|
|
794
|
+
var okValue;
|
|
795
|
+
try {
|
|
796
|
+
okValue = task(extra);
|
|
797
|
+
} catch (caught) {
|
|
798
|
+
error = caught;
|
|
799
|
+
} finally {
|
|
800
|
+
if (recordsExecutionTimeMs) {
|
|
801
|
+
extra["_sdk_execution_time_ms"] = performance.now() - start;
|
|
802
|
+
}
|
|
803
|
+
if (error !== void 0) {
|
|
804
|
+
return _Result.Err({ error, extra });
|
|
805
|
+
} else {
|
|
806
|
+
return _Result.Ok({ value: okValue, extra });
|
|
807
|
+
}
|
|
808
|
+
}
|
|
809
|
+
}
|
|
810
|
+
/**
|
|
811
|
+
* You write an async closure that either returns a T or throws, and we wrap it to return a Result<T>.
|
|
812
|
+
* Your closure is also given an `extra` dictionary to record additional context.
|
|
813
|
+
*/
|
|
814
|
+
static async captureAsync({ task, recordsExecutionTimeMs = false }) {
|
|
815
|
+
var extra = {};
|
|
816
|
+
const start = performance.now();
|
|
817
|
+
var error;
|
|
818
|
+
var okValue;
|
|
819
|
+
try {
|
|
820
|
+
okValue = await task(extra);
|
|
821
|
+
} catch (caught) {
|
|
822
|
+
error = caught;
|
|
823
|
+
} finally {
|
|
824
|
+
if (recordsExecutionTimeMs) {
|
|
825
|
+
extra["_sdk_execution_time_ms"] = performance.now() - start;
|
|
826
|
+
}
|
|
827
|
+
if (error !== void 0) {
|
|
828
|
+
return _Result.Err({ error, extra });
|
|
829
|
+
} else {
|
|
830
|
+
return _Result.Ok({ value: okValue, extra });
|
|
831
|
+
}
|
|
832
|
+
}
|
|
833
|
+
}
|
|
834
|
+
unwrapOrThrow(tothrow) {
|
|
835
|
+
if (!this.isOk) throw tothrow;
|
|
836
|
+
return this.okValue;
|
|
837
|
+
}
|
|
838
|
+
unwrapErrOrThrow(tothrow) {
|
|
839
|
+
if (this.isOk) throw tothrow;
|
|
840
|
+
return this.errValue;
|
|
841
|
+
}
|
|
842
|
+
};
|
|
843
|
+
|
|
844
|
+
// src/ibe/otp_hmac_boneh_franklin_bls12381_short_pk.ts
|
|
764
845
|
var DST_OTP = new TextEncoder().encode("BONEH_FRANKLIN_BLS12381_SHORT_PK/OTP");
|
|
765
846
|
var DST_ID_HASH = new TextEncoder().encode("BONEH_FRANKLIN_BLS12381_SHORT_PK/HASH_ID_TO_CURVE");
|
|
766
847
|
var DST_MAC = new TextEncoder().encode("BONEH_FRANKLIN_BLS12381_SHORT_PK/MAC");
|
|
@@ -894,6 +975,21 @@ function decrypt3(identityKey, ciphertext) {
|
|
|
894
975
|
const plaintext = xorBytes(otp, ciphertext.symmetricCiph);
|
|
895
976
|
return plaintext;
|
|
896
977
|
}
|
|
978
|
+
function tryDecrypt(identityKey, ciphertext) {
|
|
979
|
+
const task = (_extra) => {
|
|
980
|
+
const seedElementGt = import_bls12_381.bls12_381.pairing(ciphertext.c0, identityKey.privatePointG2);
|
|
981
|
+
const seed = bls12381GtReprNobleToAptos(import_bls12_381.bls12_381.fields.Fp12.toBytes(seedElementGt));
|
|
982
|
+
const macKey = kdf(seed, DST_MAC, 32);
|
|
983
|
+
const macAnother = hmac_sha3_256(macKey, ciphertext.symmetricCiph);
|
|
984
|
+
if ((0, import_utils7.bytesToHex)(ciphertext.mac) !== (0, import_utils7.bytesToHex)(macAnother)) {
|
|
985
|
+
throw "decryption failed";
|
|
986
|
+
}
|
|
987
|
+
const otp = kdf(seed, DST_OTP, ciphertext.symmetricCiph.length);
|
|
988
|
+
const plaintext = xorBytes(otp, ciphertext.symmetricCiph);
|
|
989
|
+
return plaintext;
|
|
990
|
+
};
|
|
991
|
+
return Result.capture({ task, recordsExecutionTimeMs: true });
|
|
992
|
+
}
|
|
897
993
|
|
|
898
994
|
// src/ibe/index.ts
|
|
899
995
|
var SCHEME_OTP_HAMC_BONEH_FRANKLIN_BLS12381_SHORT_PK = 0;
|
|
@@ -1124,12 +1220,36 @@ function extract2(privateKey, id) {
|
|
|
1124
1220
|
}
|
|
1125
1221
|
throw new Error(`Unknown scheme: ${privateKey.scheme}`);
|
|
1126
1222
|
}
|
|
1223
|
+
function tryExtract(privateKey, id) {
|
|
1224
|
+
const task = (extra) => {
|
|
1225
|
+
extra["scheme"] = privateKey.scheme;
|
|
1226
|
+
if (privateKey.scheme == SCHEME_OTP_HAMC_BONEH_FRANKLIN_BLS12381_SHORT_PK) {
|
|
1227
|
+
return new IdentityPrivateKey2(
|
|
1228
|
+
SCHEME_OTP_HAMC_BONEH_FRANKLIN_BLS12381_SHORT_PK,
|
|
1229
|
+
extract(privateKey.inner, id)
|
|
1230
|
+
);
|
|
1231
|
+
}
|
|
1232
|
+
throw `unknown scheme`;
|
|
1233
|
+
};
|
|
1234
|
+
return Result.capture({ task, recordsExecutionTimeMs: true });
|
|
1235
|
+
}
|
|
1127
1236
|
function decrypt4(identityKey, ciphertext) {
|
|
1128
1237
|
if (identityKey.scheme == SCHEME_OTP_HAMC_BONEH_FRANKLIN_BLS12381_SHORT_PK) {
|
|
1129
1238
|
return decrypt3(identityKey.inner, ciphertext.inner);
|
|
1130
1239
|
}
|
|
1131
1240
|
throw new Error(`Unknown scheme: ${identityKey.scheme}`);
|
|
1132
1241
|
}
|
|
1242
|
+
function tryDecrypt2(identityKey, ciphertext) {
|
|
1243
|
+
const task = (extra) => {
|
|
1244
|
+
extra["scheme"] = identityKey.scheme;
|
|
1245
|
+
if (identityKey.scheme == SCHEME_OTP_HAMC_BONEH_FRANKLIN_BLS12381_SHORT_PK) {
|
|
1246
|
+
const innerResult = tryDecrypt(identityKey.inner, ciphertext.inner);
|
|
1247
|
+
return innerResult.unwrapOrThrow("OtpHmacBonehFranklinBls12381ShortPK.tryDecrypt failed");
|
|
1248
|
+
}
|
|
1249
|
+
throw `unknown scheme`;
|
|
1250
|
+
};
|
|
1251
|
+
return Result.capture({ task, recordsExecutionTimeMs: true });
|
|
1252
|
+
}
|
|
1133
1253
|
|
|
1134
1254
|
// src/sig/index.ts
|
|
1135
1255
|
var sig_exports = {};
|
|
@@ -2196,7 +2316,8 @@ __export(sym_exports, {
|
|
|
2196
2316
|
decrypt: () => decrypt6,
|
|
2197
2317
|
encrypt: () => encrypt6,
|
|
2198
2318
|
encryptWithRandomness: () => encryptWithRandomness6,
|
|
2199
|
-
keygen: () => keygen8
|
|
2319
|
+
keygen: () => keygen8,
|
|
2320
|
+
tryDecrypt: () => tryDecrypt4
|
|
2200
2321
|
});
|
|
2201
2322
|
var import_ts_sdk10 = require("@aptos-labs/ts-sdk");
|
|
2202
2323
|
var import_utils15 = require("@noble/curves/utils");
|
|
@@ -2297,6 +2418,16 @@ function decrypt5(key, ciphertext) {
|
|
|
2297
2418
|
return void 0;
|
|
2298
2419
|
}
|
|
2299
2420
|
}
|
|
2421
|
+
function tryDecrypt3(key, ciphertext) {
|
|
2422
|
+
const task = (_extra) => {
|
|
2423
|
+
const gcmInstance = (0, import_aes.gcm)(key.inner, ciphertext.iv);
|
|
2424
|
+
const encryptedData = new Uint8Array(ciphertext.ct.length + ciphertext.tag.length);
|
|
2425
|
+
encryptedData.set(ciphertext.ct, 0);
|
|
2426
|
+
encryptedData.set(ciphertext.tag, ciphertext.ct.length);
|
|
2427
|
+
return gcmInstance.decrypt(encryptedData);
|
|
2428
|
+
};
|
|
2429
|
+
return Result.capture({ task, recordsExecutionTimeMs: true });
|
|
2430
|
+
}
|
|
2300
2431
|
|
|
2301
2432
|
// src/sym/index.ts
|
|
2302
2433
|
var SCHEME_AES256GCM = 0;
|
|
@@ -2406,6 +2537,17 @@ function decrypt6(key, ciphertext) {
|
|
|
2406
2537
|
}
|
|
2407
2538
|
throw new Error("Invalid scheme");
|
|
2408
2539
|
}
|
|
2540
|
+
function tryDecrypt4(key, ciphertext) {
|
|
2541
|
+
const task = (extra) => {
|
|
2542
|
+
extra["scheme"] = key.scheme;
|
|
2543
|
+
if (key.scheme === SCHEME_AES256GCM) {
|
|
2544
|
+
const innerResult = tryDecrypt3(key.inner, ciphertext.inner);
|
|
2545
|
+
return innerResult.unwrapOrThrow("AES256GCM decryption failed");
|
|
2546
|
+
}
|
|
2547
|
+
throw `unknown scheme`;
|
|
2548
|
+
};
|
|
2549
|
+
return Result.capture({ task, recordsExecutionTimeMs: true });
|
|
2550
|
+
}
|
|
2409
2551
|
|
|
2410
2552
|
// src/worker_config.ts
|
|
2411
2553
|
var worker_config_exports = {};
|
|
@@ -2418,76 +2560,6 @@ __export(worker_config_exports, {
|
|
|
2418
2560
|
});
|
|
2419
2561
|
var import_ts_sdk11 = require("@aptos-labs/ts-sdk");
|
|
2420
2562
|
var import_utils16 = require("@noble/curves/utils");
|
|
2421
|
-
|
|
2422
|
-
// src/result.ts
|
|
2423
|
-
var Result = class _Result {
|
|
2424
|
-
isOk;
|
|
2425
|
-
okValue;
|
|
2426
|
-
errValue;
|
|
2427
|
-
extra;
|
|
2428
|
-
constructor({ isOk, okValue, errValue, extra }) {
|
|
2429
|
-
this.isOk = isOk;
|
|
2430
|
-
this.okValue = okValue;
|
|
2431
|
-
this.errValue = errValue;
|
|
2432
|
-
this.extra = extra;
|
|
2433
|
-
}
|
|
2434
|
-
static Ok(args) {
|
|
2435
|
-
return new _Result({ isOk: true, okValue: args.value, extra: args.extra });
|
|
2436
|
-
}
|
|
2437
|
-
static Err(args) {
|
|
2438
|
-
return new _Result({ isOk: false, errValue: args.error, extra: args.extra });
|
|
2439
|
-
}
|
|
2440
|
-
/**
|
|
2441
|
-
* You write a closure that either returns a T or throws, and we wrap it to return a Result<T>.
|
|
2442
|
-
* Your closure is also given an `extra` dictionary to record additional context.
|
|
2443
|
-
*/
|
|
2444
|
-
static capture({ task, recordsExecutionTimeMs = false }) {
|
|
2445
|
-
const start = performance.now();
|
|
2446
|
-
var extra = {};
|
|
2447
|
-
var error;
|
|
2448
|
-
var okValue;
|
|
2449
|
-
try {
|
|
2450
|
-
okValue = task(extra);
|
|
2451
|
-
} catch (caught) {
|
|
2452
|
-
error = caught;
|
|
2453
|
-
} finally {
|
|
2454
|
-
if (recordsExecutionTimeMs) {
|
|
2455
|
-
extra["_sdk_execution_time_ms"] = performance.now() - start;
|
|
2456
|
-
}
|
|
2457
|
-
if (error !== void 0) {
|
|
2458
|
-
return _Result.Err({ error, extra });
|
|
2459
|
-
} else {
|
|
2460
|
-
return _Result.Ok({ value: okValue, extra });
|
|
2461
|
-
}
|
|
2462
|
-
}
|
|
2463
|
-
}
|
|
2464
|
-
/**
|
|
2465
|
-
* You write an async closure that either returns a T or throws, and we wrap it to return a Result<T>.
|
|
2466
|
-
* Your closure is also given an `extra` dictionary to record additional context.
|
|
2467
|
-
*/
|
|
2468
|
-
static async captureAsync({ task, recordsExecutionTimeMs = false }) {
|
|
2469
|
-
var extra = {};
|
|
2470
|
-
const start = performance.now();
|
|
2471
|
-
var error;
|
|
2472
|
-
var okValue;
|
|
2473
|
-
try {
|
|
2474
|
-
okValue = await task(extra);
|
|
2475
|
-
} catch (caught) {
|
|
2476
|
-
error = caught;
|
|
2477
|
-
} finally {
|
|
2478
|
-
if (recordsExecutionTimeMs) {
|
|
2479
|
-
extra["_sdk_execution_time_ms"] = performance.now() - start;
|
|
2480
|
-
}
|
|
2481
|
-
if (error !== void 0) {
|
|
2482
|
-
return _Result.Err({ error, extra });
|
|
2483
|
-
} else {
|
|
2484
|
-
return _Result.Ok({ value: okValue, extra });
|
|
2485
|
-
}
|
|
2486
|
-
}
|
|
2487
|
-
}
|
|
2488
|
-
};
|
|
2489
|
-
|
|
2490
|
-
// src/worker_config.ts
|
|
2491
2563
|
var WorkerConfig = class _WorkerConfig {
|
|
2492
2564
|
expiryTimeMicrosecs;
|
|
2493
2565
|
endpoint;
|
|
@@ -2615,9 +2687,9 @@ __export(threshold_ibe_exports, {
|
|
|
2615
2687
|
EncryptionKey: () => EncryptionKey2,
|
|
2616
2688
|
FullDecryptionDomain: () => FullDecryptionDomain,
|
|
2617
2689
|
ProofOfPermission: () => ProofOfPermission3,
|
|
2618
|
-
decrypt: () => decrypt7,
|
|
2619
2690
|
encrypt: () => encrypt7,
|
|
2620
|
-
|
|
2691
|
+
tryDecrypt: () => tryDecrypt5,
|
|
2692
|
+
tryExtract: () => tryExtract2
|
|
2621
2693
|
});
|
|
2622
2694
|
var import_ts_sdk14 = require("@aptos-labs/ts-sdk");
|
|
2623
2695
|
var import_utils19 = require("@noble/hashes/utils");
|
|
@@ -3468,21 +3540,29 @@ function encrypt7({ committee, encryptionKey, contractId, domain, plaintext }) {
|
|
|
3468
3540
|
const ibeCiphs = symmKeyShares.map((share, idx) => encrypt4(encryptionKey.ibeMpks[idx], fullDecryptionDomain.toBytes(), share.payload));
|
|
3469
3541
|
return { fullDecryptionDomain, ciphertext: new Ciphertext7(symmCiph, ibeCiphs) };
|
|
3470
3542
|
}
|
|
3471
|
-
function
|
|
3472
|
-
|
|
3473
|
-
|
|
3474
|
-
|
|
3475
|
-
|
|
3476
|
-
|
|
3477
|
-
|
|
3478
|
-
|
|
3479
|
-
|
|
3480
|
-
|
|
3481
|
-
|
|
3482
|
-
|
|
3483
|
-
|
|
3543
|
+
function tryDecrypt5({ decryptionKey, ciphertext }) {
|
|
3544
|
+
const task = (extra) => {
|
|
3545
|
+
extra["numIbeDecryptionKeys"] = decryptionKey.ibeDecryptionKeys.length;
|
|
3546
|
+
extra["numIbeCiphs"] = ciphertext.ibeCiphs.length;
|
|
3547
|
+
if (decryptionKey.ibeDecryptionKeys.length !== ciphertext.ibeCiphs.length) {
|
|
3548
|
+
throw "decryption key share count does not match ciphertext share count";
|
|
3549
|
+
}
|
|
3550
|
+
const unfilteredSymmKeyShares = ciphertext.ibeCiphs.map((ibeCiph, idx) => {
|
|
3551
|
+
if (decryptionKey.ibeDecryptionKeys[idx] == null) return null;
|
|
3552
|
+
const maybeSharePayload = tryDecrypt2(decryptionKey.ibeDecryptionKeys[idx], ibeCiph);
|
|
3553
|
+
if (!maybeSharePayload.isOk) return null;
|
|
3554
|
+
return new Share(idx + 1, maybeSharePayload.okValue);
|
|
3555
|
+
});
|
|
3556
|
+
extra["symmKeySharePresences"] = unfilteredSymmKeyShares.map((share) => share != null);
|
|
3557
|
+
const symmKeyShares = unfilteredSymmKeyShares.filter((share) => share != null);
|
|
3558
|
+
const symmKeyBytes = combine(symmKeyShares);
|
|
3559
|
+
const symmKey = Key2.fromBytes(symmKeyBytes);
|
|
3560
|
+
const symDecResult = tryDecrypt4(symmKey, ciphertext.aesCiph);
|
|
3561
|
+
return symDecResult.unwrapOrThrow("symmetric decryption failed");
|
|
3562
|
+
};
|
|
3563
|
+
return Result.capture({ task, recordsExecutionTimeMs: true });
|
|
3484
3564
|
}
|
|
3485
|
-
async function
|
|
3565
|
+
async function tryExtract2({ ibeMsk, committee, contractId, domain, proof }) {
|
|
3486
3566
|
const task = async (extra) => {
|
|
3487
3567
|
extra["contractIdScheme"] = contractId.scheme;
|
|
3488
3568
|
extra["proofScheme"] = proof.scheme;
|
|
@@ -4603,6 +4683,7 @@ var RequestForDecryptionKey2 = class _RequestForDecryptionKey {
|
|
|
4603
4683
|
Enc,
|
|
4604
4684
|
Group,
|
|
4605
4685
|
IBE,
|
|
4686
|
+
Result,
|
|
4606
4687
|
Sig,
|
|
4607
4688
|
SilentSetupEncryption,
|
|
4608
4689
|
SilentSetupEncryptionXChain,
|