@inco/js 0.8.0-devnet-11 → 0.8.0-devnet-13
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 +541 -47
- package/dist/cjs/binary.d.ts +84 -0
- package/dist/cjs/binary.js +81 -4
- package/dist/cjs/chain.d.ts +21 -4
- package/dist/cjs/chain.js +18 -7
- package/dist/cjs/encryption/encryption.d.ts +115 -0
- package/dist/cjs/encryption/encryption.js +98 -7
- package/dist/cjs/generated/local-node.d.ts +2 -2
- package/dist/cjs/generated/local-node.js +2 -2
- package/dist/cjs/handle.d.ts +41 -0
- package/dist/cjs/handle.js +31 -6
- package/dist/cjs/lite/lightning.d.ts +19 -0
- package/dist/cjs/lite/lightning.js +20 -5
- package/dist/cjs/local/local-node.d.ts +18 -0
- package/dist/cjs/local/local-node.js +18 -3
- package/dist/cjs/reencryption/eip712.d.ts +27 -0
- package/dist/cjs/reencryption/eip712.js +20 -7
- package/dist/cjs/reencryption/types.d.ts +24 -0
- package/dist/cjs/viem.d.ts +11 -0
- package/dist/cjs/viem.js +12 -1
- package/dist/esm/binary.d.ts +84 -0
- package/dist/esm/binary.js +81 -4
- package/dist/esm/chain.d.ts +21 -4
- package/dist/esm/chain.js +17 -6
- package/dist/esm/encryption/encryption.d.ts +115 -0
- package/dist/esm/encryption/encryption.js +98 -7
- package/dist/esm/generated/local-node.d.ts +2 -2
- package/dist/esm/generated/local-node.js +2 -2
- package/dist/esm/handle.d.ts +41 -0
- package/dist/esm/handle.js +31 -6
- package/dist/esm/lite/lightning.d.ts +19 -0
- package/dist/esm/lite/lightning.js +20 -5
- package/dist/esm/local/local-node.d.ts +18 -0
- package/dist/esm/local/local-node.js +18 -3
- package/dist/esm/reencryption/eip712.d.ts +27 -0
- package/dist/esm/reencryption/eip712.js +20 -7
- package/dist/esm/reencryption/types.d.ts +24 -0
- package/dist/esm/viem.d.ts +11 -0
- package/dist/esm/viem.js +12 -1
- package/dist/types/binary.d.ts +84 -0
- package/dist/types/chain.d.ts +21 -4
- package/dist/types/encryption/encryption.d.ts +115 -0
- package/dist/types/generated/local-node.d.ts +2 -2
- package/dist/types/handle.d.ts +41 -0
- package/dist/types/lite/lightning.d.ts +19 -0
- package/dist/types/local/local-node.d.ts +18 -0
- package/dist/types/reencryption/eip712.d.ts +27 -0
- package/dist/types/reencryption/types.d.ts +24 -0
- package/dist/types/viem.d.ts +11 -0
- package/package.json +1 -7
package/dist/cjs/binary.d.ts
CHANGED
|
@@ -1,22 +1,106 @@
|
|
|
1
1
|
import { Schema } from 'effect';
|
|
2
2
|
import { Hex } from 'viem';
|
|
3
|
+
/** Schema for a `0x`-prefixed hex string. */
|
|
3
4
|
export declare const HexString: Schema.TemplateLiteral<`0x${string}`>;
|
|
5
|
+
/** A `0x`-prefixed hex-encoded string (e.g. `"0xdeadbeef"`). */
|
|
4
6
|
export type HexString = typeof HexString.Type;
|
|
7
|
+
/** A value that can represent raw bytes — either a hex string or a `Uint8Array`. */
|
|
5
8
|
export type BytesIsh = string | Uint8Array;
|
|
9
|
+
/**
|
|
10
|
+
* Converts a `Uint8Array` to a `bigint`. Returns `0n` for empty arrays.
|
|
11
|
+
* @param byteArray - The byte array to convert.
|
|
12
|
+
* @returns The unsigned big-endian integer representation of the bytes.
|
|
13
|
+
*/
|
|
6
14
|
export declare function bytesToBigInt(byteArray: Uint8Array): bigint;
|
|
15
|
+
/**
|
|
16
|
+
* Converts a `Buffer` to a `bigint`.
|
|
17
|
+
* @param buffer - The buffer to convert.
|
|
18
|
+
* @returns The unsigned big-endian integer representation of the buffer.
|
|
19
|
+
*/
|
|
7
20
|
export declare function bufferToBigInt(buffer: Buffer): bigint;
|
|
21
|
+
/**
|
|
22
|
+
* Converts a `bigint` to a 32-byte `Buffer`, zero-padded on the left.
|
|
23
|
+
* @param value - The bigint to convert.
|
|
24
|
+
* @returns A 32-byte big-endian buffer.
|
|
25
|
+
*/
|
|
8
26
|
export declare function bigintToBytes(value: bigint): Buffer;
|
|
27
|
+
/**
|
|
28
|
+
* Converts a `bigint` to a {@link Bytes32} hex string, left-padded to 32 bytes.
|
|
29
|
+
*
|
|
30
|
+
* **Warning:** It is the caller's responsibility to ensure the value fits in
|
|
31
|
+
* 32 bytes. Values that are too large will be silently truncated.
|
|
32
|
+
*
|
|
33
|
+
* @param value - The bigint to convert.
|
|
34
|
+
* @returns A `Bytes32` hex string.
|
|
35
|
+
*/
|
|
9
36
|
export declare function bigintToBytes32(value: bigint): Bytes32;
|
|
37
|
+
/**
|
|
38
|
+
* Left-pads a byte array with zeros to the specified length.
|
|
39
|
+
* @param bs - The byte array to pad.
|
|
40
|
+
* @param n - The desired total length in bytes.
|
|
41
|
+
* @returns A new `Buffer` of length `n` with `bs` right-aligned.
|
|
42
|
+
* @throws If `bs` is longer than `n` (would require truncation).
|
|
43
|
+
*/
|
|
10
44
|
export declare function padLeft(bs: Uint8Array, n: number): Buffer;
|
|
45
|
+
/**
|
|
46
|
+
* Parses a {@link BytesIsh} value as a 32-byte value and converts it to a `bigint`.
|
|
47
|
+
* @param bs - A hex string or `Uint8Array` representing exactly 32 bytes.
|
|
48
|
+
* @returns The `bigint` representation of the 32-byte value.
|
|
49
|
+
* @throws If the input is not exactly 32 bytes.
|
|
50
|
+
*/
|
|
11
51
|
export declare function bytes32ToBigint(bs: BytesIsh): bigint;
|
|
52
|
+
/**
|
|
53
|
+
* Decodes a hex string into a `Buffer`. Handles both `0x`-prefixed and bare hex strings.
|
|
54
|
+
* @param hexString - The hex string to decode.
|
|
55
|
+
* @returns A `Buffer` containing the decoded bytes.
|
|
56
|
+
*/
|
|
12
57
|
export declare function bytesFromHexString(hexString: string): Buffer;
|
|
58
|
+
/**
|
|
59
|
+
* Asserts that a string is a valid `0x`-prefixed hex string and narrows its type to `Hex`.
|
|
60
|
+
* @param value - The string to validate.
|
|
61
|
+
* @returns The input typed as `Hex`.
|
|
62
|
+
* @throws If `value` is not a valid hex string.
|
|
63
|
+
*/
|
|
13
64
|
export declare function mustBeHex(value: string): Hex;
|
|
65
|
+
/**
|
|
66
|
+
* Normalises a string to a `0x`-prefixed `Hex` value, adding the prefix if missing.
|
|
67
|
+
* @param value - A hex string, with or without a `0x` prefix.
|
|
68
|
+
* @returns The `0x`-prefixed `Hex` string.
|
|
69
|
+
* @throws If the resulting string is not valid hex.
|
|
70
|
+
*/
|
|
14
71
|
export declare function normaliseToHex(value: string): Hex;
|
|
72
|
+
/**
|
|
73
|
+
* Encodes a `Uint8Array` as a `0x`-prefixed hex string.
|
|
74
|
+
* @param bs - The byte array to encode.
|
|
75
|
+
* @returns A `Hex` string representation of the bytes.
|
|
76
|
+
*/
|
|
15
77
|
export declare function bytesToHex(bs: Uint8Array): Hex;
|
|
78
|
+
/** Schema for a 32-byte (66-character with `0x` prefix) hex string, branded as `Bytes32`. Accepts both hex strings and `Uint8Array` inputs. */
|
|
16
79
|
export declare const Bytes32: Schema.brand<Schema.filter<Schema.transformOrFail<Schema.Union<[typeof Schema.String, Schema.refine<object & Uint8Array<ArrayBufferLike>, Schema.Schema<object, object, never>>]>, Schema.TemplateLiteral<`0x${string}`>, never>>, "Bytes32">;
|
|
80
|
+
/**
|
|
81
|
+
* Parses and validates a {@link BytesIsh} value as a {@link Bytes32}.
|
|
82
|
+
* @param x - A hex string or `Uint8Array` to parse.
|
|
83
|
+
* @returns A validated `Bytes32` value.
|
|
84
|
+
* @throws If the input is not exactly 32 bytes.
|
|
85
|
+
*/
|
|
17
86
|
export declare function asBytes32(x: BytesIsh): Bytes32;
|
|
87
|
+
/** A branded 32-byte hex string type (`0x` + 64 hex characters). */
|
|
18
88
|
export type Bytes32 = typeof Bytes32.Type;
|
|
89
|
+
/** A branded 20-byte Ethereum address type (`0x` + 40 hex characters). */
|
|
19
90
|
export type Address = typeof Address.Type;
|
|
91
|
+
/** Schema for a 20-byte `0x`-prefixed Ethereum address, branded as `Address`. */
|
|
20
92
|
export declare const Address: Schema.brand<Schema.filter<Schema.TemplateLiteral<`0x${string}`>>, "Address">;
|
|
93
|
+
/**
|
|
94
|
+
* Parses and validates a string as an Ethereum {@link Address} (20-byte, `0x`-prefixed).
|
|
95
|
+
* @param address - The string to parse.
|
|
96
|
+
* @returns A validated `Address` value.
|
|
97
|
+
* @throws If the input is not a valid 20-byte hex address.
|
|
98
|
+
*/
|
|
21
99
|
export declare function parseAddress(address: string): Address;
|
|
100
|
+
/**
|
|
101
|
+
* Parses and validates a string as a {@link HexString} (`0x`-prefixed).
|
|
102
|
+
* @param hex - The string to parse.
|
|
103
|
+
* @returns A validated `HexString` value.
|
|
104
|
+
* @throws If the input is not a valid `0x`-prefixed hex string.
|
|
105
|
+
*/
|
|
22
106
|
export declare function parseHex(hex: string): HexString;
|
package/dist/cjs/binary.js
CHANGED
|
@@ -17,25 +17,54 @@ exports.parseHex = parseHex;
|
|
|
17
17
|
const effect_1 = require("effect");
|
|
18
18
|
const viem_1 = require("viem");
|
|
19
19
|
const schema_js_1 = require("./schema.js");
|
|
20
|
+
/** Schema for a `0x`-prefixed hex string. */
|
|
20
21
|
exports.HexString = effect_1.Schema.TemplateLiteral('0x', effect_1.Schema.String);
|
|
22
|
+
/**
|
|
23
|
+
* Converts a `Uint8Array` to a `bigint`. Returns `0n` for empty arrays.
|
|
24
|
+
* @param byteArray - The byte array to convert.
|
|
25
|
+
* @returns The unsigned big-endian integer representation of the bytes.
|
|
26
|
+
*/
|
|
21
27
|
function bytesToBigInt(byteArray) {
|
|
22
28
|
// Ugly but better than bigint-buffer that insists on writing junk to stderr if it doesn't have native bindings
|
|
23
29
|
return !byteArray?.length
|
|
24
30
|
? BigInt(0)
|
|
25
31
|
: BigInt('0x' + Buffer.from(byteArray).toString('hex'));
|
|
26
32
|
}
|
|
33
|
+
/**
|
|
34
|
+
* Converts a `Buffer` to a `bigint`.
|
|
35
|
+
* @param buffer - The buffer to convert.
|
|
36
|
+
* @returns The unsigned big-endian integer representation of the buffer.
|
|
37
|
+
*/
|
|
27
38
|
function bufferToBigInt(buffer) {
|
|
28
39
|
return bytesToBigInt(Uint8Array.from(buffer));
|
|
29
40
|
}
|
|
41
|
+
/**
|
|
42
|
+
* Converts a `bigint` to a 32-byte `Buffer`, zero-padded on the left.
|
|
43
|
+
* @param value - The bigint to convert.
|
|
44
|
+
* @returns A 32-byte big-endian buffer.
|
|
45
|
+
*/
|
|
30
46
|
function bigintToBytes(value) {
|
|
31
47
|
return Buffer.from(value.toString(16).padStart(64, '0'), 'hex');
|
|
32
48
|
}
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
49
|
+
/**
|
|
50
|
+
* Converts a `bigint` to a {@link Bytes32} hex string, left-padded to 32 bytes.
|
|
51
|
+
*
|
|
52
|
+
* **Warning:** It is the caller's responsibility to ensure the value fits in
|
|
53
|
+
* 32 bytes. Values that are too large will be silently truncated.
|
|
54
|
+
*
|
|
55
|
+
* @param value - The bigint to convert.
|
|
56
|
+
* @returns A `Bytes32` hex string.
|
|
57
|
+
*/
|
|
36
58
|
function bigintToBytes32(value) {
|
|
37
59
|
return (0, schema_js_1.parse)(exports.Bytes32, bigintToBytes(value).toString('hex'));
|
|
38
60
|
}
|
|
61
|
+
/**
|
|
62
|
+
* Left-pads a byte array with zeros to the specified length.
|
|
63
|
+
* @param bs - The byte array to pad.
|
|
64
|
+
* @param n - The desired total length in bytes.
|
|
65
|
+
* @returns A new `Buffer` of length `n` with `bs` right-aligned.
|
|
66
|
+
* @throws If `bs` is longer than `n` (would require truncation).
|
|
67
|
+
*/
|
|
39
68
|
function padLeft(bs, n) {
|
|
40
69
|
if (bs.length > n) {
|
|
41
70
|
throw new Error(`Cannot pad ${bs.length} bytes to ${n} - would truncate`);
|
|
@@ -44,22 +73,50 @@ function padLeft(bs, n) {
|
|
|
44
73
|
buf.set(bs, n - bs.length);
|
|
45
74
|
return buf;
|
|
46
75
|
}
|
|
76
|
+
/**
|
|
77
|
+
* Parses a {@link BytesIsh} value as a 32-byte value and converts it to a `bigint`.
|
|
78
|
+
* @param bs - A hex string or `Uint8Array` representing exactly 32 bytes.
|
|
79
|
+
* @returns The `bigint` representation of the 32-byte value.
|
|
80
|
+
* @throws If the input is not exactly 32 bytes.
|
|
81
|
+
*/
|
|
47
82
|
function bytes32ToBigint(bs) {
|
|
48
83
|
const bytes32 = asBytes32(bs);
|
|
49
84
|
return BigInt(bytes32);
|
|
50
85
|
}
|
|
86
|
+
/**
|
|
87
|
+
* Decodes a hex string into a `Buffer`. Handles both `0x`-prefixed and bare hex strings.
|
|
88
|
+
* @param hexString - The hex string to decode.
|
|
89
|
+
* @returns A `Buffer` containing the decoded bytes.
|
|
90
|
+
*/
|
|
51
91
|
function bytesFromHexString(hexString) {
|
|
52
92
|
return Buffer.from(hexString.startsWith('0x') ? hexString.slice(2) : hexString, 'hex');
|
|
53
93
|
}
|
|
94
|
+
/**
|
|
95
|
+
* Asserts that a string is a valid `0x`-prefixed hex string and narrows its type to `Hex`.
|
|
96
|
+
* @param value - The string to validate.
|
|
97
|
+
* @returns The input typed as `Hex`.
|
|
98
|
+
* @throws If `value` is not a valid hex string.
|
|
99
|
+
*/
|
|
54
100
|
function mustBeHex(value) {
|
|
55
101
|
if (!(0, viem_1.isHex)(value)) {
|
|
56
102
|
throw new Error(`Expected hex string, got: ${value}`);
|
|
57
103
|
}
|
|
58
104
|
return value;
|
|
59
105
|
}
|
|
106
|
+
/**
|
|
107
|
+
* Normalises a string to a `0x`-prefixed `Hex` value, adding the prefix if missing.
|
|
108
|
+
* @param value - A hex string, with or without a `0x` prefix.
|
|
109
|
+
* @returns The `0x`-prefixed `Hex` string.
|
|
110
|
+
* @throws If the resulting string is not valid hex.
|
|
111
|
+
*/
|
|
60
112
|
function normaliseToHex(value) {
|
|
61
113
|
return mustBeHex(value.startsWith('0x') ? value : `0x${value}`);
|
|
62
114
|
}
|
|
115
|
+
/**
|
|
116
|
+
* Encodes a `Uint8Array` as a `0x`-prefixed hex string.
|
|
117
|
+
* @param bs - The byte array to encode.
|
|
118
|
+
* @returns A `Hex` string representation of the bytes.
|
|
119
|
+
*/
|
|
63
120
|
function bytesToHex(bs) {
|
|
64
121
|
return ('0x' + Buffer.from(bs).toString('hex'));
|
|
65
122
|
}
|
|
@@ -73,17 +130,37 @@ const BytesToHex = effect_1.Schema.transformOrFail(effect_1.Schema.Union(effect_
|
|
|
73
130
|
? effect_1.ParseResult.succeed(y)
|
|
74
131
|
: effect_1.ParseResult.fail(new effect_1.ParseResult.Unexpected(y, `'${y}' is not a hex string`)))(normaliseToHex(x)),
|
|
75
132
|
});
|
|
133
|
+
/** Schema for a 32-byte (66-character with `0x` prefix) hex string, branded as `Bytes32`. Accepts both hex strings and `Uint8Array` inputs. */
|
|
76
134
|
exports.Bytes32 = BytesToHex.pipe(effect_1.Schema.filter((x) => x.length === 66 ||
|
|
77
135
|
`Expected 32-byte hex string (66 characters with 0x prefix) but got ${x.length} character string`), effect_1.Schema.brand('Bytes32'));
|
|
136
|
+
/**
|
|
137
|
+
* Parses and validates a {@link BytesIsh} value as a {@link Bytes32}.
|
|
138
|
+
* @param x - A hex string or `Uint8Array` to parse.
|
|
139
|
+
* @returns A validated `Bytes32` value.
|
|
140
|
+
* @throws If the input is not exactly 32 bytes.
|
|
141
|
+
*/
|
|
78
142
|
function asBytes32(x) {
|
|
79
143
|
return (0, schema_js_1.parse)(exports.Bytes32, x);
|
|
80
144
|
}
|
|
145
|
+
/** Schema for a 20-byte `0x`-prefixed Ethereum address, branded as `Address`. */
|
|
81
146
|
exports.Address = exports.HexString.pipe(effect_1.Schema.filter((s) => s.length === 42 ||
|
|
82
147
|
`Address must be a 20-byte '0x'-prefixed hex string, but got: ${s}`), effect_1.Schema.brand('Address'));
|
|
148
|
+
/**
|
|
149
|
+
* Parses and validates a string as an Ethereum {@link Address} (20-byte, `0x`-prefixed).
|
|
150
|
+
* @param address - The string to parse.
|
|
151
|
+
* @returns A validated `Address` value.
|
|
152
|
+
* @throws If the input is not a valid 20-byte hex address.
|
|
153
|
+
*/
|
|
83
154
|
function parseAddress(address) {
|
|
84
155
|
return (0, schema_js_1.parse)(exports.Address, address);
|
|
85
156
|
}
|
|
157
|
+
/**
|
|
158
|
+
* Parses and validates a string as a {@link HexString} (`0x`-prefixed).
|
|
159
|
+
* @param hex - The string to parse.
|
|
160
|
+
* @returns A validated `HexString` value.
|
|
161
|
+
* @throws If the input is not a valid `0x`-prefixed hex string.
|
|
162
|
+
*/
|
|
86
163
|
function parseHex(hex) {
|
|
87
164
|
return (0, schema_js_1.parse)(exports.HexString, hex);
|
|
88
165
|
}
|
|
89
|
-
//# sourceMappingURL=data:application/json;base64,
|
|
166
|
+
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiYmluYXJ5LmpzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi4vLi4vc3JjL2JpbmFyeS50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiOzs7QUFrQkEsc0NBS0M7QUFPRCx3Q0FFQztBQU9ELHNDQUVDO0FBV0QsMENBRUM7QUFTRCwwQkFPQztBQVFELDBDQUdDO0FBT0QsZ0RBS0M7QUFRRCw4QkFLQztBQVFELHdDQUVDO0FBT0QsZ0NBRUM7QUF3Q0QsOEJBRUM7QUF3QkQsb0NBRUM7QUFRRCw0QkFFQztBQTNNRCxtQ0FBNkM7QUFDN0MsK0JBQWtDO0FBQ2xDLDJDQUFvQztBQUVwQyw2Q0FBNkM7QUFDaEMsUUFBQSxTQUFTLEdBQUcsZUFBTSxDQUFDLGVBQWUsQ0FBQyxJQUFJLEVBQUUsZUFBTSxDQUFDLE1BQU0sQ0FBQyxDQUFDO0FBUXJFOzs7O0dBSUc7QUFDSCxTQUFnQixhQUFhLENBQUMsU0FBcUI7SUFDakQsK0dBQStHO0lBQy9HLE9BQU8sQ0FBQyxTQUFTLEVBQUUsTUFBTTtRQUN2QixDQUFDLENBQUMsTUFBTSxDQUFDLENBQUMsQ0FBQztRQUNYLENBQUMsQ0FBQyxNQUFNLENBQUMsSUFBSSxHQUFH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
+
* Map of supported chain short names to their chain IDs.
|
|
3
|
+
*
|
|
4
|
+
* @remarks This mirrors viem chain definitions without depending on viem directly,
|
|
5
|
+
* to work around Pulumi closure serialisation issues.
|
|
6
|
+
*/
|
|
1
7
|
export declare const supportedChains: {
|
|
2
8
|
readonly baseSepolia: 84532;
|
|
3
9
|
readonly sepolia: 11155111;
|
|
@@ -6,20 +12,31 @@ export declare const supportedChains: {
|
|
|
6
12
|
readonly worldchainSepolia: 4801;
|
|
7
13
|
readonly anvil: 31337;
|
|
8
14
|
};
|
|
9
|
-
export declare const fheSupportedChains: {
|
|
10
|
-
readonly baseSepolia: 84532;
|
|
11
|
-
readonly sepolia: 11155111;
|
|
12
|
-
};
|
|
13
15
|
type SupportedChains = typeof supportedChains;
|
|
16
|
+
/** Numeric chain ID of a supported chain (e.g. `84532`, `11155111`). */
|
|
14
17
|
export type SupportedChainId = SupportedChains[keyof SupportedChains];
|
|
18
|
+
/** Short name of a supported chain (e.g. `"baseSepolia"`, `"sepolia"`). */
|
|
15
19
|
export type SupportedChainName = keyof SupportedChains;
|
|
20
|
+
/** A supported chain identified by both its short name and numeric ID. */
|
|
16
21
|
export type SupportedChain = {
|
|
17
22
|
name: SupportedChainName;
|
|
18
23
|
id: SupportedChainId;
|
|
19
24
|
};
|
|
25
|
+
/** A value that can represent a number — either a `number` or a `bigint`. */
|
|
20
26
|
export type Numberish = number | bigint;
|
|
27
|
+
/** A flexible chain identifier: a chain ID (`number` | `bigint`), an object with an `id` field, or a chain short name. */
|
|
21
28
|
export type Chainish = {
|
|
22
29
|
id: Numberish;
|
|
23
30
|
} | Numberish | string;
|
|
31
|
+
/**
|
|
32
|
+
* Resolves a {@link Chainish} value to a {@link SupportedChain}.
|
|
33
|
+
*
|
|
34
|
+
* Accepts a chain ID (`number` or `bigint`), an object with an `id` field,
|
|
35
|
+
* or a chain short name (e.g. `"baseSepolia"`).
|
|
36
|
+
*
|
|
37
|
+
* @param chainish - The chain identifier to resolve.
|
|
38
|
+
* @returns The matching `SupportedChain` with both `name` and `id`.
|
|
39
|
+
* @throws If no supported chain matches the given identifier.
|
|
40
|
+
*/
|
|
24
41
|
export declare function getSupportedChain(chainish: Chainish): SupportedChain;
|
|
25
42
|
export {};
|
package/dist/cjs/chain.js
CHANGED
|
@@ -1,11 +1,17 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
// No imports here to avoid issues with closures and modules across pulumi boundary
|
|
3
3
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
-
exports.
|
|
4
|
+
exports.supportedChains = void 0;
|
|
5
5
|
exports.getSupportedChain = getSupportedChain;
|
|
6
6
|
// This file can be seen as mirroring the functionality of viem changes without depending on it directly.
|
|
7
7
|
// It exists as a workaround for some very gnarly issues with code reuse between Pulumi and this module, partly
|
|
8
8
|
// relating to modules but also linked to Pulumi's ability to capture closures and serialise them.
|
|
9
|
+
/**
|
|
10
|
+
* Map of supported chain short names to their chain IDs.
|
|
11
|
+
*
|
|
12
|
+
* @remarks This mirrors viem chain definitions without depending on viem directly,
|
|
13
|
+
* to work around Pulumi closure serialisation issues.
|
|
14
|
+
*/
|
|
9
15
|
exports.supportedChains = {
|
|
10
16
|
baseSepolia: 84532,
|
|
11
17
|
sepolia: 11155111,
|
|
@@ -14,11 +20,16 @@ exports.supportedChains = {
|
|
|
14
20
|
worldchainSepolia: 4801,
|
|
15
21
|
anvil: 31337,
|
|
16
22
|
};
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
23
|
+
/**
|
|
24
|
+
* Resolves a {@link Chainish} value to a {@link SupportedChain}.
|
|
25
|
+
*
|
|
26
|
+
* Accepts a chain ID (`number` or `bigint`), an object with an `id` field,
|
|
27
|
+
* or a chain short name (e.g. `"baseSepolia"`).
|
|
28
|
+
*
|
|
29
|
+
* @param chainish - The chain identifier to resolve.
|
|
30
|
+
* @returns The matching `SupportedChain` with both `name` and `id`.
|
|
31
|
+
* @throws If no supported chain matches the given identifier.
|
|
32
|
+
*/
|
|
22
33
|
function getSupportedChain(chainish) {
|
|
23
34
|
const found = typeof chainish === 'number' || typeof chainish === 'bigint'
|
|
24
35
|
? Object.entries(exports.supportedChains).find(([, id]) => id === Number(chainish))
|
|
@@ -31,4 +42,4 @@ function getSupportedChain(chainish) {
|
|
|
31
42
|
const [name, id] = found;
|
|
32
43
|
return { name: name, id };
|
|
33
44
|
}
|
|
34
|
-
//# sourceMappingURL=data:application/json;base64,
|
|
45
|
+
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiY2hhaW4uanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi8uLi9zcmMvY2hhaW4udHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IjtBQUFBLG1GQUFtRjs7O0FBZ0RuRiw4Q0FrQkM7QUFoRUQseUdBQXlHO0FBQ3pHLCtHQUErRztBQUMvRyxrR0FBa0c7QUFFbEc7Ozs7O0dBS0c7QUFDVSxRQUFBLGVBQWUsR0FBRztJQUM3QixXQUFXLEVBQUUsS0FBSztJQUNsQixPQUFPLEVBQUUsUUFBUTtJQUNqQixZQUFZLEVBQUUsS0FBSztJQUNuQixhQUFhLEVBQUUsSUFBSTtJQUNuQixpQkFBaUIsRUFBRSxJQUFJO0lBQ3ZCLEtBQUssRUFBRSxLQUFLO0NBQ0osQ0FBQztBQW1CWDs7Ozs7Ozs7O0dBU0c7QUFDSCxTQUFnQixpQkFBaUIsQ0FBQyxRQUFrQjtJQUNsRCxNQUFNLEtBQUssR0FDVCxPQUFPLFFBQVEsS0FBSyxRQUFRLElBQUksT0FBTyxRQUFRLEtBQUssUUFBUTtRQUMxRCxDQUFDLENBQUMsTUFBTSxDQUFDLE9BQU8sQ0FBQyx1QkFBZSxDQUFDLENBQUMsSUFBSSxDQUNsQyxDQUFDLENBQUMsRUFBRSxFQUFFLENBQUMsRUFBRSxFQUFFLENBQUMsRUFBRSxLQUFLLE1BQU0sQ0FBQyxRQUFRLENBQUMsQ0FDcEM7UUFDSCxDQUFDLENBQUMsT0FBTyxRQUFRLEtBQUssUUFBUTtZQUM1QixDQUFDLENBQUMsTUFBTSxDQUFDLE9BQU8sQ0FBQyx1QkFBZSxDQUFDLENBQUMsSUFBSSxDQUNsQyxDQUFDLENBQUMsRUFBRSxFQUFFLENBQUMsRUFBRSxFQUFFLENBQUMsRUFBRSxLQUFLLE1BQU0sQ0FBQyxRQUFRLENBQUMsRUFBRSxDQUFDLENBQ3ZDO1lBQ0gsQ0FBQyxDQUFDLE1BQU0sQ0FBQyxPQUFPLENBQUMsdUJBQWUsQ0FBQyxDQUFDLElBQUksQ0FDbEMsQ0FBQyxDQUFDLFNBQVMsQ0FBQyxFQUFFLEVBQUUsQ0FBQyxTQUFTLEtBQUssUUFBUSxDQUN4QyxDQUFDO0lBQ1YsSUFBSSxDQUFDLEtBQUssRUFBRSxDQUFDO1FBQ1gsTUFBTSxJQUFJLEtBQUssQ0FBQyxtQkFBbUIsUUFBUSxZQUFZLENBQUMsQ0FBQztJQUMzRCxDQUFDO0lBQ0QsTUFBTSxDQUFDLElBQUksRUFBRSxFQUFFLENBQUMsR0FBRyxLQUFLLENBQUM7SUFDekIsT0FBTyxFQUFFLElBQUksRUFBRSxJQUEwQixFQUFFLEVBQUUsRUFBRSxDQUFDO0FBQ2xELENBQUMifQ==
|
|
@@ -1,37 +1,79 @@
|
|
|
1
1
|
import { Schema } from 'effect';
|
|
2
2
|
import { ByteArray, Hex } from 'viem';
|
|
3
3
|
import { Bytes32 } from '../binary.js';
|
|
4
|
+
/**
|
|
5
|
+
* A function that encrypts a plaintext value, embedding its {@link InputContext} into the resulting ciphertext.
|
|
6
|
+
*
|
|
7
|
+
* @typeParam S - The encryption scheme (e.g. X-Wing).
|
|
8
|
+
* @example
|
|
9
|
+
* ```ts
|
|
10
|
+
* const result = await encrypt({ plaintext: { scheme: 2, type: 5, value: 42n }, context });
|
|
11
|
+
* // result.handle, result.ciphertext, result.prehandle
|
|
12
|
+
* ```
|
|
13
|
+
*/
|
|
4
14
|
export type Encryptor<S extends EncryptionScheme = EncryptionScheme> = <T extends SupportedFheType>(plaintext: PlaintextWithContextOf<S, T>) => Promise<EncryptResultOf<S, T>>;
|
|
15
|
+
/**
|
|
16
|
+
* A function that decrypts a ciphertext back to its plaintext value.
|
|
17
|
+
*
|
|
18
|
+
* @typeParam S - The encryption scheme (e.g. X-Wing).
|
|
19
|
+
* @example
|
|
20
|
+
* ```ts
|
|
21
|
+
* const plaintext = await decrypt({ scheme: 2, type: 5, value: '0x...' });
|
|
22
|
+
* ```
|
|
23
|
+
*/
|
|
5
24
|
export type Decryptor<S extends EncryptionScheme = EncryptionScheme> = <T extends SupportedFheType>(ciphertext: CiphertextOf<S, T>) => Promise<PlaintextOf<S, T>>;
|
|
25
|
+
/**
|
|
26
|
+
* Subset of ENCRYPTION types currently supported for encryption/decryption.
|
|
27
|
+
*
|
|
28
|
+
* @remarks TODO: review need of `euint64` and `euint160` — `Lib.sol` only supports `euint256` and `ebool`.
|
|
29
|
+
*/
|
|
6
30
|
export declare const supportedFheTypes: {
|
|
7
31
|
readonly euint64: 5;
|
|
8
32
|
readonly euint160: 7;
|
|
9
33
|
readonly euint256: 8;
|
|
10
34
|
readonly ebool: 0;
|
|
11
35
|
};
|
|
36
|
+
/** Schema that validates a string is one of the supported ENCRYPTION type names. */
|
|
12
37
|
export declare const SupportedFheTypeName: Schema.SchemaClass<"ebool" | "euint64" | "euint160" | "euint256", "ebool" | "euint64" | "euint160" | "euint256", never>;
|
|
38
|
+
/** A supported ENCRYPTION type name (e.g. `"euint256"`, `"ebool"`). */
|
|
13
39
|
export type SupportedFheTypeName = typeof SupportedFheTypeName.Type;
|
|
40
|
+
/** Schema that validates a number is one of the supported ENCRYPTION type integer identifiers. */
|
|
14
41
|
export declare const SupportedFheType: Schema.SchemaClass<0 | 5 | 7 | 8, 0 | 5 | 7 | 8, never>;
|
|
42
|
+
/** Integer identifier of a supported ENCRYPTION type (a subset of all ENCRYPTION types). */
|
|
15
43
|
export type SupportedFheType = typeof SupportedFheType.Type;
|
|
44
|
+
/** Map of encryption scheme names to their integer identifiers. Currently only X-Wing (2) is supported. */
|
|
16
45
|
export declare const encryptionSchemes: {
|
|
17
46
|
readonly xwing: 2;
|
|
18
47
|
};
|
|
48
|
+
/**
|
|
49
|
+
* Returns the human-readable name of an encryption scheme.
|
|
50
|
+
* @param scheme - The encryption scheme integer identifier.
|
|
51
|
+
* @returns The scheme name (e.g. `"X-Wing"`).
|
|
52
|
+
* @throws If the scheme identifier is unknown.
|
|
53
|
+
*/
|
|
19
54
|
export declare function getEncryptionSchemeName(scheme: number): string;
|
|
55
|
+
/** The typeof {@link encryptionSchemes} — mapping from scheme names to integer IDs. */
|
|
20
56
|
export type EncryptionSchemes = typeof encryptionSchemes;
|
|
57
|
+
/** The integer identifier for the X-Wing encryption scheme (`2`). */
|
|
21
58
|
export type XwingScheme = EncryptionSchemes['xwing'];
|
|
59
|
+
/** Schema that validates a value is a known encryption scheme identifier. */
|
|
22
60
|
export declare const EncryptionScheme: Schema.Literal<[2]>;
|
|
61
|
+
/** An encryption scheme identifier (currently only X-Wing = `2`). */
|
|
23
62
|
export type EncryptionScheme = typeof EncryptionScheme.Type;
|
|
24
63
|
type DistType<P, S extends EncryptionScheme, T extends SupportedFheType> = P extends any ? P & {
|
|
25
64
|
scheme: S;
|
|
26
65
|
type: T;
|
|
27
66
|
} : never;
|
|
67
|
+
/** Schema for an ENCRYPTION ciphertext: encryption scheme, ENCRYPTION type, and the encrypted value as a hex string. */
|
|
28
68
|
export declare const Ciphertext: Schema.Struct<{
|
|
29
69
|
scheme: Schema.Literal<[2]>;
|
|
30
70
|
type: Schema.SchemaClass<0 | 5 | 7 | 8, 0 | 5 | 7 | 8, never>;
|
|
31
71
|
value: Schema.TemplateLiteral<`0x${string}`>;
|
|
32
72
|
}>;
|
|
73
|
+
/** An ENCRYPTION ciphertext containing the encryption scheme, ENCRYPTION type, and encrypted hex value. */
|
|
33
74
|
export type Ciphertext = typeof Ciphertext.Type;
|
|
34
75
|
export type CiphertextOf<S extends EncryptionScheme, T extends SupportedFheType> = DistType<Ciphertext, S, T>;
|
|
76
|
+
/** Schema for a ciphertext paired with the {@link InputContext} it was encrypted under. */
|
|
35
77
|
export declare const CiphertextWithContext: Schema.Struct<{
|
|
36
78
|
ciphertext: Schema.Struct<{
|
|
37
79
|
scheme: Schema.Literal<[2]>;
|
|
@@ -46,10 +88,12 @@ export declare const CiphertextWithContext: Schema.Struct<{
|
|
|
46
88
|
version: typeof Schema.Number;
|
|
47
89
|
}>;
|
|
48
90
|
}>;
|
|
91
|
+
/** A ciphertext paired with the {@link InputContext} it was encrypted under. */
|
|
49
92
|
export type CiphertextWithContext = typeof CiphertextWithContext.Type;
|
|
50
93
|
export type CiphertextWithContextOf<S extends EncryptionScheme, T extends SupportedFheType> = CiphertextWithContext & {
|
|
51
94
|
ciphertext: CiphertextOf<S, T>;
|
|
52
95
|
};
|
|
96
|
+
/** Schema for the result of an encryption operation: ciphertext, input context, prehandle, and final handle. */
|
|
53
97
|
export declare const EncryptResult: Schema.Struct<{
|
|
54
98
|
ciphertext: Schema.Struct<{
|
|
55
99
|
scheme: Schema.Literal<[2]>;
|
|
@@ -66,10 +110,16 @@ export declare const EncryptResult: Schema.Struct<{
|
|
|
66
110
|
prehandle: Schema.brand<Schema.filter<Schema.transformOrFail<Schema.Union<[typeof Schema.String, Schema.refine<object & Uint8Array<ArrayBufferLike>, Schema.Schema<object, object, never>>]>, Schema.TemplateLiteral<`0x${string}`>, never>>, "Bytes32">;
|
|
67
111
|
handle: Schema.brand<Schema.filter<Schema.transformOrFail<Schema.Union<[typeof Schema.String, Schema.refine<object & Uint8Array<ArrayBufferLike>, Schema.Schema<object, object, never>>]>, Schema.TemplateLiteral<`0x${string}`>, never>>, "Bytes32">;
|
|
68
112
|
}>;
|
|
113
|
+
/** The result of an encryption operation, containing the ciphertext, context, prehandle, and deterministic handle. */
|
|
69
114
|
export type EncryptResult = typeof EncryptResult.Type;
|
|
70
115
|
export type EncryptResultOf<S extends EncryptionScheme, T extends SupportedFheType> = EncryptResult & {
|
|
71
116
|
ciphertext: CiphertextOf<S, T>;
|
|
72
117
|
};
|
|
118
|
+
/**
|
|
119
|
+
* Schema for an ENCRYPTION plaintext value. The `value` field type depends on the ENCRYPTION type:
|
|
120
|
+
* - `euint64` / `euint160` / `euint256`: `bigint`
|
|
121
|
+
* - `ebool`: `boolean`
|
|
122
|
+
*/
|
|
73
123
|
export declare const Plaintext: Schema.Union<[Schema.Struct<{
|
|
74
124
|
scheme: Schema.Literal<[2]>;
|
|
75
125
|
type: Schema.Literal<[5, 7, 8]>;
|
|
@@ -79,8 +129,10 @@ export declare const Plaintext: Schema.Union<[Schema.Struct<{
|
|
|
79
129
|
type: Schema.Literal<[0]>;
|
|
80
130
|
value: typeof Schema.Boolean;
|
|
81
131
|
}>]>;
|
|
132
|
+
/** An ENCRYPTION plaintext value — `bigint` for integer types, `boolean` for `ebool`. */
|
|
82
133
|
export type Plaintext = typeof Plaintext.Type;
|
|
83
134
|
export type PlaintextOf<S extends EncryptionScheme, T extends SupportedFheType> = DistType<Plaintext, S, T>;
|
|
135
|
+
/** Schema for a plaintext paired with the {@link InputContext} it will be encrypted under. */
|
|
84
136
|
export declare const PlaintextWithContext: Schema.Struct<{
|
|
85
137
|
plaintext: Schema.Union<[Schema.Struct<{
|
|
86
138
|
scheme: Schema.Literal<[2]>;
|
|
@@ -99,20 +151,83 @@ export declare const PlaintextWithContext: Schema.Struct<{
|
|
|
99
151
|
version: typeof Schema.Number;
|
|
100
152
|
}>;
|
|
101
153
|
}>;
|
|
154
|
+
/** A plaintext paired with the {@link InputContext} it will be encrypted under. */
|
|
102
155
|
export type PlaintextWithContext = typeof PlaintextWithContext.Type;
|
|
103
156
|
export type PlaintextWithContextOf<S extends EncryptionScheme, T extends SupportedFheType> = PlaintextWithContext & {
|
|
104
157
|
plaintext: PlaintextOf<S, T>;
|
|
105
158
|
};
|
|
159
|
+
/**
|
|
160
|
+
* Converts a `bigint` to a typed {@link Plaintext} value.
|
|
161
|
+
*
|
|
162
|
+
* For integer ENCRYPTION types (`euint64`, `euint160`, `euint256`) the value is passed through as-is.
|
|
163
|
+
* For `ebool`, non-zero values become `true`.
|
|
164
|
+
*
|
|
165
|
+
* @param scheme - The encryption scheme identifier.
|
|
166
|
+
* @param type - The ENCRYPTION type to interpret the value as.
|
|
167
|
+
* @param bigPt - The raw bigint plaintext value.
|
|
168
|
+
* @returns A typed `Plaintext` matching the given scheme and ENCRYPTION type.
|
|
169
|
+
* @throws If `type` is not a supported ENCRYPTION type.
|
|
170
|
+
*/
|
|
106
171
|
export declare function bigintToPlaintext<S extends EncryptionScheme, T extends SupportedFheType>(scheme: S, type: T, bigPt: bigint): PlaintextOf<S, T>;
|
|
172
|
+
/**
|
|
173
|
+
* Decodes an ABI-encoded ciphertext input into its components.
|
|
174
|
+
*
|
|
175
|
+
* The input format is: `4-byte version || abi.encode(bytes32 handle, bytes ciphertext)`.
|
|
176
|
+
*
|
|
177
|
+
* @param input - The raw encoded input as a byte array or hex string.
|
|
178
|
+
* @returns The decoded version, handle, and ciphertext.
|
|
179
|
+
*/
|
|
107
180
|
export declare function decodeCiphertextInput(input: ByteArray | Hex): {
|
|
108
181
|
version: number;
|
|
109
182
|
handle: Hex;
|
|
110
183
|
ciphertext: Hex;
|
|
111
184
|
};
|
|
185
|
+
/**
|
|
186
|
+
* Encodes a handle and ciphertext into the on-chain input format.
|
|
187
|
+
*
|
|
188
|
+
* The output format is: `4-byte version || abi.encode(bytes32 handle, bytes ciphertext)`.
|
|
189
|
+
*
|
|
190
|
+
* @param version - The encoding version (int32).
|
|
191
|
+
* @param handle - The 32-byte handle as a hex string.
|
|
192
|
+
* @param ciphertext - The ciphertext as a hex string.
|
|
193
|
+
* @returns The ABI-encoded input as a hex string.
|
|
194
|
+
*/
|
|
112
195
|
export declare function encodeCiphertextInput(version: number, handle: Hex, ciphertext: Hex): Hex;
|
|
196
|
+
/**
|
|
197
|
+
* Converts a {@link Plaintext} to its `bigint` representation.
|
|
198
|
+
*
|
|
199
|
+
* Integer types pass through directly; `ebool` maps `true` → `1n`, `false` → `0n`.
|
|
200
|
+
*
|
|
201
|
+
* @param plaintext - The plaintext to convert.
|
|
202
|
+
* @returns The bigint representation of the plaintext value.
|
|
203
|
+
*/
|
|
113
204
|
export declare function plaintextToBigint(plaintext: Plaintext): bigint;
|
|
205
|
+
/**
|
|
206
|
+
* Converts a {@link Plaintext} to a {@link Bytes32} hex string.
|
|
207
|
+
* @param plaintext - The plaintext to convert.
|
|
208
|
+
* @returns A 32-byte hex representation of the plaintext value.
|
|
209
|
+
*/
|
|
114
210
|
export declare function plaintextToBytes32(plaintext: Plaintext): Bytes32;
|
|
211
|
+
/**
|
|
212
|
+
* Converts a {@link Plaintext} to a 32-byte `Buffer`.
|
|
213
|
+
* @param plaintext - The plaintext to convert.
|
|
214
|
+
* @returns A 32-byte big-endian buffer of the plaintext value.
|
|
215
|
+
*/
|
|
115
216
|
export declare function plaintextToBytes(plaintext: Plaintext): Buffer;
|
|
217
|
+
/**
|
|
218
|
+
* Parses a {@link Bytes32} hex string into a typed {@link Plaintext}.
|
|
219
|
+
* @param plaintext - The 32-byte hex value to interpret.
|
|
220
|
+
* @param scheme - The encryption scheme identifier.
|
|
221
|
+
* @param type - The ENCRYPTION type to interpret the bytes as.
|
|
222
|
+
* @returns A typed `Plaintext` value.
|
|
223
|
+
*/
|
|
116
224
|
export declare function bytes32ToPlaintext(plaintext: Bytes32, scheme: EncryptionScheme, type: SupportedFheType): Plaintext;
|
|
225
|
+
/**
|
|
226
|
+
* Parses a `Uint8Array` into a typed {@link Plaintext}.
|
|
227
|
+
* @param plaintext - The byte array to interpret.
|
|
228
|
+
* @param scheme - The encryption scheme identifier.
|
|
229
|
+
* @param type - The ENCRYPTION type to interpret the bytes as.
|
|
230
|
+
* @returns A typed `Plaintext` value.
|
|
231
|
+
*/
|
|
117
232
|
export declare function bytesToPlaintext(plaintext: Uint8Array, scheme: EncryptionScheme, type: SupportedFheType): Plaintext;
|
|
118
233
|
export {};
|