@inco/js 0.1.21 → 0.1.23

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.
@@ -0,0 +1,99 @@
1
+ import { Account, Chain, Transport, WalletClient } from 'viem';
2
+ import { HexString } from '../binary';
3
+ import { EciesScheme } from '../encryption';
4
+ import { lightningDeployments } from '../generated/lightning';
5
+ import { LocalNodeEnv } from '../local';
6
+ import type { Reencryptor } from '../reencryption';
7
+ type TupleToUnion<T> = T extends readonly unknown[] ? T[number] : never;
8
+ type ToBigInt<T extends string> = T extends `${infer N extends bigint}` ? N : never;
9
+ type ValuesToBigInt<T> = {
10
+ [K in keyof T]: T[K] extends string ? ToBigInt<T[K]> : never;
11
+ };
12
+ type DistributedToBigInt<T, K> = T extends infer U ? K extends keyof U ? Omit<U, K> & (ValuesToBigInt<Pick<U, K>> | Pick<U, K>) : never : never;
13
+ type Deployment = TupleToUnion<typeof lightningDeployments>;
14
+ type DeploymentWithBigIntChainId = DistributedToBigInt<Deployment, 'chainId'>;
15
+ type DistributedPick<T, K> = T extends any ? Pick<T, Extract<keyof T, K>> : never;
16
+ export type DeploymentByName = DistributedPick<DeploymentWithBigIntChainId, 'name' | 'chainId'>;
17
+ export type DeploymentByExecutor = DistributedPick<DeploymentWithBigIntChainId, 'executorAddress' | 'chainId'>;
18
+ export type DeploymentId = DeploymentByName | DeploymentByExecutor;
19
+ export type Pepper = Deployment['pepper'];
20
+ export type ChainId = ToBigInt<Deployment['chainId']>;
21
+ export type SupportedNativeType = boolean | bigint | number;
22
+ export type EncryptionContext = {
23
+ accountAddress: string;
24
+ dappAddress: string;
25
+ };
26
+ export type DeploymentSlice = {
27
+ executorAddress: string;
28
+ eciesPublicKey: string;
29
+ chainId: string;
30
+ };
31
+ /**
32
+ * The Lightning class provides a convenient way to interact with the Inco Lightning contract by binding to a specific
33
+ * deployment.
34
+ */
35
+ export declare class Lightning<T extends DeploymentSlice> {
36
+ private readonly _deployment;
37
+ readonly covalidatorUrl: string;
38
+ private readonly encryptor;
39
+ private readonly ephemeralKeypair;
40
+ private readonly kmsClient;
41
+ constructor(_deployment: T, covalidatorUrl: string);
42
+ /**
43
+ * Get a Lightning deployment by name or executor address on a particular chain.
44
+ *
45
+ * @param id this is an object containing either the pair of name and chainId or the executorAddress and chainId
46
+ */
47
+ static at(id: DeploymentId): Lightning<Deployment>;
48
+ static local({ EXECUTOR_ADDRESS, ECIES_PUBLIC_KEY }: LocalNodeEnv, { chainId, covalidatorUrl }: {
49
+ chainId: bigint;
50
+ covalidatorUrl: string;
51
+ }): Lightning<DeploymentSlice>;
52
+ /**
53
+ * Get the latest deployment for a given pepper, which usually denotes a family of deployments distinct from their
54
+ * version such as 'devnet', 'testnet', 'mainnet', etc.
55
+ *
56
+ * @param pepper the pepper to use to filter the deployments
57
+ * @param chainId the chainId to use to filter the deployments
58
+ */
59
+ static latestDeployment<P extends Pepper>(pepper: P, chainId: ChainId): Deployment;
60
+ /**
61
+ * Get the latest Lightning deployment for a given pepper amd chainId unconditionally.
62
+ * Note that if you upgrade the library the latest deployment may change and contracts deployed to a previous version
63
+ * will not be compatible with the new version.
64
+ *
65
+ * @param pepper the pepper to use to filter the deployments
66
+ * @param chainId the chainId to use to filter the deployments
67
+ */
68
+ static latest<P extends Pepper>(pepper: P, chainId: ChainId): Lightning<Deployment>;
69
+ get deployment(): T;
70
+ /**
71
+ * Get the chainId of the deployment to which this Lightning instance is bound.
72
+ */
73
+ get chainId(): bigint;
74
+ /**
75
+ * Encrypt a value using the public ECIES key of the Lightning deployment.
76
+ *
77
+ * @param value a boolean or numeric value to encrypt
78
+ * @param accountAddress the address of the account interacting with the dapp contract, normally an Externally Owned Account (EOA)
79
+ * @param dappAddress the address of the dapp contract that interacts with the Inco Lightning contract or library
80
+ */
81
+ encrypt<T extends SupportedNativeType>(value: T, { accountAddress, dappAddress }: EncryptionContext): Promise<HexString>;
82
+ /**
83
+ * Obtain a reencryptor for a particular Externally Owned Account (EOA) to request decrypted values.
84
+ * The account associated with the walletClient must have permissions to decrypt the handle or ciphertext passed
85
+ * to the reencryptor function.
86
+ *
87
+ * @param walletClient the wallet client to use for signing the reencrypt request.
88
+ */
89
+ getReencryptor(walletClient: WalletClient<Transport, Chain, Account>): Promise<Reencryptor<EciesScheme>>;
90
+ /**
91
+ * Get the GRPC endpoint for the covalidator that services this deployment.
92
+ */
93
+ static getCovalidatorUrl(deployment: DeploymentSlice & {
94
+ pepper: string;
95
+ }): string;
96
+ private static isIdByName;
97
+ private static plaintextFromValue;
98
+ }
99
+ export {};