@cofhe/sdk 0.6.1 → 0.7.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/CHANGELOG.md +43 -0
- package/acps/acp.ts +411 -0
- package/acps/index.ts +70 -0
- package/{permits → acps}/onchain-utils.ts +49 -24
- package/acps/sealing.ts +90 -0
- package/acps/signature.ts +89 -0
- package/acps/store.ts +172 -0
- package/acps/test/acp.test.ts +615 -0
- package/acps/test/localstorage.test.ts +105 -0
- package/acps/test/sealing.test.ts +77 -0
- package/acps/test/store.test.ts +88 -0
- package/acps/test/validation.test.ts +361 -0
- package/acps/test-utils.ts +32 -0
- package/acps/types.ts +252 -0
- package/acps/validation.ts +392 -0
- package/adapters/test/ethers5.test.ts +4 -1
- package/adapters/test/ethers6.test.ts +4 -1
- package/adapters/test/wagmi.test.ts +5 -2
- package/chains/chains/stagingCofhe.ts +21 -0
- package/chains/index.ts +3 -1
- package/chains/test/chains.test.ts +2 -1
- package/core/acps.ts +625 -0
- package/core/client.ts +136 -39
- package/core/clientTypes.ts +52 -41
- package/core/config.ts +66 -5
- package/core/decrypt/MockThresholdNetworkAbi.ts +20 -11
- package/core/decrypt/apiError.ts +104 -0
- package/core/decrypt/cofheMocksDecryptForTx.ts +11 -11
- package/core/decrypt/cofheMocksDecryptForView.ts +7 -7
- package/core/decrypt/decryptForTxBuilder.ts +102 -102
- package/core/decrypt/decryptForViewBuilder.ts +90 -90
- package/core/decrypt/submitRetry.ts +38 -30
- package/core/decrypt/tnDecryptV1.ts +5 -5
- package/core/decrypt/tnDecryptV2.ts +25 -21
- package/core/decrypt/tnSealOutputV1.ts +4 -3
- package/core/decrypt/tnSealOutputV2.ts +24 -18
- package/core/encrypt/cofheMocksZkVerifySign.ts +59 -74
- package/core/encrypt/encryptInputsBuilder.ts +86 -52
- package/core/encrypt/zkPackProveVerify.ts +25 -18
- package/core/error.ts +34 -6
- package/core/index.ts +4 -14
- package/core/test/acpDefaults.test.ts +52 -0
- package/core/test/acps.test.ts +596 -0
- package/core/test/apiError.test.ts +130 -0
- package/core/test/client.test.ts +22 -19
- package/core/test/config.test.ts +25 -5
- package/core/test/decrypt.test.ts +40 -35
- package/core/test/decryptBuilders.test.ts +68 -68
- package/core/test/decryptErrorCodes.test.ts +217 -0
- package/core/test/encryptInputsBuilder.test.ts +72 -41
- package/core/test/pollCallbacks.test.ts +89 -18
- package/core/test/stagingRedirect.ts +18 -0
- package/core/test/submitRetry.test.ts +182 -0
- package/core/types.ts +9 -69
- package/dist/acp-Wi6isVQI.d.cts +407 -0
- package/dist/acp-Wi6isVQI.d.ts +407 -0
- package/dist/acps.cjs +1081 -0
- package/dist/acps.d.cts +480 -0
- package/dist/acps.d.ts +480 -0
- package/dist/acps.js +2 -0
- package/dist/chains.cjs +14 -1
- package/dist/chains.d.cts +30 -1
- package/dist/chains.d.ts +30 -1
- package/dist/chains.js +1 -1
- package/dist/{chunk-NOC3PYB7.js → chunk-43USWPEH.js} +930 -580
- package/dist/{chunk-MTRAXQXC.js → chunk-N6IDQRRU.js} +14 -2
- package/dist/chunk-Q7CBWGQX.js +1029 -0
- package/dist/{clientTypes-CyUvRRzA.d.ts → clientTypes-BN3nbzYM.d.ts} +342 -165
- package/dist/{clientTypes-BDy1qIBu.d.cts → clientTypes-CYZjFznO.d.cts} +342 -165
- package/dist/core.cjs +1358 -1002
- package/dist/core.d.cts +31 -9
- package/dist/core.d.ts +31 -9
- package/dist/core.js +3 -3
- package/dist/node.cjs +1293 -952
- package/dist/node.d.cts +2 -2
- package/dist/node.d.ts +2 -2
- package/dist/node.js +3 -3
- package/dist/web.cjs +1293 -952
- package/dist/web.d.cts +2 -2
- package/dist/web.d.ts +2 -2
- package/dist/web.js +3 -3
- package/node/test/inherited.test.ts +75 -65
- package/node/test/tfheinit.test.ts +23 -8
- package/package.json +6 -6
- package/web/test/client.web.test.ts +5 -1
- package/web/test/inherited.web.test.ts +75 -65
- package/web/test/tfheinit.web.test.ts +14 -5
- package/web/test/worker.config.web.test.ts +38 -23
- package/web/test/worker.output.web.test.ts +25 -24
- package/core/encrypt/encryptUtils.ts +0 -67
- package/core/permits.ts +0 -216
- package/core/test/permits.test.ts +0 -596
- package/dist/chunk-VB62WYPL.js +0 -978
- package/dist/permit-DnVMDT5h.d.cts +0 -376
- package/dist/permit-DnVMDT5h.d.ts +0 -376
- package/dist/permits.cjs +0 -1026
- package/dist/permits.d.cts +0 -353
- package/dist/permits.d.ts +0 -353
- package/dist/permits.js +0 -2
- package/permits/index.ts +0 -68
- package/permits/permit.ts +0 -385
- package/permits/sealing.ts +0 -131
- package/permits/signature.ts +0 -79
- package/permits/store.ts +0 -157
- package/permits/test/localstorage.test.ts +0 -113
- package/permits/test/permit.test.ts +0 -557
- package/permits/test/sealing.test.ts +0 -84
- package/permits/test/store.test.ts +0 -88
- package/permits/test/validation.test.ts +0 -361
- package/permits/test-utils.ts +0 -28
- package/permits/types.ts +0 -204
- package/permits/validation.ts +0 -327
- /package/{permits → acps}/utils.ts +0 -0
package/core/error.ts
CHANGED
|
@@ -9,12 +9,13 @@ export enum CofheErrorCode {
|
|
|
9
9
|
MissingWalletClient = 'MISSING_WALLET_CLIENT',
|
|
10
10
|
MissingProviderParam = 'MISSING_PROVIDER_PARAM',
|
|
11
11
|
EmptySecurityZonesParam = 'EMPTY_SECURITY_ZONES_PARAM',
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
12
|
+
InvalidACPData = 'INVALID_ACP_DATA',
|
|
13
|
+
InvalidACPDomain = 'INVALID_ACP_DOMAIN',
|
|
14
|
+
ACPNotFound = 'ACP_NOT_FOUND',
|
|
15
|
+
CannotRemoveLastACP = 'CANNOT_REMOVE_LAST_ACP',
|
|
16
16
|
AccountUninitialized = 'ACCOUNT_UNINITIALIZED',
|
|
17
17
|
ChainIdUninitialized = 'CHAIN_ID_UNINITIALIZED',
|
|
18
|
+
ConsumingContractUninitialized = 'CONSUMING_CONTRACT_UNINITIALIZED',
|
|
18
19
|
SealOutputFailed = 'SEAL_OUTPUT_FAILED',
|
|
19
20
|
SealOutputReturnedNull = 'SEAL_OUTPUT_RETURNED_NULL',
|
|
20
21
|
InvalidUtype = 'INVALID_UTYPE',
|
|
@@ -42,6 +43,26 @@ export enum CofheErrorCode {
|
|
|
42
43
|
PublicWalletGetChainIdFailed = 'PUBLIC_WALLET_GET_CHAIN_ID_FAILED',
|
|
43
44
|
PublicWalletGetAddressesFailed = 'PUBLIC_WALLET_GET_ADDRESSES_FAILED',
|
|
44
45
|
RehydrateKeysStoreFailed = 'REHYDRATE_KEYS_STORE_FAILED',
|
|
46
|
+
|
|
47
|
+
// Threshold-network stable error codes (decrypt/sealoutput), see API-RESPONSES.md
|
|
48
|
+
BadRequest = 'BAD_REQUEST',
|
|
49
|
+
UnknownChain = 'UNKNOWN_CHAIN',
|
|
50
|
+
ACPMalformed = 'ACP_MALFORMED',
|
|
51
|
+
ACPDenied = 'ACP_DENIED',
|
|
52
|
+
ACPExpired = 'ACP_EXPIRED',
|
|
53
|
+
ACPInvalid = 'ACP_INVALID',
|
|
54
|
+
ACPRevoked = 'ACP_REVOKED',
|
|
55
|
+
NotPubliclyAllowed = 'NOT_PUBLICLY_ALLOWED',
|
|
56
|
+
CtNotFound = 'CT_NOT_FOUND',
|
|
57
|
+
UnsupportedSecurityZone = 'UNSUPPORTED_SECURITY_ZONE',
|
|
58
|
+
UnsupportedType = 'UNSUPPORTED_TYPE',
|
|
59
|
+
SigningFailed = 'SIGNING_FAILED',
|
|
60
|
+
CtSourceError = 'CT_SOURCE_ERROR',
|
|
61
|
+
ACPVerifierError = 'ACP_VERIFIER_ERROR',
|
|
62
|
+
CtSourceTimeout = 'CT_SOURCE_TIMEOUT',
|
|
63
|
+
ACPVerifierTimeout = 'ACP_VERIFIER_TIMEOUT',
|
|
64
|
+
ACPRequired = 'ACP_REQUIRED',
|
|
65
|
+
SealFailed = 'SEAL_FAILED',
|
|
45
66
|
}
|
|
46
67
|
|
|
47
68
|
export type CofheErrorParams = {
|
|
@@ -50,6 +71,8 @@ export type CofheErrorParams = {
|
|
|
50
71
|
cause?: Error;
|
|
51
72
|
hint?: string;
|
|
52
73
|
context?: Record<string, unknown>;
|
|
74
|
+
/** Raw backend `error` string, when this error originated from a threshold-network response. */
|
|
75
|
+
apiErrorCode?: string;
|
|
53
76
|
};
|
|
54
77
|
|
|
55
78
|
/**
|
|
@@ -68,8 +91,9 @@ export class CofheError extends Error {
|
|
|
68
91
|
public readonly cause?: Error;
|
|
69
92
|
public readonly hint?: string;
|
|
70
93
|
public readonly context?: Record<string, unknown>;
|
|
94
|
+
public readonly apiErrorCode?: string;
|
|
71
95
|
|
|
72
|
-
constructor({ code, message, cause, hint, context }: CofheErrorParams) {
|
|
96
|
+
constructor({ code, message, cause, hint, context, apiErrorCode }: CofheErrorParams) {
|
|
73
97
|
// If there's a cause, append its message to provide full context
|
|
74
98
|
const fullMessage = cause ? `${message} | Caused by: ${cause.message}` : message;
|
|
75
99
|
|
|
@@ -79,6 +103,7 @@ export class CofheError extends Error {
|
|
|
79
103
|
this.cause = cause;
|
|
80
104
|
this.hint = hint;
|
|
81
105
|
this.context = context;
|
|
106
|
+
this.apiErrorCode = apiErrorCode;
|
|
82
107
|
|
|
83
108
|
// Maintains proper stack trace for where our error was thrown (only available on V8)
|
|
84
109
|
if (Error.captureStackTrace) {
|
|
@@ -101,6 +126,7 @@ export class CofheError extends Error {
|
|
|
101
126
|
message: wrapperError?.message ?? 'An internal error occurred',
|
|
102
127
|
hint: wrapperError?.hint,
|
|
103
128
|
context: wrapperError?.context,
|
|
129
|
+
apiErrorCode: wrapperError?.apiErrorCode,
|
|
104
130
|
cause: cause,
|
|
105
131
|
});
|
|
106
132
|
}
|
|
@@ -115,6 +141,7 @@ export class CofheError extends Error {
|
|
|
115
141
|
message: this.message,
|
|
116
142
|
hint: this.hint,
|
|
117
143
|
context: this.context,
|
|
144
|
+
apiErrorCode: this.apiErrorCode,
|
|
118
145
|
cause: this.cause
|
|
119
146
|
? {
|
|
120
147
|
name: this.cause.name,
|
|
@@ -130,7 +157,8 @@ export class CofheError extends Error {
|
|
|
130
157
|
* Returns a human-readable string representation of the error
|
|
131
158
|
*/
|
|
132
159
|
toString(): string {
|
|
133
|
-
const
|
|
160
|
+
const codeSuffix = this.apiErrorCode ? ` (api: ${this.apiErrorCode})` : '';
|
|
161
|
+
const parts = [`${this.name} [${this.code}]${codeSuffix}: ${this.message}`];
|
|
134
162
|
|
|
135
163
|
if (this.hint) {
|
|
136
164
|
parts.push(`Hint: ${this.hint}`);
|
package/core/index.ts
CHANGED
|
@@ -12,7 +12,7 @@ export type {
|
|
|
12
12
|
} from './debug.js';
|
|
13
13
|
|
|
14
14
|
// Configuration (base implementations)
|
|
15
|
-
export { createCofheConfigBase, getCofheConfigItem } from './config.js';
|
|
15
|
+
export { createCofheConfigBase, getCofheConfigItem, assertNoRenamedConfigKeys } from './config.js';
|
|
16
16
|
export type { CofheConfig, CofheInputConfig, CofheInternalConfig } from './config.js';
|
|
17
17
|
|
|
18
18
|
// Types
|
|
@@ -21,7 +21,7 @@ export type {
|
|
|
21
21
|
CofheClient as CofheClient,
|
|
22
22
|
CofheClientParams as CofheClientParams,
|
|
23
23
|
CofheClientConnectionState as CofheClientConnectionState,
|
|
24
|
-
|
|
24
|
+
CofheClientACPs as CofheClientACPs,
|
|
25
25
|
} from './clientTypes.js';
|
|
26
26
|
|
|
27
27
|
export type {
|
|
@@ -40,18 +40,8 @@ export type {
|
|
|
40
40
|
EncryptableAddress,
|
|
41
41
|
// Encrypted types
|
|
42
42
|
EncryptedNumber,
|
|
43
|
-
EncryptedItemInput,
|
|
44
|
-
EncryptedBoolInput,
|
|
45
|
-
EncryptedUint8Input,
|
|
46
|
-
EncryptedUint16Input,
|
|
47
|
-
EncryptedUint32Input,
|
|
48
|
-
EncryptedUint64Input,
|
|
49
|
-
EncryptedUint128Input,
|
|
50
|
-
EncryptedAddressInput,
|
|
51
|
-
EncryptedItemInputs,
|
|
52
|
-
EncryptableToEncryptedItemInputMap,
|
|
53
43
|
FheTypeValue,
|
|
54
|
-
//
|
|
44
|
+
// Batch-verified external hash + signature types
|
|
55
45
|
ExternalBoolHash,
|
|
56
46
|
ExternalUint8Hash,
|
|
57
47
|
ExternalUint16Hash,
|
|
@@ -81,7 +71,6 @@ export {
|
|
|
81
71
|
isEncryptableItem,
|
|
82
72
|
EncryptStep,
|
|
83
73
|
isLastEncryptionStep,
|
|
84
|
-
assertCorrectEncryptedItemInput,
|
|
85
74
|
} from './types.js';
|
|
86
75
|
|
|
87
76
|
// Error handling
|
|
@@ -98,6 +87,7 @@ export type { KeysStorage, KeysStore } from './keyStore.js';
|
|
|
98
87
|
|
|
99
88
|
// Builders (exported via client, but can be imported directly for typing)
|
|
100
89
|
export { EncryptInputsBuilder } from './encrypt/encryptInputsBuilder.js';
|
|
90
|
+
export type { EncryptInputsBuilderUnset } from './encrypt/encryptInputsBuilder.js';
|
|
101
91
|
export { DecryptForViewBuilder } from './decrypt/decryptForViewBuilder.js';
|
|
102
92
|
export { DecryptForTxBuilder } from './decrypt/decryptForTxBuilder.js';
|
|
103
93
|
export type { DecryptForTxResult } from './decrypt/decryptForTxBuilder.js';
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import { describe, it, expect } from 'vitest';
|
|
2
|
+
import { acps } from '../acps.js';
|
|
3
|
+
|
|
4
|
+
type ScopeOpts = {
|
|
5
|
+
revokerData?: number;
|
|
6
|
+
revokerContract?: string;
|
|
7
|
+
scope?: number;
|
|
8
|
+
contracts?: string[];
|
|
9
|
+
handles?: bigint[];
|
|
10
|
+
};
|
|
11
|
+
const opts = (o: ScopeOpts): ScopeOpts => o;
|
|
12
|
+
|
|
13
|
+
const CHAIN = 31337;
|
|
14
|
+
const REVOKER = '0x00000000000000000000000000000000000000aa' as `0x${string}`;
|
|
15
|
+
const CONTRACT_A = '0x00000000000000000000000000000000000000bb' as `0x${string}`;
|
|
16
|
+
|
|
17
|
+
const acpConfig = {
|
|
18
|
+
defaultRevoker: { [CHAIN]: REVOKER },
|
|
19
|
+
defaultContractScopes: { [CHAIN]: [CONTRACT_A] },
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
describe('applyACPDefaults', () => {
|
|
23
|
+
it('injects default revoker (contract + creation timestamp) when no revoker options given', () => {
|
|
24
|
+
const before = Math.round(Date.now() / 1000);
|
|
25
|
+
const result = acps.applyACPDefaults(opts({}), acpConfig, CHAIN);
|
|
26
|
+
expect(result.revokerContract).toBe(REVOKER);
|
|
27
|
+
expect(result.revokerData).toBeGreaterThanOrEqual(before - 60); // 60s clock-skew backdating
|
|
28
|
+
expect(result.revokerData).toBeLessThanOrEqual(Math.round(Date.now() / 1000) - 59);
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
it('does not override an explicit revoker pair', () => {
|
|
32
|
+
const result = acps.applyACPDefaults({ revokerData: 42, revokerContract: CONTRACT_A }, acpConfig, CHAIN);
|
|
33
|
+
expect(result.revokerData).toBe(42);
|
|
34
|
+
expect(result.revokerContract).toBe(CONTRACT_A);
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
it('injects default contract scopes when no scope options given', () => {
|
|
38
|
+
const result = acps.applyACPDefaults(opts({}), acpConfig, CHAIN);
|
|
39
|
+
expect(result.contracts).toEqual([CONTRACT_A]);
|
|
40
|
+
});
|
|
41
|
+
|
|
42
|
+
it('does not inject scopes when the caller provides any scope option (incl. explicit scope)', () => {
|
|
43
|
+
expect(acps.applyACPDefaults(opts({ scope: 0 }), acpConfig, CHAIN).contracts).toBeUndefined();
|
|
44
|
+
expect(acps.applyACPDefaults(opts({ handles: [1n] }), acpConfig, CHAIN).contracts).toBeUndefined();
|
|
45
|
+
expect(acps.applyACPDefaults(opts({ contracts: [] }), acpConfig, CHAIN).contracts).toEqual([]);
|
|
46
|
+
});
|
|
47
|
+
|
|
48
|
+
it('no-op for chains without defaults and for missing config', () => {
|
|
49
|
+
expect(acps.applyACPDefaults(opts({}), acpConfig, 999)).toEqual({});
|
|
50
|
+
expect(acps.applyACPDefaults(opts({}), undefined, CHAIN)).toEqual({});
|
|
51
|
+
});
|
|
52
|
+
});
|