@inco/shield-js 0.1.0 → 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/README.md +52 -308
- package/dist/contracts/abi.d.ts +2000 -4513
- package/dist/contracts/abi.js +2400 -5651
- package/dist/contracts/index.d.ts +2 -2
- package/dist/contracts/index.js +2 -2
- package/dist/contracts/utils.d.ts +5 -24
- package/dist/contracts/utils.js +13 -24
- package/dist/errors.d.ts +16 -47
- package/dist/errors.js +6 -53
- package/dist/generated/inco/shield/v2/conductor_pb.d.ts +77 -0
- package/dist/generated/inco/shield/v2/conductor_pb.js +6 -0
- package/dist/generated/inco/shield/v2/deposit_pb.d.ts +12 -103
- package/dist/generated/inco/shield/v2/deposit_pb.js +4 -141
- package/dist/generated/inco/shield/v2/drafting_pb.d.ts +45 -269
- package/dist/generated/inco/shield/v2/drafting_pb.js +8 -361
- package/dist/generated/inco/shield/v2/types_pb.d.ts +47 -166
- package/dist/generated/inco/shield/v2/types_pb.js +12 -261
- package/dist/index.d.ts +1 -7
- package/dist/index.js +1 -14
- package/dist/shield/abi.d.ts +5 -0
- package/dist/shield/abi.js +28 -0
- package/dist/shield/client.d.ts +27 -51
- package/dist/shield/client.js +73 -65
- package/dist/shield/convert.d.ts +2 -14
- package/dist/shield/convert.js +39 -115
- package/dist/shield/encryption.d.ts +0 -67
- package/dist/shield/encryption.js +0 -67
- package/dist/shield/envelope.d.ts +10 -11
- package/dist/shield/envelope.js +15 -14
- package/dist/shield/fee.d.ts +24 -0
- package/dist/shield/fee.js +151 -0
- package/dist/shield/index.d.ts +9 -3
- package/dist/shield/index.js +7 -2
- package/dist/shield/intent.d.ts +20 -933
- package/dist/shield/intent.js +92 -112
- package/dist/shield/permission-status.d.ts +9 -0
- package/dist/shield/permission-status.js +8 -0
- package/dist/shield/rpc.d.ts +50 -49
- package/dist/shield/rpc.js +207 -354
- package/dist/shield/shield.eip712.gen.d.ts +1096 -43
- package/dist/shield/shield.eip712.gen.js +572 -62
- package/dist/shield/types.d.ts +7 -102
- package/dist/shield/types.js +1 -4
- package/dist/shield/userop/gas-estimation.d.ts +7 -22
- package/dist/shield/userop/gas-estimation.js +100 -137
- package/dist/shield/userop/paymaster.d.ts +15 -0
- package/dist/shield/userop/paymaster.js +17 -0
- package/dist/shield/userop/token-exchange.d.ts +5 -52
- package/dist/shield/userop/token-exchange.js +41 -149
- package/dist/shield/userop/types.d.ts +2 -27
- package/dist/shield/userop/types.js +0 -3
- package/dist/shield/userop/userOp.d.ts +0 -19
- package/dist/shield/userop/userOp.js +4 -22
- package/dist/shield/utils/chain.d.ts +1 -0
- package/dist/shield/utils/chain.js +3 -0
- package/dist/shield/validate-withdrawal-split.d.ts +13 -0
- package/dist/shield/validate-withdrawal-split.js +93 -0
- package/package.json +18 -27
- package/dist/generated/inco/shield/v2/conductor_connect.d.ts +0 -137
- package/dist/generated/inco/shield/v2/conductor_connect.js +0 -141
- package/dist/generated/inco/shield/v2/permission_pb.d.ts +0 -443
- package/dist/generated/inco/shield/v2/permission_pb.js +0 -639
- package/dist/generated/inco/shield/v2/query_pb.d.ts +0 -103
- package/dist/generated/inco/shield/v2/query_pb.js +0 -141
- package/dist/shield/userop/index.d.ts +0 -1
- package/dist/shield/userop/index.js +0 -1
- package/dist/uniswap-adapter/config.d.ts +0 -34
- package/dist/uniswap-adapter/config.js +0 -45
- package/dist/uniswap-adapter/find-pools.d.ts +0 -91
- package/dist/uniswap-adapter/find-pools.js +0 -108
- package/dist/uniswap-adapter/index.d.ts +0 -10
- package/dist/uniswap-adapter/index.js +0 -13
- package/dist/uniswap-adapter/swap.d.ts +0 -344
- package/dist/uniswap-adapter/swap.js +0 -309
|
@@ -1,261 +1,12 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
export
|
|
13
|
-
/**
|
|
14
|
-
* The raw 20-byte address value.
|
|
15
|
-
*
|
|
16
|
-
* @generated from field: bytes value = 1;
|
|
17
|
-
*/
|
|
18
|
-
value = new Uint8Array(0);
|
|
19
|
-
constructor(data) {
|
|
20
|
-
super();
|
|
21
|
-
proto3.util.initPartial(data, this);
|
|
22
|
-
}
|
|
23
|
-
static runtime = proto3;
|
|
24
|
-
static typeName = "inco.shield.v2.Address";
|
|
25
|
-
static fields = proto3.util.newFieldList(() => [
|
|
26
|
-
{ no: 1, name: "value", kind: "scalar", T: 12 /* ScalarType.BYTES */ },
|
|
27
|
-
]);
|
|
28
|
-
static fromBinary(bytes, options) {
|
|
29
|
-
return new Address().fromBinary(bytes, options);
|
|
30
|
-
}
|
|
31
|
-
static fromJson(jsonValue, options) {
|
|
32
|
-
return new Address().fromJson(jsonValue, options);
|
|
33
|
-
}
|
|
34
|
-
static fromJsonString(jsonString, options) {
|
|
35
|
-
return new Address().fromJsonString(jsonString, options);
|
|
36
|
-
}
|
|
37
|
-
static equals(a, b) {
|
|
38
|
-
return proto3.util.equals(Address, a, b);
|
|
39
|
-
}
|
|
40
|
-
}
|
|
41
|
-
/**
|
|
42
|
-
* Bytes32 represents a 32-byte value, used for hashes and other fixed-size data.
|
|
43
|
-
*
|
|
44
|
-
* @generated from message inco.shield.v2.Bytes32
|
|
45
|
-
*/
|
|
46
|
-
export class Bytes32 extends Message {
|
|
47
|
-
/**
|
|
48
|
-
* The raw 32-byte value.
|
|
49
|
-
*
|
|
50
|
-
* @generated from field: bytes value = 1;
|
|
51
|
-
*/
|
|
52
|
-
value = new Uint8Array(0);
|
|
53
|
-
constructor(data) {
|
|
54
|
-
super();
|
|
55
|
-
proto3.util.initPartial(data, this);
|
|
56
|
-
}
|
|
57
|
-
static runtime = proto3;
|
|
58
|
-
static typeName = "inco.shield.v2.Bytes32";
|
|
59
|
-
static fields = proto3.util.newFieldList(() => [
|
|
60
|
-
{ no: 1, name: "value", kind: "scalar", T: 12 /* ScalarType.BYTES */ },
|
|
61
|
-
]);
|
|
62
|
-
static fromBinary(bytes, options) {
|
|
63
|
-
return new Bytes32().fromBinary(bytes, options);
|
|
64
|
-
}
|
|
65
|
-
static fromJson(jsonValue, options) {
|
|
66
|
-
return new Bytes32().fromJson(jsonValue, options);
|
|
67
|
-
}
|
|
68
|
-
static fromJsonString(jsonString, options) {
|
|
69
|
-
return new Bytes32().fromJsonString(jsonString, options);
|
|
70
|
-
}
|
|
71
|
-
static equals(a, b) {
|
|
72
|
-
return proto3.util.equals(Bytes32, a, b);
|
|
73
|
-
}
|
|
74
|
-
}
|
|
75
|
-
/**
|
|
76
|
-
* Handle is a unique identifier for a position in the shield state.
|
|
77
|
-
* Used to track the covalidator's view of the on-chain state.
|
|
78
|
-
*
|
|
79
|
-
* @generated from message inco.shield.v2.Handle
|
|
80
|
-
*/
|
|
81
|
-
export class Handle extends Message {
|
|
82
|
-
/**
|
|
83
|
-
* The 32-byte handle value.
|
|
84
|
-
*
|
|
85
|
-
* @generated from field: bytes value = 1;
|
|
86
|
-
*/
|
|
87
|
-
value = new Uint8Array(0);
|
|
88
|
-
constructor(data) {
|
|
89
|
-
super();
|
|
90
|
-
proto3.util.initPartial(data, this);
|
|
91
|
-
}
|
|
92
|
-
static runtime = proto3;
|
|
93
|
-
static typeName = "inco.shield.v2.Handle";
|
|
94
|
-
static fields = proto3.util.newFieldList(() => [
|
|
95
|
-
{ no: 1, name: "value", kind: "scalar", T: 12 /* ScalarType.BYTES */ },
|
|
96
|
-
]);
|
|
97
|
-
static fromBinary(bytes, options) {
|
|
98
|
-
return new Handle().fromBinary(bytes, options);
|
|
99
|
-
}
|
|
100
|
-
static fromJson(jsonValue, options) {
|
|
101
|
-
return new Handle().fromJson(jsonValue, options);
|
|
102
|
-
}
|
|
103
|
-
static fromJsonString(jsonString, options) {
|
|
104
|
-
return new Handle().fromJsonString(jsonString, options);
|
|
105
|
-
}
|
|
106
|
-
static equals(a, b) {
|
|
107
|
-
return proto3.util.equals(Handle, a, b);
|
|
108
|
-
}
|
|
109
|
-
}
|
|
110
|
-
/**
|
|
111
|
-
* AssetId identifies a specific asset type within the shield system.
|
|
112
|
-
* Typically derived from the token contract address.
|
|
113
|
-
*
|
|
114
|
-
* @generated from message inco.shield.v2.AssetId
|
|
115
|
-
*/
|
|
116
|
-
export class AssetId extends Message {
|
|
117
|
-
/**
|
|
118
|
-
* The 32-byte asset identifier.
|
|
119
|
-
*
|
|
120
|
-
* @generated from field: bytes value = 1;
|
|
121
|
-
*/
|
|
122
|
-
value = new Uint8Array(0);
|
|
123
|
-
constructor(data) {
|
|
124
|
-
super();
|
|
125
|
-
proto3.util.initPartial(data, this);
|
|
126
|
-
}
|
|
127
|
-
static runtime = proto3;
|
|
128
|
-
static typeName = "inco.shield.v2.AssetId";
|
|
129
|
-
static fields = proto3.util.newFieldList(() => [
|
|
130
|
-
{ no: 1, name: "value", kind: "scalar", T: 12 /* ScalarType.BYTES */ },
|
|
131
|
-
]);
|
|
132
|
-
static fromBinary(bytes, options) {
|
|
133
|
-
return new AssetId().fromBinary(bytes, options);
|
|
134
|
-
}
|
|
135
|
-
static fromJson(jsonValue, options) {
|
|
136
|
-
return new AssetId().fromJson(jsonValue, options);
|
|
137
|
-
}
|
|
138
|
-
static fromJsonString(jsonString, options) {
|
|
139
|
-
return new AssetId().fromJsonString(jsonString, options);
|
|
140
|
-
}
|
|
141
|
-
static equals(a, b) {
|
|
142
|
-
return proto3.util.equals(AssetId, a, b);
|
|
143
|
-
}
|
|
144
|
-
}
|
|
145
|
-
/**
|
|
146
|
-
* Uint256 is an unsigned 256-bit integer.
|
|
147
|
-
*
|
|
148
|
-
* Wire encoding: `value` is exactly 32 bytes, big-endian, unsigned. Same
|
|
149
|
-
* byte layout as Solidity's `uint256` ABI encoding. Producers write the
|
|
150
|
-
* integer to a 32-byte buffer big-endian (left-zero-padded); consumers
|
|
151
|
-
* read the 32 bytes as a big-endian unsigned integer. The zero value is
|
|
152
|
-
* 32 zero bytes (not an empty `value`). Length other than 32 is invalid.
|
|
153
|
-
*
|
|
154
|
-
* @generated from message inco.shield.v2.Uint256
|
|
155
|
-
*/
|
|
156
|
-
export class Uint256 extends Message {
|
|
157
|
-
/**
|
|
158
|
-
* @generated from field: bytes value = 1;
|
|
159
|
-
*/
|
|
160
|
-
value = new Uint8Array(0);
|
|
161
|
-
constructor(data) {
|
|
162
|
-
super();
|
|
163
|
-
proto3.util.initPartial(data, this);
|
|
164
|
-
}
|
|
165
|
-
static runtime = proto3;
|
|
166
|
-
static typeName = "inco.shield.v2.Uint256";
|
|
167
|
-
static fields = proto3.util.newFieldList(() => [
|
|
168
|
-
{ no: 1, name: "value", kind: "scalar", T: 12 /* ScalarType.BYTES */ },
|
|
169
|
-
]);
|
|
170
|
-
static fromBinary(bytes, options) {
|
|
171
|
-
return new Uint256().fromBinary(bytes, options);
|
|
172
|
-
}
|
|
173
|
-
static fromJson(jsonValue, options) {
|
|
174
|
-
return new Uint256().fromJson(jsonValue, options);
|
|
175
|
-
}
|
|
176
|
-
static fromJsonString(jsonString, options) {
|
|
177
|
-
return new Uint256().fromJsonString(jsonString, options);
|
|
178
|
-
}
|
|
179
|
-
static equals(a, b) {
|
|
180
|
-
return proto3.util.equals(Uint256, a, b);
|
|
181
|
-
}
|
|
182
|
-
}
|
|
183
|
-
/**
|
|
184
|
-
* EncryptedEnvelope wraps an authenticated payload for the covalidator.
|
|
185
|
-
* The covalidator determines the inner plaintext type from the RPC method being called.
|
|
186
|
-
* The payload is serialized into a protobuf message and encrypted using the TEE's public key.
|
|
187
|
-
*
|
|
188
|
-
* @generated from message inco.shield.v2.EncryptedEnvelope
|
|
189
|
-
*/
|
|
190
|
-
export class EncryptedEnvelope extends Message {
|
|
191
|
-
/**
|
|
192
|
-
* The payload bytes, encrypted using the TEE's public key.
|
|
193
|
-
*
|
|
194
|
-
* @generated from field: bytes payload = 1;
|
|
195
|
-
*/
|
|
196
|
-
payload = new Uint8Array(0);
|
|
197
|
-
constructor(data) {
|
|
198
|
-
super();
|
|
199
|
-
proto3.util.initPartial(data, this);
|
|
200
|
-
}
|
|
201
|
-
static runtime = proto3;
|
|
202
|
-
static typeName = "inco.shield.v2.EncryptedEnvelope";
|
|
203
|
-
static fields = proto3.util.newFieldList(() => [
|
|
204
|
-
{ no: 1, name: "payload", kind: "scalar", T: 12 /* ScalarType.BYTES */ },
|
|
205
|
-
]);
|
|
206
|
-
static fromBinary(bytes, options) {
|
|
207
|
-
return new EncryptedEnvelope().fromBinary(bytes, options);
|
|
208
|
-
}
|
|
209
|
-
static fromJson(jsonValue, options) {
|
|
210
|
-
return new EncryptedEnvelope().fromJson(jsonValue, options);
|
|
211
|
-
}
|
|
212
|
-
static fromJsonString(jsonString, options) {
|
|
213
|
-
return new EncryptedEnvelope().fromJsonString(jsonString, options);
|
|
214
|
-
}
|
|
215
|
-
static equals(a, b) {
|
|
216
|
-
return proto3.util.equals(EncryptedEnvelope, a, b);
|
|
217
|
-
}
|
|
218
|
-
}
|
|
219
|
-
/**
|
|
220
|
-
* EncryptedResponse wraps a response payload from the covalidator.
|
|
221
|
-
* The response is serialized into a protobuf message and AEAD-encrypted using the caller's response_key.
|
|
222
|
-
* The nonce and ciphertext are always populated.
|
|
223
|
-
*
|
|
224
|
-
* @generated from message inco.shield.v2.EncryptedResponse
|
|
225
|
-
*/
|
|
226
|
-
export class EncryptedResponse extends Message {
|
|
227
|
-
/**
|
|
228
|
-
* The AEAD nonce used to encrypt the response payload.
|
|
229
|
-
*
|
|
230
|
-
* @generated from field: bytes nonce = 1;
|
|
231
|
-
*/
|
|
232
|
-
nonce = new Uint8Array(0);
|
|
233
|
-
/**
|
|
234
|
-
* The AEAD-encrypted serialized response payload.
|
|
235
|
-
*
|
|
236
|
-
* @generated from field: bytes ciphertext = 2;
|
|
237
|
-
*/
|
|
238
|
-
ciphertext = new Uint8Array(0);
|
|
239
|
-
constructor(data) {
|
|
240
|
-
super();
|
|
241
|
-
proto3.util.initPartial(data, this);
|
|
242
|
-
}
|
|
243
|
-
static runtime = proto3;
|
|
244
|
-
static typeName = "inco.shield.v2.EncryptedResponse";
|
|
245
|
-
static fields = proto3.util.newFieldList(() => [
|
|
246
|
-
{ no: 1, name: "nonce", kind: "scalar", T: 12 /* ScalarType.BYTES */ },
|
|
247
|
-
{ no: 2, name: "ciphertext", kind: "scalar", T: 12 /* ScalarType.BYTES */ },
|
|
248
|
-
]);
|
|
249
|
-
static fromBinary(bytes, options) {
|
|
250
|
-
return new EncryptedResponse().fromBinary(bytes, options);
|
|
251
|
-
}
|
|
252
|
-
static fromJson(jsonValue, options) {
|
|
253
|
-
return new EncryptedResponse().fromJson(jsonValue, options);
|
|
254
|
-
}
|
|
255
|
-
static fromJsonString(jsonString, options) {
|
|
256
|
-
return new EncryptedResponse().fromJsonString(jsonString, options);
|
|
257
|
-
}
|
|
258
|
-
static equals(a, b) {
|
|
259
|
-
return proto3.util.equals(EncryptedResponse, a, b);
|
|
260
|
-
}
|
|
261
|
-
}
|
|
1
|
+
import { fileDesc, messageDesc } from "@bufbuild/protobuf/codegenv2";
|
|
2
|
+
export const file_inco_shield_v2_types = fileDesc("ChppbmNvL3NoaWVsZC92Mi90eXBlcy5wcm90bxIOaW5jby5zaGllbGQudjIiGAoHQWRkcmVzcxINCgV2YWx1ZRgBIAEoDCIYCgdCeXRlczMyEg0KBXZhbHVlGAEgASgMIhcKBkhhbmRsZRINCgV2YWx1ZRgBIAEoDCIYCgdBc3NldElkEg0KBXZhbHVlGAEgASgMIhgKB1VpbnQyNTYSDQoFdmFsdWUYASABKAwiJAoRRW5jcnlwdGVkRW52ZWxvcGUSDwoHcGF5bG9hZBgBIAEoDCJXCgtSZXF1ZXN0QXV0aBIdChBlaXA3MTJfc2lnbmF0dXJlGAEgASgMSACIAQESFAoMcmVzcG9uc2Vfa2V5GAIgASgMQhMKEV9laXA3MTJfc2lnbmF0dXJlIkgKDVNpZ25lZFJlcXVlc3QSKQoEYXV0aBgBIAEoCzIbLmluY28uc2hpZWxkLnYyLlJlcXVlc3RBdXRoEgwKBGJvZHkYAiABKAwiNgoRRW5jcnlwdGVkUmVzcG9uc2USDQoFbm9uY2UYASABKAwSEgoKY2lwaGVydGV4dBgCIAEoDCI1Cg5TaWduZWRSZXNwb25zZRIMCgRib2R5GAEgASgMEhUKDXRlZV9zaWduYXR1cmUYAiABKAxiBnByb3RvMw");
|
|
3
|
+
export const AddressSchema = messageDesc(file_inco_shield_v2_types, 0);
|
|
4
|
+
export const Bytes32Schema = messageDesc(file_inco_shield_v2_types, 1);
|
|
5
|
+
export const HandleSchema = messageDesc(file_inco_shield_v2_types, 2);
|
|
6
|
+
export const AssetIdSchema = messageDesc(file_inco_shield_v2_types, 3);
|
|
7
|
+
export const Uint256Schema = messageDesc(file_inco_shield_v2_types, 4);
|
|
8
|
+
export const EncryptedEnvelopeSchema = messageDesc(file_inco_shield_v2_types, 5);
|
|
9
|
+
export const RequestAuthSchema = messageDesc(file_inco_shield_v2_types, 6);
|
|
10
|
+
export const SignedRequestSchema = messageDesc(file_inco_shield_v2_types, 7);
|
|
11
|
+
export const EncryptedResponseSchema = messageDesc(file_inco_shield_v2_types, 8);
|
|
12
|
+
export const SignedResponseSchema = messageDesc(file_inco_shield_v2_types, 9);
|
package/dist/index.d.ts
CHANGED
|
@@ -1,12 +1,6 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* IncoShield SDK
|
|
3
|
-
*
|
|
4
|
-
* TypeScript SDK for interacting with IncoShield contracts.
|
|
5
|
-
* Works in both browser and Node.js environments.
|
|
6
|
-
*/
|
|
7
1
|
export { bytesToHex, hexToBytes } from './binary.js';
|
|
8
2
|
export * as contracts from './contracts/index.js';
|
|
9
|
-
export { computeErc20AssetId } from './contracts/utils.js';
|
|
3
|
+
export { computeErc20AssetId, ERC20_ASSET_STANDARD, } from './contracts/utils.js';
|
|
10
4
|
export * from './errors.js';
|
|
11
5
|
export * from './shield/index.js';
|
|
12
6
|
export * as abi from './shield/shield.eip712.gen.js';
|
package/dist/index.js
CHANGED
|
@@ -1,19 +1,6 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* IncoShield SDK
|
|
3
|
-
*
|
|
4
|
-
* TypeScript SDK for interacting with IncoShield contracts.
|
|
5
|
-
* Works in both browser and Node.js environments.
|
|
6
|
-
*/
|
|
7
|
-
// Binary helpers
|
|
8
1
|
export { bytesToHex, hexToBytes } from './binary.js';
|
|
9
|
-
// On-chain contract interactions
|
|
10
2
|
export * as contracts from './contracts/index.js';
|
|
11
|
-
export { computeErc20AssetId } from './contracts/utils.js';
|
|
12
|
-
// Tagged error types
|
|
3
|
+
export { computeErc20AssetId, ERC20_ASSET_STANDARD, } from './contracts/utils.js';
|
|
13
4
|
export * from './errors.js';
|
|
14
|
-
// Shield covalidator client
|
|
15
5
|
export * from './shield/index.js';
|
|
16
|
-
// Generated EIP-712 ABI structs and digest helpers
|
|
17
6
|
export * as abi from './shield/shield.eip712.gen.js';
|
|
18
|
-
// The UniswapV4 adapter is exposed via the `@inco/shield-js/uniswap` subpath so
|
|
19
|
-
// its ethers/@uniswap peer dependencies stay optional for core consumers.
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { type Hex } from 'viem';
|
|
2
|
+
import { EIP712_TYPES, type EIP712StructTypes } from './shield.eip712.gen.js';
|
|
3
|
+
export type StructName = keyof typeof EIP712_TYPES;
|
|
4
|
+
export declare function encodeStruct<Name extends StructName>(name: Name, value: EIP712StructTypes[Name]): Hex;
|
|
5
|
+
export declare function decodeStruct<Name extends StructName>(name: Name, data: Hex): EIP712StructTypes[Name];
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { decodeAbiParameters, encodeAbiParameters, } from 'viem';
|
|
2
|
+
import { EIP712_TYPES, } from './shield.eip712.gen.js';
|
|
3
|
+
function isStructName(name) {
|
|
4
|
+
return name in EIP712_TYPES;
|
|
5
|
+
}
|
|
6
|
+
function componentsOf(name) {
|
|
7
|
+
return EIP712_TYPES[name].map((f) => {
|
|
8
|
+
const isArray = f.type.endsWith('[]');
|
|
9
|
+
const elem = isArray ? f.type.slice(0, -2) : f.type;
|
|
10
|
+
if (isStructName(elem)) {
|
|
11
|
+
return {
|
|
12
|
+
name: f.name,
|
|
13
|
+
type: isArray ? 'tuple[]' : 'tuple',
|
|
14
|
+
components: componentsOf(elem),
|
|
15
|
+
};
|
|
16
|
+
}
|
|
17
|
+
return { name: f.name, type: f.type };
|
|
18
|
+
});
|
|
19
|
+
}
|
|
20
|
+
function structTupleParam(name) {
|
|
21
|
+
return { type: 'tuple', components: componentsOf(name) };
|
|
22
|
+
}
|
|
23
|
+
export function encodeStruct(name, value) {
|
|
24
|
+
return encodeAbiParameters([structTupleParam(name)], [value]);
|
|
25
|
+
}
|
|
26
|
+
export function decodeStruct(name, data) {
|
|
27
|
+
return decodeAbiParameters([structTupleParam(name)], data)[0];
|
|
28
|
+
}
|
package/dist/shield/client.d.ts
CHANGED
|
@@ -1,72 +1,48 @@
|
|
|
1
|
-
import { type Hex, type TransactionReceipt } from 'viem';
|
|
2
|
-
import { type
|
|
3
|
-
import type {
|
|
4
|
-
import
|
|
1
|
+
import { type Hex, type TransactionReceipt, type TypedDataDomain } from 'viem';
|
|
2
|
+
import { type UserOperation } from 'viem/account-abstraction';
|
|
3
|
+
import type { UserGasParams } from './intent.js';
|
|
4
|
+
import { type DepositAttestationParams, type GetBalanceParams, type GetPermissionDetailsParams, type GetPermissionsByOwnerParams, type GetPermissionsBySpenderParams, type HistoryPageOptions, type SignedViewingSession, type ViewingSessionParams } from './rpc.js';
|
|
5
|
+
import type { BalanceHistoryResponse, BalanceResponse, DepositAttestation, OwnerGenerationResponse, PermissionAttestation, PermissionDetailsResponse, PermissionListResponse, PermissionRequest, PortfolioHistoryResponse, PortfolioResponse, TransferIntentOp, WithdrawalIntentOp } from './shield.eip712.gen.js';
|
|
6
|
+
import type { ResolvedSigner, ShieldConfig, ShieldSignerInput } from './types.js';
|
|
5
7
|
import type { ENTRYPOINT_VERSION } from './userop/types.js';
|
|
6
8
|
export declare function computeDomainSeparator(chainId: bigint, verifyingContract: Hex): Hex;
|
|
7
|
-
|
|
9
|
+
export declare function shieldDomain(chainId: bigint, verifyingContract: Hex): TypedDataDomain;
|
|
10
|
+
export declare function resolveShieldSigner(signer: ShieldSignerInput): ResolvedSigner;
|
|
8
11
|
export interface ShieldClient {
|
|
9
|
-
issueTransfer(intentOp: TransferIntentOp): Promise<{
|
|
12
|
+
issueTransfer(intentOp: TransferIntentOp, gas?: UserGasParams): Promise<{
|
|
10
13
|
userOp: UserOperation<typeof ENTRYPOINT_VERSION>;
|
|
11
14
|
}>;
|
|
12
|
-
issueWithdraw(intentOp: WithdrawalIntentOp): Promise<{
|
|
15
|
+
issueWithdraw(intentOp: WithdrawalIntentOp, gas?: UserGasParams): Promise<{
|
|
13
16
|
userOp: UserOperation<typeof ENTRYPOINT_VERSION>;
|
|
14
17
|
}>;
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
* TEE-signed `PermissionAttestation` the spender presents on every draft.
|
|
18
|
-
*/
|
|
19
|
-
requestPermissionAttestation(req: PermissionAttestationRequest): Promise<PermissionAttestation>;
|
|
20
|
-
issueDelegatedTransfer(intentOp: TransferIntentOp, attestation: PermissionAttestation): Promise<{
|
|
18
|
+
requestPermissionAttestation(req: PermissionRequest): Promise<PermissionAttestation>;
|
|
19
|
+
issueDelegatedTransfer(intentOp: TransferIntentOp, permissionId: Hex, gas?: UserGasParams): Promise<{
|
|
21
20
|
userOp: UserOperation<typeof ENTRYPOINT_VERSION>;
|
|
22
21
|
}>;
|
|
23
|
-
|
|
24
|
-
issueDelegatedWithdraw(intentOp: WithdrawalIntentOp, attestation: PermissionAttestation): Promise<{
|
|
22
|
+
issueDelegatedWithdraw(intentOp: WithdrawalIntentOp, permissionId: Hex, gas?: UserGasParams): Promise<{
|
|
25
23
|
userOp: UserOperation<typeof ENTRYPOINT_VERSION>;
|
|
26
24
|
}>;
|
|
27
|
-
|
|
25
|
+
createViewingSession(params: ViewingSessionParams): Promise<SignedViewingSession>;
|
|
26
|
+
getBalance(viewing: SignedViewingSession, params: GetBalanceParams): Promise<BalanceResponse>;
|
|
27
|
+
getPortfolio(viewing: SignedViewingSession): Promise<PortfolioResponse>;
|
|
28
|
+
getBalanceHistory(viewing: SignedViewingSession, assetId: Hex, options?: HistoryPageOptions): Promise<BalanceHistoryResponse>;
|
|
29
|
+
getPortfolioHistory(viewing: SignedViewingSession, options?: HistoryPageOptions): Promise<PortfolioHistoryResponse>;
|
|
28
30
|
revokeOne(params: {
|
|
29
31
|
permissionId: Hex;
|
|
30
|
-
}): Promise<{
|
|
32
|
+
}, gas?: UserGasParams): Promise<{
|
|
31
33
|
userOp: UserOperation<typeof ENTRYPOINT_VERSION>;
|
|
32
34
|
}>;
|
|
33
|
-
revokeAll(): Promise<{
|
|
35
|
+
revokeAll(gas?: UserGasParams): Promise<{
|
|
34
36
|
userOp: UserOperation<typeof ENTRYPOINT_VERSION>;
|
|
35
37
|
}>;
|
|
36
|
-
requestDepositAttestation(params:
|
|
37
|
-
getPermissionsByOwner(params
|
|
38
|
-
getPermissionsBySpender(params
|
|
39
|
-
getPermissionDetails(params: GetPermissionDetailsParams): Promise<
|
|
40
|
-
getOwnerGeneration(): Promise<
|
|
41
|
-
|
|
42
|
-
submitUserOp(userOp: UserOperation<typeof ENTRYPOINT_VERSION
|
|
38
|
+
requestDepositAttestation(params: DepositAttestationParams): Promise<DepositAttestation>;
|
|
39
|
+
getPermissionsByOwner(params?: GetPermissionsByOwnerParams): Promise<PermissionListResponse>;
|
|
40
|
+
getPermissionsBySpender(params?: GetPermissionsBySpenderParams): Promise<PermissionListResponse>;
|
|
41
|
+
getPermissionDetails(params: GetPermissionDetailsParams): Promise<PermissionDetailsResponse>;
|
|
42
|
+
getOwnerGeneration(): Promise<OwnerGenerationResponse>;
|
|
43
|
+
getLatestHandle(): Promise<Hex>;
|
|
44
|
+
submitUserOp(userOp: UserOperation<typeof ENTRYPOINT_VERSION>): Promise<{
|
|
43
45
|
receipt: TransactionReceipt;
|
|
44
46
|
}>;
|
|
45
47
|
}
|
|
46
|
-
/**
|
|
47
|
-
* Create a client for the shield covalidator.
|
|
48
|
-
*
|
|
49
|
-
* @example
|
|
50
|
-
* ```ts
|
|
51
|
-
* import { createShieldClient } from "@inco/shield-js";
|
|
52
|
-
* import { createConnectTransport } from "@connectrpc/connect-web";
|
|
53
|
-
* import { privateKeyToAccount } from "viem/accounts";
|
|
54
|
-
*
|
|
55
|
-
* const transport = createConnectTransport({ baseUrl: "http://localhost:50051" });
|
|
56
|
-
* const signer = privateKeyToAccount("0x...");
|
|
57
|
-
*
|
|
58
|
-
* const client = createShieldClient({
|
|
59
|
-
* transport,
|
|
60
|
-
* chainId: BigInt("<your-chain-id>"),
|
|
61
|
-
* shieldAddress: "0x...",
|
|
62
|
-
* signer,
|
|
63
|
-
* });
|
|
64
|
-
*
|
|
65
|
-
* const balance = await client.getBalance({ address: signer.address, assetId: "0x..." });
|
|
66
|
-
* ```
|
|
67
|
-
*/
|
|
68
48
|
export declare function createShieldClient(config: ShieldConfig): Promise<ShieldClient>;
|
|
69
|
-
type SubmitUserOpParams = {
|
|
70
|
-
bundlerClient: BundlerClient;
|
|
71
|
-
};
|
|
72
|
-
export {};
|
package/dist/shield/client.js
CHANGED
|
@@ -1,21 +1,29 @@
|
|
|
1
1
|
import { createClient } from '@connectrpc/connect';
|
|
2
|
-
import { createPublicClient, encodeAbiParameters, http, keccak256, toBytes, } from 'viem';
|
|
3
|
-
import { createBundlerClient, } from 'viem/account-abstraction';
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
2
|
+
import { createPublicClient, encodeAbiParameters, hashTypedData, http, keccak256, toBytes, zeroAddress, } from 'viem';
|
|
3
|
+
import { createBundlerClient, entryPoint07Address, } from 'viem/account-abstraction';
|
|
4
|
+
import { incoShieldAbi } from '../contracts/abi.js';
|
|
5
|
+
import { MissingPaymasterAddress, MissingWalletAccount, ShieldError, } from '../errors.js';
|
|
6
|
+
import { ConductorService } from '../generated/inco/shield/v2/conductor_pb.js';
|
|
6
7
|
import { deserializePublicKey } from './encryption.js';
|
|
7
|
-
import { getBalance, getOwnerGeneration, getPermissionDetails, getPermissionsByOwner, getPermissionsBySpender, issueDelegatedTransfer, issueDelegatedWithdraw, issueTransfer, issueWithdraw, requestDepositAttestation, requestPermissionAttestation, revokeAll, revokeOne, } from './rpc.js';
|
|
8
|
-
import {
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
8
|
+
import { createViewingSession, getBalance, getBalanceHistory, getLatestHandle, getOwnerGeneration, getPermissionDetails, getPermissionsByOwner, getPermissionsBySpender, getPortfolio, getPortfolioHistory, issueDelegatedTransfer, issueDelegatedWithdraw, issueTransfer, issueWithdraw, requestDepositAttestation, requestPermissionAttestation, revokeAll, revokeOne, } from './rpc.js';
|
|
9
|
+
import { getPaymasterAssetAdapter } from './userop/token-exchange.js';
|
|
10
|
+
import { defaultBundlerUrl, getChainFromId } from './utils/chain.js';
|
|
11
|
+
async function resolvePaymasterContext(publicClient, shieldAddress) {
|
|
12
|
+
const paymaster = await publicClient.readContract({
|
|
13
|
+
address: shieldAddress,
|
|
14
|
+
abi: incoShieldAbi,
|
|
15
|
+
functionName: 'paymaster',
|
|
16
|
+
});
|
|
17
|
+
if (paymaster === zeroAddress) {
|
|
18
|
+
throw new MissingPaymasterAddress({
|
|
19
|
+
message: `shield ${shieldAddress} has no paymaster bound (paymaster() returned the zero address); call grantPaymasterRole before constructing a client`,
|
|
20
|
+
});
|
|
21
|
+
}
|
|
22
|
+
const adapter = await getPaymasterAssetAdapter(publicClient, paymaster);
|
|
23
|
+
return { paymaster, adapter };
|
|
15
24
|
}
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
// ---------------------------------------------------------------------------
|
|
25
|
+
const EIP712_DOMAIN_NAME = 'IncoShield';
|
|
26
|
+
const EIP712_DOMAIN_VERSION = '1';
|
|
19
27
|
const EIP712_DOMAIN_TYPEHASH = keccak256(toBytes('EIP712Domain(string name,string version,uint256 chainId,address verifyingContract)'));
|
|
20
28
|
export function computeDomainSeparator(chainId, verifyingContract) {
|
|
21
29
|
return keccak256(encodeAbiParameters([
|
|
@@ -26,12 +34,20 @@ export function computeDomainSeparator(chainId, verifyingContract) {
|
|
|
26
34
|
{ type: 'address' },
|
|
27
35
|
], [
|
|
28
36
|
EIP712_DOMAIN_TYPEHASH,
|
|
29
|
-
keccak256(toBytes(
|
|
30
|
-
keccak256(toBytes(
|
|
37
|
+
keccak256(toBytes(EIP712_DOMAIN_NAME)),
|
|
38
|
+
keccak256(toBytes(EIP712_DOMAIN_VERSION)),
|
|
31
39
|
chainId,
|
|
32
40
|
verifyingContract,
|
|
33
41
|
]));
|
|
34
42
|
}
|
|
43
|
+
export function shieldDomain(chainId, verifyingContract) {
|
|
44
|
+
return {
|
|
45
|
+
name: EIP712_DOMAIN_NAME,
|
|
46
|
+
version: EIP712_DOMAIN_VERSION,
|
|
47
|
+
chainId,
|
|
48
|
+
verifyingContract,
|
|
49
|
+
};
|
|
50
|
+
}
|
|
35
51
|
function isShieldSigner(signer) {
|
|
36
52
|
return ('address' in signer &&
|
|
37
53
|
typeof signer.address === 'string' &&
|
|
@@ -39,9 +55,13 @@ function isShieldSigner(signer) {
|
|
|
39
55
|
typeof signer.sign === 'function' &&
|
|
40
56
|
!('account' in signer));
|
|
41
57
|
}
|
|
42
|
-
function resolveShieldSigner(signer) {
|
|
43
|
-
if (isShieldSigner(signer))
|
|
44
|
-
return
|
|
58
|
+
export function resolveShieldSigner(signer) {
|
|
59
|
+
if (isShieldSigner(signer)) {
|
|
60
|
+
return {
|
|
61
|
+
address: signer.address,
|
|
62
|
+
signTypedData: (typedData) => signer.sign({ hash: hashTypedData(typedData) }),
|
|
63
|
+
};
|
|
64
|
+
}
|
|
45
65
|
const account = signer.account;
|
|
46
66
|
if (!account)
|
|
47
67
|
throw new MissingWalletAccount({
|
|
@@ -49,43 +69,13 @@ function resolveShieldSigner(signer) {
|
|
|
49
69
|
});
|
|
50
70
|
return {
|
|
51
71
|
address: account.address,
|
|
52
|
-
|
|
53
|
-
if ('sign' in account && typeof account.sign === 'function') {
|
|
54
|
-
return account.sign({ hash });
|
|
55
|
-
}
|
|
56
|
-
return signer.signMessage({
|
|
57
|
-
account,
|
|
58
|
-
message: { raw: hash },
|
|
59
|
-
});
|
|
60
|
-
},
|
|
72
|
+
signTypedData: (typedData) => signer.signTypedData({ account, ...typedData }),
|
|
61
73
|
};
|
|
62
74
|
}
|
|
63
|
-
/**
|
|
64
|
-
* Create a client for the shield covalidator.
|
|
65
|
-
*
|
|
66
|
-
* @example
|
|
67
|
-
* ```ts
|
|
68
|
-
* import { createShieldClient } from "@inco/shield-js";
|
|
69
|
-
* import { createConnectTransport } from "@connectrpc/connect-web";
|
|
70
|
-
* import { privateKeyToAccount } from "viem/accounts";
|
|
71
|
-
*
|
|
72
|
-
* const transport = createConnectTransport({ baseUrl: "http://localhost:50051" });
|
|
73
|
-
* const signer = privateKeyToAccount("0x...");
|
|
74
|
-
*
|
|
75
|
-
* const client = createShieldClient({
|
|
76
|
-
* transport,
|
|
77
|
-
* chainId: BigInt("<your-chain-id>"),
|
|
78
|
-
* shieldAddress: "0x...",
|
|
79
|
-
* signer,
|
|
80
|
-
* });
|
|
81
|
-
*
|
|
82
|
-
* const balance = await client.getBalance({ address: signer.address, assetId: "0x..." });
|
|
83
|
-
* ```
|
|
84
|
-
*/
|
|
85
75
|
export async function createShieldClient(config) {
|
|
86
76
|
const chain = getChainFromId(Number(config.chainId));
|
|
87
77
|
const conductorClient = createClient(ConductorService, config.grpcTransport);
|
|
88
|
-
const
|
|
78
|
+
const domain = shieldDomain(config.chainId, config.shieldAddress);
|
|
89
79
|
let teePublicKey;
|
|
90
80
|
try {
|
|
91
81
|
teePublicKey = await deserializePublicKey(config.teePublicKey);
|
|
@@ -97,28 +87,43 @@ export async function createShieldClient(config) {
|
|
|
97
87
|
}
|
|
98
88
|
const signer = resolveShieldSigner(config.signer);
|
|
99
89
|
const bundlerUrl = config.bundlerUrl ?? defaultBundlerUrl(Number(config.chainId));
|
|
90
|
+
const publicClient = createPublicClient({
|
|
91
|
+
chain,
|
|
92
|
+
transport: config.viemTransport ?? http(chain.rpcUrls.default.http[0]),
|
|
93
|
+
});
|
|
100
94
|
const bundlerClient = createBundlerClient({
|
|
101
|
-
client:
|
|
102
|
-
chain,
|
|
103
|
-
transport: config.viemTransport ?? http(chain.rpcUrls.default.http[0]),
|
|
104
|
-
}),
|
|
95
|
+
client: publicClient,
|
|
105
96
|
transport: http(bundlerUrl),
|
|
106
97
|
});
|
|
107
|
-
const
|
|
98
|
+
const paymasterContext = await resolvePaymasterContext(publicClient, config.shieldAddress);
|
|
99
|
+
const ctx = {
|
|
100
|
+
rpc: conductorClient,
|
|
101
|
+
domain,
|
|
102
|
+
signer,
|
|
103
|
+
teePublicKey,
|
|
104
|
+
publicClient,
|
|
105
|
+
shieldConfig: config,
|
|
106
|
+
paymasterContext,
|
|
107
|
+
};
|
|
108
108
|
return {
|
|
109
|
-
issueTransfer: (intentOp) => issueTransfer(ctx, intentOp),
|
|
110
|
-
issueWithdraw: (intentOp) => issueWithdraw(ctx, intentOp),
|
|
109
|
+
issueTransfer: (intentOp, gas) => issueTransfer(ctx, intentOp, gas),
|
|
110
|
+
issueWithdraw: (intentOp, gas) => issueWithdraw(ctx, intentOp, gas),
|
|
111
111
|
requestPermissionAttestation: (params) => requestPermissionAttestation(ctx, params),
|
|
112
|
-
issueDelegatedTransfer: (intentOp,
|
|
113
|
-
issueDelegatedWithdraw: (intentOp,
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
112
|
+
issueDelegatedTransfer: (intentOp, permissionId, gas) => issueDelegatedTransfer(ctx, intentOp, permissionId, gas),
|
|
113
|
+
issueDelegatedWithdraw: (intentOp, permissionId, gas) => issueDelegatedWithdraw(ctx, intentOp, permissionId, gas),
|
|
114
|
+
createViewingSession: (params) => createViewingSession(ctx, params),
|
|
115
|
+
getBalance: (viewing, params) => getBalance(ctx, viewing, params),
|
|
116
|
+
getPortfolio: (viewing) => getPortfolio(ctx, viewing),
|
|
117
|
+
getBalanceHistory: (viewing, assetId, options) => getBalanceHistory(ctx, viewing, assetId, options),
|
|
118
|
+
getPortfolioHistory: (viewing, options) => getPortfolioHistory(ctx, viewing, options),
|
|
119
|
+
revokeOne: (params, gas) => revokeOne(ctx, params, gas),
|
|
120
|
+
revokeAll: (gas) => revokeAll(ctx, gas),
|
|
117
121
|
requestDepositAttestation: (params) => requestDepositAttestation(ctx, params),
|
|
118
122
|
getPermissionsByOwner: (params) => getPermissionsByOwner(ctx, params),
|
|
119
123
|
getPermissionsBySpender: (params) => getPermissionsBySpender(ctx, params),
|
|
120
124
|
getPermissionDetails: (params) => getPermissionDetails(ctx, params),
|
|
121
125
|
getOwnerGeneration: () => getOwnerGeneration(ctx),
|
|
126
|
+
getLatestHandle: () => getLatestHandle(ctx),
|
|
122
127
|
submitUserOp: async (userOp) => {
|
|
123
128
|
return submitUserOp(userOp, {
|
|
124
129
|
bundlerClient,
|
|
@@ -128,7 +133,10 @@ export async function createShieldClient(config) {
|
|
|
128
133
|
}
|
|
129
134
|
async function submitUserOp(userOp, params) {
|
|
130
135
|
const { bundlerClient } = params;
|
|
131
|
-
const userOpHash = await bundlerClient.sendUserOperation(
|
|
136
|
+
const userOpHash = await bundlerClient.sendUserOperation({
|
|
137
|
+
...userOp,
|
|
138
|
+
entryPointAddress: entryPoint07Address,
|
|
139
|
+
});
|
|
132
140
|
const { receipt } = await bundlerClient.waitForUserOperationReceipt({
|
|
133
141
|
hash: userOpHash,
|
|
134
142
|
});
|