@interfold/sdk 0.2.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/LICENSE.md +134 -0
- package/README.md +478 -0
- package/dist/contracts/index.cjs +320 -0
- package/dist/contracts/index.cjs.map +1 -0
- package/dist/contracts/index.d.ts +34 -0
- package/dist/contracts/index.js +296 -0
- package/dist/contracts/index.js.map +1 -0
- package/dist/crypto/index.cjs +1932 -0
- package/dist/crypto/index.cjs.map +1 -0
- package/dist/crypto/index.d.ts +59 -0
- package/dist/crypto/index.js +1892 -0
- package/dist/crypto/index.js.map +1 -0
- package/dist/events/index.cjs +270 -0
- package/dist/events/index.cjs.map +1 -0
- package/dist/events/index.d.ts +195 -0
- package/dist/events/index.js +241 -0
- package/dist/events/index.js.map +1 -0
- package/dist/index.cjs +2750 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.ts +136 -0
- package/dist/index.js +2694 -0
- package/dist/index.js.map +1 -0
- package/dist/types-C9WZ1Khd.d.ts +64 -0
- package/package.json +73 -0
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,136 @@
|
|
|
1
|
+
import { PublicClient, WalletClient, Chain, Hash, Abi, Log, Address } from 'viem';
|
|
2
|
+
import { C as ContractAddresses, E as E3, a as E3RequestParams, F as FailureReason, b as E3Stage } from './types-C9WZ1Khd.js';
|
|
3
|
+
export { c as CommitteeSize } from './types-C9WZ1Khd.js';
|
|
4
|
+
import { ThresholdBfvParamsPresetName, BfvParams, EncryptedValueAndPublicInputs, VerifiableEncryptionResult } from './crypto/index.js';
|
|
5
|
+
export { ThresholdBfvParamsPresetNames, computePublicKeyCommitment, encryptNumber, encryptNumberAndGenInputs, encryptNumberAndGenProof, encryptVector, encryptVectorAndGenInputs, encryptVectorAndGenProof, generateProof, generatePublicKey, getThresholdBfvParamsSet } from './crypto/index.js';
|
|
6
|
+
import { AllEventTypes, EventCallback } from './events/index.js';
|
|
7
|
+
export { CiphernodeAddedData, CiphernodeRemovedData, CiphertextOutputPublishedData, CommitteeFinalizedData, CommitteePublishedData, CommitteeRequestedData, E3ActivatedData, E3RequestedData, EventFilter, EventListener, EventListenerConfig, EventListenerOptions, InterfoldEvent, InterfoldEventData, InterfoldEventType, PlaintextOutputPublishedData, RegistryEventData, RegistryEventType, SDKEventEmitter } from './events/index.js';
|
|
8
|
+
export { ContractClient, ContractClientConfig } from './contracts/index.js';
|
|
9
|
+
import '@aztec/bb.js';
|
|
10
|
+
|
|
11
|
+
interface SDKConfig {
|
|
12
|
+
publicClient: PublicClient;
|
|
13
|
+
walletClient?: WalletClient;
|
|
14
|
+
contracts: ContractAddresses;
|
|
15
|
+
chain?: Chain;
|
|
16
|
+
thresholdBfvParamsPresetName?: ThresholdBfvParamsPresetName;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
declare class InterfoldSDK {
|
|
20
|
+
private config;
|
|
21
|
+
private eventListener;
|
|
22
|
+
private contractClient;
|
|
23
|
+
private thresholdBfvParamsPresetName;
|
|
24
|
+
private publicClient;
|
|
25
|
+
constructor(config: SDKConfig);
|
|
26
|
+
getPublicClient(): PublicClient;
|
|
27
|
+
getThresholdBfvParamsSet(): Promise<BfvParams>;
|
|
28
|
+
generatePublicKey(): Promise<Uint8Array>;
|
|
29
|
+
computePublicKeyCommitment(publicKey: Uint8Array): Promise<Uint8Array>;
|
|
30
|
+
encryptNumber(data: bigint, publicKey: Uint8Array): Promise<Uint8Array>;
|
|
31
|
+
encryptVector(data: BigUint64Array, publicKey: Uint8Array): Promise<Uint8Array>;
|
|
32
|
+
encryptNumberAndGenInputs(data: bigint, publicKey: Uint8Array): Promise<EncryptedValueAndPublicInputs>;
|
|
33
|
+
encryptNumberAndGenProof(data: bigint, publicKey: Uint8Array): Promise<VerifiableEncryptionResult>;
|
|
34
|
+
encryptVectorAndGenInputs(data: BigUint64Array, publicKey: Uint8Array): Promise<EncryptedValueAndPublicInputs>;
|
|
35
|
+
encryptVectorAndGenProof(data: BigUint64Array, publicKey: Uint8Array): Promise<VerifiableEncryptionResult>;
|
|
36
|
+
approveFeeToken(amount: bigint): Promise<Hash>;
|
|
37
|
+
requestE3(params: {
|
|
38
|
+
committeeSize: number;
|
|
39
|
+
inputWindow: [bigint, bigint];
|
|
40
|
+
e3Program: `0x${string}`;
|
|
41
|
+
paramSet: number;
|
|
42
|
+
computeProviderParams: `0x${string}`;
|
|
43
|
+
customParams?: `0x${string}`;
|
|
44
|
+
proofAggregationEnabled?: boolean;
|
|
45
|
+
gasLimit?: bigint;
|
|
46
|
+
}): Promise<Hash>;
|
|
47
|
+
getE3PublicKey(e3Id: bigint): Promise<`0x${string}`>;
|
|
48
|
+
publishCiphertextOutput(e3Id: bigint, ciphertextOutput: `0x${string}`, proof: `0x${string}`, gasLimit?: bigint): Promise<Hash>;
|
|
49
|
+
getE3(e3Id: bigint): Promise<E3>;
|
|
50
|
+
getE3Quote(params: E3RequestParams): Promise<bigint>;
|
|
51
|
+
getFailureReason(e3Id: bigint): Promise<FailureReason>;
|
|
52
|
+
getE3Stage(e3Id: bigint): Promise<E3Stage>;
|
|
53
|
+
estimateGas(functionName: string, args: readonly unknown[], contractAddress: `0x${string}`, abi: Abi, value?: bigint): Promise<bigint>;
|
|
54
|
+
waitForTransaction(hash: Hash): Promise<unknown>;
|
|
55
|
+
onInterfoldEvent<T extends AllEventTypes>(eventType: T, callback: EventCallback<T>): Promise<void>;
|
|
56
|
+
off<T extends AllEventTypes>(eventType: T, callback: EventCallback<T>): void;
|
|
57
|
+
once<T extends AllEventTypes>(type: T, callback: EventCallback<T>): Promise<void>;
|
|
58
|
+
getHistoricalEvents(eventType: AllEventTypes, fromBlock?: bigint, toBlock?: bigint): Promise<Log[]>;
|
|
59
|
+
startEventPolling(): Promise<void>;
|
|
60
|
+
stopEventPolling(): void;
|
|
61
|
+
cleanup(): void;
|
|
62
|
+
static create(options: {
|
|
63
|
+
rpcUrl: string;
|
|
64
|
+
contracts: {
|
|
65
|
+
interfold: `0x${string}`;
|
|
66
|
+
ciphernodeRegistry: `0x${string}`;
|
|
67
|
+
feeToken: `0x${string}`;
|
|
68
|
+
};
|
|
69
|
+
privateKey?: `0x${string}`;
|
|
70
|
+
chain: Chain;
|
|
71
|
+
thresholdBfvParamsPresetName?: ThresholdBfvParamsPresetName;
|
|
72
|
+
}): InterfoldSDK;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
declare const DEFAULT_THRESHOLD_BFV_PARAMS_PRESET_NAME: ThresholdBfvParamsPresetName;
|
|
76
|
+
|
|
77
|
+
declare class SDKError extends Error {
|
|
78
|
+
readonly code?: string | undefined;
|
|
79
|
+
constructor(message: string, code?: string | undefined);
|
|
80
|
+
}
|
|
81
|
+
declare function isValidAddress(address: string): address is Address;
|
|
82
|
+
declare function isValidHash(hash: string): hash is Hash;
|
|
83
|
+
declare function formatEventName(contractName: string, eventName: string): string;
|
|
84
|
+
declare function parseEventData<T>(log: Log): T;
|
|
85
|
+
/**
|
|
86
|
+
* Sleep for a specified number of milliseconds
|
|
87
|
+
*/
|
|
88
|
+
declare const sleep: (ms: number) => Promise<void>;
|
|
89
|
+
declare function formatBigInt(value: bigint): string;
|
|
90
|
+
declare function parseBigInt(value: string): bigint;
|
|
91
|
+
declare function generateEventId(log: Log): string;
|
|
92
|
+
/**
|
|
93
|
+
* Get the current timestamp in seconds
|
|
94
|
+
* from onchain
|
|
95
|
+
* @param publicClient - The public client to use
|
|
96
|
+
*/
|
|
97
|
+
declare function getCurrentTimestamp(publicClient: PublicClient): Promise<bigint>;
|
|
98
|
+
interface ComputeProviderParams {
|
|
99
|
+
name: string;
|
|
100
|
+
parallel: boolean;
|
|
101
|
+
batch_size: number;
|
|
102
|
+
}
|
|
103
|
+
declare const DEFAULT_COMPUTE_PROVIDER_PARAMS: ComputeProviderParams;
|
|
104
|
+
declare const DEFAULT_E3_CONFIG: {
|
|
105
|
+
readonly committeeSize: 0;
|
|
106
|
+
readonly duration: 1800;
|
|
107
|
+
readonly payment_amount: "0";
|
|
108
|
+
};
|
|
109
|
+
/**
|
|
110
|
+
* Encode BFV parameters for the smart contract
|
|
111
|
+
* BFV (Brakerski-Fan-Vercauteren) is a type of fully homomorphic encryption
|
|
112
|
+
*/
|
|
113
|
+
declare function encodeBfvParams(params: BfvParams): `0x${string}`;
|
|
114
|
+
/**
|
|
115
|
+
* Encode compute provider parameters for the smart contract'
|
|
116
|
+
* If mock is true, the compute provider parameters will return 32 bytes of 0x00
|
|
117
|
+
*/
|
|
118
|
+
declare function encodeComputeProviderParams(params: ComputeProviderParams, mock?: boolean): `0x${string}`;
|
|
119
|
+
/**
|
|
120
|
+
* Encode custom parameters for the smart contract.
|
|
121
|
+
*/
|
|
122
|
+
declare function encodeCustomParams(params: Record<string, unknown>): `0x${string}`;
|
|
123
|
+
/**
|
|
124
|
+
* Calculate start window for E3 request
|
|
125
|
+
* @dev This function can be used for testing purposes, or for E3s which need to start as soon as possible.
|
|
126
|
+
* @param publicClient - The public client to use
|
|
127
|
+
* @param duration - The duration of the input window in seconds
|
|
128
|
+
* @param startBuffer - Buffer in seconds added to current timestamp for input window start
|
|
129
|
+
*/
|
|
130
|
+
declare function calculateInputWindow(publicClient: PublicClient, duration?: number, startBuffer?: bigint): Promise<[bigint, bigint]>;
|
|
131
|
+
/**
|
|
132
|
+
* Decode plaintextOutput bytes to get the actual result number
|
|
133
|
+
*/
|
|
134
|
+
declare function decodePlaintextOutput(plaintextOutput: string): number | null;
|
|
135
|
+
|
|
136
|
+
export { AllEventTypes, BfvParams, type ComputeProviderParams, ContractAddresses, DEFAULT_COMPUTE_PROVIDER_PARAMS, DEFAULT_E3_CONFIG, DEFAULT_THRESHOLD_BFV_PARAMS_PRESET_NAME, E3, E3RequestParams, E3Stage, EncryptedValueAndPublicInputs, EventCallback, FailureReason, InterfoldSDK, type SDKConfig, SDKError, ThresholdBfvParamsPresetName, VerifiableEncryptionResult, calculateInputWindow, decodePlaintextOutput, encodeBfvParams, encodeComputeProviderParams, encodeCustomParams, formatBigInt, formatEventName, generateEventId, getCurrentTimestamp, isValidAddress, isValidHash, parseBigInt, parseEventData, sleep };
|