@layerzerolabs/lz-core 2.3.43 → 2.3.45-oft-rc.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 ADDED
@@ -0,0 +1,368 @@
1
+ # @layerzerolabs/lz-core
2
+
3
+ ## 2.3.45-oft-rc.0
4
+
5
+ ### Patch Changes
6
+
7
+ - 7d63aa8: test
8
+ - Updated dependencies [7d63aa8]
9
+ - @layerzerolabs/lz-foundation@2.3.30-oft-rc.0
10
+
11
+ ## 2.3.44
12
+
13
+ ### Patch Changes
14
+
15
+ - aded88c: Fix issue with workspace:^ protocol in package.json for packages version 2.3.43.
16
+
17
+ ## 2.3.43
18
+
19
+ ### Patch Changes
20
+
21
+ - eced6b4: mainnet: Hedera, testnet: bevm
22
+
23
+ ## 2.3.42
24
+
25
+ ### Patch Changes
26
+
27
+ - 515ca0a: mainnets: Bitlayer, DM2Verse. testnets: morph, ozean
28
+
29
+ ## 2.3.41
30
+
31
+ ### Patch Changes
32
+
33
+ - b01c51c: mainnet: Reya
34
+
35
+ ## 2.3.40
36
+
37
+ ### Patch Changes
38
+
39
+ - c631c6e: mainnet: Ape chain endpoint
40
+
41
+ ## 2.3.39
42
+
43
+ ### Patch Changes
44
+
45
+ - 01a6cb7: testnets: bitlayer, dm2verse, story
46
+
47
+ ## 2.3.38
48
+
49
+ ### Patch Changes
50
+
51
+ - 5ddfb3b: remove `OFT_DEFAULT_PROGRAM_ID` from soalan sdk
52
+
53
+ ## 2.3.37
54
+
55
+ ### Patch Changes
56
+
57
+ - 883c143: mainnet endpoints: Lyra, Codex, testnets: root redeploy, reya
58
+
59
+ ## 2.3.36
60
+
61
+ ### Patch Changes
62
+
63
+ - 291ef75: fix solana sdk
64
+
65
+ ## 2.3.35
66
+
67
+ ### Patch Changes
68
+
69
+ - 9913f53: new endpoints
70
+ - 21a267f: testnets: otherworld, abstract, root
71
+
72
+ ## 2.3.35-aptos.0
73
+
74
+ ### Patch Changes
75
+
76
+ - 7744b25: Add Aptos v1 support in testify, all tests passed.
77
+
78
+ ## 2.3.34
79
+
80
+ ### Patch Changes
81
+
82
+ - 5a99681: Fix an issue in Solana
83
+
84
+ ## 2.3.33
85
+
86
+ ### Patch Changes
87
+
88
+ - d9c0c10: testnets: new solana devnet, codex(evm), bahamut (evm)
89
+ - 1099b5f: testnets: lif3,iota,lyra,lightlink
90
+
91
+ ## 2.3.32
92
+
93
+ ### Patch Changes
94
+
95
+ - e846939: testnets: lif3,iota,lyra,lightlink
96
+ - 334b51e: endpoints, including flare mainnet
97
+ - 334b51e: zklink mainnet, and testnets
98
+ - 334b51e: testnet endpoints
99
+
100
+ ## 2.3.31
101
+
102
+ ### Patch Changes
103
+
104
+ - 29fecfc: testnets: zksyncsep v2 redeploy, curtis
105
+
106
+ ## 2.3.30
107
+
108
+ ### Patch Changes
109
+
110
+ - 32f8ebd: peaq,zircuit mainnet, and plume testnet
111
+ - b602b9f: peaq,zircuit mainnet, and plume testnet
112
+
113
+ ## 2.3.29
114
+
115
+ ### Patch Changes
116
+
117
+ - a42fff0: endpoints, including flare mainnet
118
+ - a42fff0: zklink mainnet, and testnets
119
+ - a42fff0: testnet endpoints
120
+
121
+ ## 2.3.28
122
+
123
+ ### Patch Changes
124
+
125
+ - 23d7ea0: endpoints, including flare mainnet
126
+ - 23d7ea0: zklink mainnet, and testnets
127
+ - 8a40261: Fix some known issues in Solana
128
+ - 23d7ea0: testnet endpoints
129
+
130
+ ## 2.3.27
131
+
132
+ ### Patch Changes
133
+
134
+ - e382bef: Update the access property of the `hardhat-tron` package
135
+ - d41cbe9: endpoints, including flare mainnet
136
+ - d41cbe9: testnet endpoints
137
+
138
+ ## 2.3.26
139
+
140
+ ### Patch Changes
141
+
142
+ - 92a9a2e: upgrade solana mainnet executor/uln
143
+
144
+ ## 2.3.25
145
+
146
+ ### Patch Changes
147
+
148
+ - 003371b: endpoints, including flare mainnet
149
+ - 003371b: testnet endpoints
150
+
151
+ ## 2.3.24
152
+
153
+ ### Patch Changes
154
+
155
+ - 255da39: Fix some known issues in the OFT SDK
156
+
157
+ ## 2.3.23
158
+
159
+ ### Patch Changes
160
+
161
+ - 1e42a63: bump version: default distribution tag is `latest`
162
+ - 43c0e8f: endpoints: bouncebit, gravity ... testnet: bartio bera chain
163
+
164
+ ## 2.3.22
165
+
166
+ ### Patch Changes
167
+
168
+ - 571e2c2: update oft sdk
169
+
170
+ ## 2.3.21
171
+
172
+ ### Patch Changes
173
+
174
+ - 2a5e6c8: fix some bugs & public lz-solana-sdk-v2 & upgrade @solana/web3.js
175
+
176
+ ## 2.3.20
177
+
178
+ ### Patch Changes
179
+
180
+ - 1b332c1: endpoints: taiko,joc,xchain,etherlink, testnet:bouncebit
181
+
182
+ ## 2.3.19
183
+
184
+ ### Patch Changes
185
+
186
+ - 5fce234: minor update & fix some bugs
187
+
188
+ ## 2.3.18
189
+
190
+ ### Patch Changes
191
+
192
+ - d7ddb1e: Make `solana-sdk` compatible with browsers
193
+
194
+ ## 2.3.17
195
+
196
+ ### Patch Changes
197
+
198
+ - 7e1d72a: minor update & fix some bugs
199
+ - a255697: SEI mainnet
200
+
201
+ ## 2.3.16
202
+
203
+ ### Patch Changes
204
+
205
+ - b0ac3fe: deploy & config oft
206
+
207
+ ## 2.3.15
208
+
209
+ ### Patch Changes
210
+
211
+ - 66c554b: minor update & fix some bugs
212
+
213
+ ## 2.3.14
214
+
215
+ ### Patch Changes
216
+
217
+ - minor update
218
+
219
+ ## 2.3.13
220
+
221
+ ### Patch Changes
222
+
223
+ - c294e0e: add missing artifacts
224
+
225
+ ## 2.3.12
226
+
227
+ ### Patch Changes
228
+
229
+ - 2761d43: minor update & fix some bugs
230
+
231
+ ## 2.3.11
232
+
233
+ ### Patch Changes
234
+
235
+ - a7ee3c1: mainnet endpoints, cyber, iota
236
+
237
+ ## 2.3.10
238
+
239
+ ### Patch Changes
240
+
241
+ - b9804e1: export tron and zksync artifacts to sdk
242
+
243
+ ## 2.3.9
244
+
245
+ ### Patch Changes
246
+
247
+ - c208955: minor update & fix some bugs
248
+
249
+ ## 2.3.8
250
+
251
+ ### Patch Changes
252
+
253
+ - e0f5d04: deploy contracts to Ebi mainnet
254
+
255
+ ## 2.3.7
256
+
257
+ ### Patch Changes
258
+
259
+ - 5fa1b78: fix some solana bugs
260
+
261
+ ## 2.3.6
262
+
263
+ ### Patch Changes
264
+
265
+ - 4a92ba6: send and receive with ULN on solana
266
+
267
+ ## 2.3.5
268
+
269
+ ### Patch Changes
270
+
271
+ - 20c33bb: tron v2
272
+
273
+ ## 2.3.4
274
+
275
+ ### Patch Changes
276
+
277
+ - efcf65d: testnet endpoint deployments: Botanix, xchain, ebi
278
+
279
+ ## 2.3.3
280
+
281
+ ### Patch Changes
282
+
283
+ - 44f13a2: endpoints (mainnet): Skale, Bob, Sanko
284
+
285
+ ## 2.3.2
286
+
287
+ ### Patch Changes
288
+
289
+ - bd47f83: testnet endpoints: Bob, Cyber
290
+
291
+ ## 2.3.1
292
+
293
+ ### Patch Changes
294
+
295
+ - c467a80: update RUST_TOOL version and catch errors when checking if chain is ready
296
+
297
+ ## 2.3.0
298
+
299
+ ### Minor Changes
300
+
301
+ - 211e282: add solana to belowzero & build solana snapshot image
302
+
303
+ ## 2.2.6
304
+
305
+ ### Patch Changes
306
+
307
+ - 8ecd2dc: endpoints
308
+
309
+ ## 2.2.5
310
+
311
+ ### Patch Changes
312
+
313
+ - fc047bc: endpoints
314
+
315
+ ## 2.2.4
316
+
317
+ ### Patch Changes
318
+
319
+ - f525086: add non-tron chain back to testify
320
+
321
+ ## 2.2.3
322
+
323
+ ### Patch Changes
324
+
325
+ - 4c53623: empty version
326
+
327
+ ## 2.2.2
328
+
329
+ ### Patch Changes
330
+
331
+ - b04320e: empty version
332
+
333
+ ## 2.2.1
334
+
335
+ ### Patch Changes
336
+
337
+ - fb15753: new endpoints. 4 testnets xlayer, form, ll1, mantasep, 2 mainnet Merlin, Degen
338
+
339
+ ## 2.2.0
340
+
341
+ ### Minor Changes
342
+
343
+ - aa51c78: updated sandbox chain keys for frontend
344
+
345
+ ## 2.1.27
346
+
347
+ ### Patch Changes
348
+
349
+ - 099e19b: internalize common functions and add public onlyOwner passthroughs
350
+
351
+ ## 2.1.25
352
+
353
+ ### Patch Changes
354
+
355
+ - 57fe209: wire ulnv2 during snapshot build
356
+
357
+ ## 2.1.24
358
+
359
+ ### Patch Changes
360
+
361
+ - c663d78: remove duplicate `sleep` func
362
+
363
+ ## 2.1.23
364
+
365
+ ### Patch Changes
366
+
367
+ - c2fc9fe: - update dvn config on blast chain for some dvn partners
368
+ - update OApp, OFT contracts
package/dist/index.cjs CHANGED
@@ -1,117 +1,5 @@
1
1
  'use strict';
2
2
 
3
- var blake2b$1 = require('@noble/hashes/blake2b');
4
- var sha256 = require('@noble/hashes/sha256');
5
- var sha3 = require('@noble/hashes/sha3');
6
- var ed25519 = require('@noble/ed25519');
7
- var secp256k1 = require('@noble/secp256k1');
8
-
9
- function _interopNamespace(e) {
10
- if (e && e.__esModule) return e;
11
- var n = Object.create(null);
12
- if (e) {
13
- Object.keys(e).forEach(function (k) {
14
- if (k !== 'default') {
15
- var d = Object.getOwnPropertyDescriptor(e, k);
16
- Object.defineProperty(n, k, d.get ? d : {
17
- enumerable: true,
18
- get: function () { return e[k]; }
19
- });
20
- }
21
- });
22
- }
23
- n.default = e;
24
- return Object.freeze(n);
25
- }
26
-
27
- var ed25519__namespace = /*#__PURE__*/_interopNamespace(ed25519);
28
- var secp256k1__namespace = /*#__PURE__*/_interopNamespace(secp256k1);
29
-
30
- var __defProp = Object.defineProperty;
31
- var __export = (target, all) => {
32
- for (var name in all)
33
- __defProp(target, name, { get: all[name], enumerable: true });
34
- };
35
- function keccak_256(message) {
36
- return sha3.keccak_256(message);
37
- }
38
- function blake2b(message) {
39
- return blake2b$1.blake2b(message);
40
- }
41
- function sha3_256(message) {
42
- return sha3.sha3_256(message);
43
- }
44
- function sha2_256(message) {
45
- return sha256.sha256(message);
46
- }
47
-
48
- // src/sign/constant.ts
49
- var SignAlgorithm = /* @__PURE__ */ ((SignAlgorithm2) => {
50
- SignAlgorithm2[SignAlgorithm2["NATIVE"] = 0] = "NATIVE";
51
- SignAlgorithm2[SignAlgorithm2["SECP256K1"] = 1] = "SECP256K1";
52
- SignAlgorithm2[SignAlgorithm2["ED25519"] = 2] = "ED25519";
53
- return SignAlgorithm2;
54
- })(SignAlgorithm || {});
55
-
56
- // src/sign/ed25519.ts
57
- var ed25519_exports = {};
58
- __export(ed25519_exports, {
59
- signHash: () => signHash
60
- });
61
- async function signHash(hash, privateKey) {
62
- if (hash.length !== 32) {
63
- throw new Error("Hash must be 32 bytes long");
64
- }
65
- const pubKey = await ed25519__namespace.getPublicKey(privateKey);
66
- const signature = await ed25519__namespace.sign(hash, privateKey);
67
- const isValid = await ed25519__namespace.verify(signature, hash, pubKey);
68
- if (!isValid) {
69
- throw new Error("Invalid signature");
70
- }
71
- return signature;
72
- }
73
-
74
- // src/sign/secp256k1.ts
75
- var secp256k1_exports = {};
76
- __export(secp256k1_exports, {
77
- signHash: () => signHash2
78
- });
79
- async function signHash2(hash, privateKey) {
80
- if (hash.length !== 32) {
81
- throw new Error("Hash must be 32 bytes long");
82
- }
83
- const privKey = privateKey.replace("0x", "");
84
- const pubKey = secp256k1__namespace.getPublicKey(privKey, false);
85
- const [signature, recoveryId] = await secp256k1__namespace.sign(hash, privKey, {
86
- // recovered - true indicates the recovered bit should be included in the result
87
- recovered: true,
88
- // canonical - true makes signatures compatible with libsecp256k1, false makes signatures compatible with openssl
89
- canonical: true,
90
- // der - whether the returned signature should be in DER format. If false, it would be in Compact format (32-byte r + 32-byte s)
91
- der: false,
92
- // extraEntropy - When true, it would automatically be filled with 32 bytes of cryptographically secure entropy. Strongly recommended to pass true to improve security:
93
- extraEntropy: true
94
- });
95
- const isValid = secp256k1__namespace.verify(signature, hash, pubKey, { strict: true });
96
- if (!isValid) {
97
- throw new Error("Invalid signature");
98
- }
99
- return signature;
100
- }
101
-
102
- // src/sign/index.ts
103
- async function signHash3(hash, privateKey, algorithm) {
104
- const privKey = typeof privateKey === "string" ? privateKey.replace(/^0x/, "") : Buffer.from(privateKey).toString("hex");
105
- switch (algorithm) {
106
- case 1 /* SECP256K1 */:
107
- return signHash2(hash, privKey);
108
- case 2 /* ED25519 */:
109
- return signHash(hash, privKey);
110
- default:
111
- throw new Error(`Unsupported algorithm: ${algorithm}`);
112
- }
113
- }
114
-
115
3
  // src/transaction.ts
116
4
  var Block = class _Block {
117
5
  constructor(block) {
@@ -187,19 +75,11 @@ function isConnectable(obj) {
187
75
 
188
76
  exports.Block = Block;
189
77
  exports.BlockWithTransactions = BlockWithTransactions;
190
- exports.SignAlgorithm = SignAlgorithm;
191
78
  exports.SignedTransaction = SignedTransaction;
192
79
  exports.TransactionPending = TransactionPending;
193
80
  exports.TransactionReceipt = TransactionReceipt;
194
81
  exports.TransactionRequest = TransactionRequest;
195
82
  exports.TransactionResponse = TransactionResponse;
196
- exports.blake2b = blake2b;
197
- exports.ed25519 = ed25519_exports;
198
83
  exports.isConnectable = isConnectable;
199
- exports.keccak_256 = keccak_256;
200
- exports.secp256k1 = secp256k1_exports;
201
- exports.sha2_256 = sha2_256;
202
- exports.sha3_256 = sha3_256;
203
- exports.signHash = signHash3;
204
84
  //# sourceMappingURL=out.js.map
205
85
  //# sourceMappingURL=index.cjs.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/hash/index.ts","../src/sign/constant.ts","../src/sign/ed25519.ts","../src/sign/secp256k1.ts","../src/sign/index.ts","../src/transaction.ts","../src/signer.ts"],"names":["SignAlgorithm","signHash"],"mappings":";;;;;;;AAAA,SAAS,WAAW,gBAAgB;AACpC,SAAS,UAAU,eAAe;AAClC,SAAS,cAAc,aAAa,YAAY,iBAAiB;AAE1D,SAAS,WAAW,SAA0C;AACjE,SAAO,YAAY,OAAO;AAC9B;AAEO,SAAS,QAAQ,SAA0C;AAC9D,SAAO,SAAS,OAAO;AAC3B;AAE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AAM,mBAAkB;AAAA,EAEnB,YAAmB,QAAiB;AAAjB;AAD3B,SAAS,OAAO;AAAA,EAC6B;AAAA,EAC7C,OAAO,KAAQ,KAAkE;AAC7E,WAAO,IAAI,mBAAkB,GAAG;AAAA,EACpC;AACJ;AAKO,IAAM,qBAAN,MAAM,oBAAmB;AAAA,EAEpB,YAAmB,SAAkB;AAAlB;AAD3B,SAAS,OAAO;AAAA,EAC8B;AAAA,EAC9C,OAAO,KAAQ,KAAmE;AAC9E,WAAO,IAAI,oBAAmB,GAAG;AAAA,EACrC;AACJ;;;AC7DO,SAAS,cAAiB,KAAqC;AAClE,MAAI,OAAO,QAAQ,YAAY,QAAQ;AAAM,WAAO;AACpD,QAAM,KAAM,IAA8B;AAC1C,SAAO,OAAO,OAAO,cAAc,OAAO,GAAG,WAAW,YAAY,GAAG,WAAW;AACtF","sourcesContent":["import { blake2b as _blake2b } from '@noble/hashes/blake2b'\nimport { sha256 as _sha256 } from '@noble/hashes/sha256'\nimport { keccak_256 as _keccak_256, sha3_256 as _sha3_256 } from '@noble/hashes/sha3'\n\nexport function keccak_256(message: Uint8Array | string): Uint8Array {\n return _keccak_256(message)\n}\n\nexport function blake2b(message: Uint8Array | string): Uint8Array {\n return _blake2b(message)\n}\n\nexport function sha3_256(message: Uint8Array | string): Uint8Array {\n return _sha3_256(message)\n}\n\nexport function sha2_256(message: Uint8Array | string): Uint8Array {\n return _sha256(message)\n}\n","export enum SignAlgorithm {\n NATIVE,\n SECP256K1,\n ED25519,\n}\n","import * as ed25519 from '@noble/ed25519'\n\n/**\n * Sign a hash using ed25519\n * @param hash - 32 bytes long\n * @param privateKey - private key in hex format\n * @returns\n */\nexport async function signHash(hash: Uint8Array, privateKey: string): Promise<Uint8Array> {\n if (hash.length !== 32) {\n throw new Error('Hash must be 32 bytes long')\n }\n\n const pubKey = await ed25519.getPublicKey(privateKey)\n const signature = await ed25519.sign(hash, privateKey)\n const isValid = await ed25519.verify(signature, hash, pubKey)\n if (!isValid) {\n throw new Error('Invalid signature')\n }\n\n return signature\n}\n","import * as secp256k1 from '@noble/secp256k1'\n\n/**\n * Sign a hash using secp256k1\n * @param hash - 32 bytes long\n * @param privateKey - private key in hex format\n * @returns\n */\nexport async function signHash(hash: Uint8Array, privateKey: string): Promise<Uint8Array> {\n if (hash.length !== 32) {\n throw new Error('Hash must be 32 bytes long')\n }\n\n const privKey = privateKey.replace('0x', '')\n const pubKey = secp256k1.getPublicKey(privKey, false)\n\n // refer to: https://github.com/paulmillr/noble-secp256k1/tree/1.7.1#signmsghash-privatekey\n const [signature, recoveryId] = await secp256k1.sign(hash, privKey, {\n // recovered - true indicates the recovered bit should be included in the result\n recovered: true,\n // canonical - true makes signatures compatible with libsecp256k1, false makes signatures compatible with openssl\n canonical: true,\n // der - whether the returned signature should be in DER format. If false, it would be in Compact format (32-byte r + 32-byte s)\n der: false,\n // extraEntropy - When true, it would automatically be filled with 32 bytes of cryptographically secure entropy. Strongly recommended to pass true to improve security:\n extraEntropy: true,\n })\n\n const isValid = secp256k1.verify(signature, hash, pubKey, { strict: true })\n if (!isValid) {\n throw new Error('Invalid signature')\n }\n\n return signature\n}\n","import { SignAlgorithm } from './constant'\nexport * from './constant'\nimport * as ed25519 from './ed25519'\nimport * as secp256k1 from './secp256k1'\n\nexport async function signHash(\n hash: Uint8Array,\n privateKey: string | Uint8Array,\n algorithm: SignAlgorithm\n): Promise<Uint8Array> {\n // privKey should be a hex string without 0x prefix\n // refer to: https://github.com/paulmillr/noble-secp256k1/blob/5ed251242bf065aeb22a54bb42eee1f67e7c77ce/index.ts#L130\n const privKey =\n typeof privateKey === 'string' ? privateKey.replace(/^0x/, '') : Buffer.from(privateKey).toString('hex')\n switch (algorithm) {\n case SignAlgorithm.SECP256K1:\n return secp256k1.signHash(hash, privKey)\n break\n case SignAlgorithm.ED25519:\n return ed25519.signHash(hash, privKey)\n break\n default:\n throw new Error(`Unsupported algorithm: ${algorithm}`)\n }\n}\n\nexport { secp256k1, ed25519 }\n","import { NonPromise } from './promise'\n\n/**\n * By declare a unique field `type` in each class, it ensure that the instance of one class can not\n * be assigned to a variable of another class. Furthermore, it also help to distinguish the type of\n * the instance at runtime.\n * By private the constructor, it ensure that the instance of the class can only be created by the\n * static method `from`, and which can enforce the type of the input parameter should not be a promise.\n * Finally, it will be helpful for the compiler to infer the type of the instance and avoid the mistake.\n */\n\n/**\n * TransactionHash represents a transaction hash.\n */\nexport type TransactionHash = string | number\n\n/**\n * Block represents a block.\n */\nexport class Block {\n readonly type = 'Block'\n private constructor(public block: unknown) {}\n static from<T>(raw: NonPromise<T>): Block {\n return new Block(raw)\n }\n}\n\n/**\n * BlockWithTransactions represents a block with transactions.\n */\nexport class BlockWithTransactions {\n readonly type = 'BlockWithTransactions'\n private constructor(public block: unknown) {}\n static from<T>(raw: NonPromise<T>): BlockWithTransactions {\n return new BlockWithTransactions(raw)\n }\n}\n\n/**\n * BlockTag represents a block tag.\n */\nexport type BlockTag = string | number\n\n/**\n * Finality represents the finality of a block.\n */\nexport type Finality = 'confirmed' | 'finalized'\n\n/**\n * A union type to represent all the possible types of a transaction.\n */\ntype TransactionTypes =\n | TransactionRequest\n | TransactionResponse\n | TransactionReceipt\n | SignedTransaction\n | TransactionPending\n\n/**\n * TransactionRequest represents the request of a transaction.\n */\nexport class TransactionRequest {\n readonly type = 'TransactionRequest'\n private constructor(public request: unknown) {}\n static from<T>(raw: Exclude<NonPromise<T>, TransactionTypes>): TransactionRequest {\n return new TransactionRequest(raw)\n }\n}\n\n/**\n * TransactionResponse represents the response of a transaction.\n */\nexport class TransactionResponse {\n readonly type = 'TransactionResponse'\n private constructor(public response: unknown) {}\n static from<T>(raw: Exclude<NonPromise<T>, TransactionTypes>): TransactionResponse {\n return new TransactionResponse(raw)\n }\n}\n\n/**\n * TransactionReceipt represents the receipt of a transaction.\n */\nexport class TransactionReceipt {\n readonly type = 'TransactionReceipt'\n private constructor(public receipt: unknown) {}\n static from<T>(raw: Exclude<NonPromise<T>, TransactionTypes>): TransactionReceipt {\n return new TransactionReceipt(raw)\n }\n}\n\n/**\n * SignedTransaction represents a signed transaction.\n */\nexport class SignedTransaction {\n readonly type = 'SignedTransaction'\n private constructor(public signed: unknown) {}\n static from<T>(raw: Exclude<NonPromise<T>, TransactionTypes>): SignedTransaction {\n return new SignedTransaction(raw)\n }\n}\n\n/**\n * TransactionPending represents a pending transaction.\n */\nexport class TransactionPending {\n readonly type = 'TransactionPending'\n private constructor(public pending: unknown) {}\n static from<T>(raw: Exclude<NonPromise<T>, TransactionTypes>): TransactionPending {\n return new TransactionPending(raw)\n }\n}\n","import { Provider } from './provider'\nimport { SignedTransaction, TransactionPending, TransactionReceipt, TransactionRequest } from './transaction'\n\nexport interface Signer {\n /**\n * Connect to a provider\n * @param provider\n */\n connect(provider: Provider): Signer\n\n /**\n * Sign a transaction\n * @param transaction\n */\n signTransaction(transaction: TransactionRequest): Promise<SignedTransaction>\n\n /**\n * Send a transaction\n * @param transaction\n * @param sendOptions\n */\n sendTransaction(transaction: SignedTransaction, sendOptions?: unknown): Promise<TransactionPending>\n\n /**\n * Send a transaction and wait for confirmation\n * @param transaction\n * @param opts\n */\n sendAndConfirm(transaction: SignedTransaction, opts?: unknown): Promise<TransactionReceipt>\n\n /**\n * Sign a buffer (e.g. a message hash)\n */\n signBuffer(buffer: Uint8Array): Promise<Uint8Array>\n\n /**\n * returns the address of the signer\n */\n getAddress(): Promise<string>\n\n /**\n * Native signer object\n */\n native: unknown\n}\n\nexport interface Connectable<T> {\n connect<U>(provider: U): T\n}\n\nexport function isConnectable<T>(obj: unknown): obj is Connectable<T> {\n if (typeof obj !== 'object' || obj === null) return false\n const fn = (obj as { connect?: unknown }).connect\n return typeof fn === 'function' && typeof fn.length === 'number' && fn.length === 1\n}\n"]}
1
+ {"version":3,"sources":["../src/transaction.ts","../src/signer.ts"],"names":[],"mappings":";AAmBO,IAAM,QAAN,MAAM,OAAM;AAAA,EAEP,YAAmB,OAAgB;AAAhB;AAD3B,SAAS,OAAO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AiB,KAAqC;AAClE,MAAI,OAAO,QAAQ,YAAY,QAAQ;AAAM,WAAO;AACpD,QAAM,KAAM,IAA8B;AAC1C,SAAO,OAAO,OAAO,cAAc,OAAO,GAAG,WAAW,YAAY,GAAG,WAAW;AACtF","sourcesContent":["import { NonPromise } from './promise'\n\n/**\n * By declare a unique field `type` in each class, it ensure that the instance of one class can not\n * be assigned to a variable of another class. Furthermore, it also help to distinguish the type of\n * the instance at runtime.\n * By private the constructor, it ensure that the instance of the class can only be created by the\n * static method `from`, and which can enforce the type of the input parameter should not be a promise.\n * Finally, it will be helpful for the compiler to infer the type of the instance and avoid the mistake.\n */\n\n/**\n * TransactionHash represents a transaction hash.\n */\nexport type TransactionHash = string | number\n\n/**\n * Block represents a block.\n */\nexport class Block {\n readonly type = 'Block'\n private constructor(public block: unknown) {}\n static from<T>(raw: NonPromise<T>): Block {\n return new Block(raw)\n }\n}\n\n/**\n * BlockWithTransactions represents a block with transactions.\n */\nexport class BlockWithTransactions {\n readonly type = 'BlockWithTransactions'\n private constructor(public block: unknown) {}\n static from<T>(raw: NonPromise<T>): BlockWithTransactions {\n return new BlockWithTransactions(raw)\n }\n}\n\n/**\n * BlockTag represents a block tag.\n */\nexport type BlockTag = string | number\n\n/**\n * Finality represents the finality of a block.\n */\nexport type Finality = 'confirmed' | 'finalized'\n\n/**\n * A union type to represent all the possible types of a transaction.\n */\ntype TransactionTypes =\n | TransactionRequest\n | TransactionResponse\n | TransactionReceipt\n | SignedTransaction\n | TransactionPending\n\n/**\n * TransactionRequest represents the request of a transaction.\n */\nexport class TransactionRequest {\n readonly type = 'TransactionRequest'\n private constructor(public request: unknown) {}\n static from<T>(raw: Exclude<NonPromise<T>, TransactionTypes>): TransactionRequest {\n return new TransactionRequest(raw)\n }\n}\n\n/**\n * TransactionResponse represents the response of a transaction.\n */\nexport class TransactionResponse {\n readonly type = 'TransactionResponse'\n private constructor(public response: unknown) {}\n static from<T>(raw: Exclude<NonPromise<T>, TransactionTypes>): TransactionResponse {\n return new TransactionResponse(raw)\n }\n}\n\n/**\n * TransactionReceipt represents the receipt of a transaction.\n */\nexport class TransactionReceipt {\n readonly type = 'TransactionReceipt'\n private constructor(public receipt: unknown) {}\n static from<T>(raw: Exclude<NonPromise<T>, TransactionTypes>): TransactionReceipt {\n return new TransactionReceipt(raw)\n }\n}\n\n/**\n * SignedTransaction represents a signed transaction.\n */\nexport class SignedTransaction {\n readonly type = 'SignedTransaction'\n private constructor(public signed: unknown) {}\n static from<T>(raw: Exclude<NonPromise<T>, TransactionTypes>): SignedTransaction {\n return new SignedTransaction(raw)\n }\n}\n\n/**\n * TransactionPending represents a pending transaction.\n */\nexport class TransactionPending {\n readonly type = 'TransactionPending'\n private constructor(public pending: unknown) {}\n static from<T>(raw: Exclude<NonPromise<T>, TransactionTypes>): TransactionPending {\n return new TransactionPending(raw)\n }\n}\n","import { Provider } from './provider'\nimport { SignedTransaction, TransactionPending, TransactionReceipt, TransactionRequest } from './transaction'\n\nexport interface Signer {\n /**\n * Connect to a provider\n * @param provider\n */\n connect(provider: Provider): Signer\n\n /**\n * Sign a transaction\n * @param transaction\n */\n signTransaction(transaction: TransactionRequest): Promise<SignedTransaction>\n\n /**\n * Send a transaction\n * @param transaction\n * @param sendOptions\n */\n sendTransaction(transaction: SignedTransaction, sendOptions?: unknown): Promise<TransactionPending>\n\n /**\n * Send a transaction and wait for confirmation\n * @param transaction\n * @param opts\n */\n sendAndConfirm(transaction: SignedTransaction, opts?: unknown): Promise<TransactionReceipt>\n\n /**\n * Sign a buffer (e.g. a message hash)\n */\n signBuffer(buffer: Uint8Array): Promise<Uint8Array>\n\n /**\n * returns the address of the signer\n */\n getAddress(): Promise<string>\n\n /**\n * Native signer object\n */\n native: unknown\n}\n\nexport interface Connectable<T> {\n connect<U>(provider: U): T\n}\n\nexport function isConnectable<T>(obj: unknown): obj is Connectable<T> {\n if (typeof obj !== 'object' || obj === null) return false\n const fn = (obj as { connect?: unknown }).connect\n return typeof fn === 'function' && typeof fn.length === 'number' && fn.length === 1\n}\n"]}
package/dist/index.d.mts CHANGED
@@ -1,40 +1,3 @@
1
- declare function keccak_256(message: Uint8Array | string): Uint8Array;
2
- declare function blake2b(message: Uint8Array | string): Uint8Array;
3
- declare function sha3_256(message: Uint8Array | string): Uint8Array;
4
- declare function sha2_256(message: Uint8Array | string): Uint8Array;
5
-
6
- declare enum SignAlgorithm {
7
- NATIVE = 0,
8
- SECP256K1 = 1,
9
- ED25519 = 2
10
- }
11
-
12
- /**
13
- * Sign a hash using ed25519
14
- * @param hash - 32 bytes long
15
- * @param privateKey - private key in hex format
16
- * @returns
17
- */
18
- declare function signHash$2(hash: Uint8Array, privateKey: string): Promise<Uint8Array>;
19
-
20
- declare namespace ed25519 {
21
- export { signHash$2 as signHash };
22
- }
23
-
24
- /**
25
- * Sign a hash using secp256k1
26
- * @param hash - 32 bytes long
27
- * @param privateKey - private key in hex format
28
- * @returns
29
- */
30
- declare function signHash$1(hash: Uint8Array, privateKey: string): Promise<Uint8Array>;
31
-
32
- declare namespace secp256k1 {
33
- export { signHash$1 as signHash };
34
- }
35
-
36
- declare function signHash(hash: Uint8Array, privateKey: string | Uint8Array, algorithm: SignAlgorithm): Promise<Uint8Array>;
37
-
38
1
  type NonPromise<T> = T extends Promise<unknown> ? never : T;
39
2
 
40
3
  /**
@@ -234,4 +197,4 @@ interface Connectable<T> {
234
197
  }
235
198
  declare function isConnectable<T>(obj: unknown): obj is Connectable<T>;
236
199
 
237
- export { Block, type BlockTag, BlockWithTransactions, type Connectable, type Finality, type Provider, SignAlgorithm, SignedTransaction, type Signer, type TransactionHash, TransactionPending, TransactionReceipt, TransactionRequest, TransactionResponse, blake2b, ed25519, isConnectable, keccak_256, secp256k1, sha2_256, sha3_256, signHash };
200
+ export { Block, type BlockTag, BlockWithTransactions, type Connectable, type Finality, type Provider, SignedTransaction, type Signer, type TransactionHash, TransactionPending, TransactionReceipt, TransactionRequest, TransactionResponse, isConnectable };
package/dist/index.d.ts CHANGED
@@ -1,40 +1,3 @@
1
- declare function keccak_256(message: Uint8Array | string): Uint8Array;
2
- declare function blake2b(message: Uint8Array | string): Uint8Array;
3
- declare function sha3_256(message: Uint8Array | string): Uint8Array;
4
- declare function sha2_256(message: Uint8Array | string): Uint8Array;
5
-
6
- declare enum SignAlgorithm {
7
- NATIVE = 0,
8
- SECP256K1 = 1,
9
- ED25519 = 2
10
- }
11
-
12
- /**
13
- * Sign a hash using ed25519
14
- * @param hash - 32 bytes long
15
- * @param privateKey - private key in hex format
16
- * @returns
17
- */
18
- declare function signHash$2(hash: Uint8Array, privateKey: string): Promise<Uint8Array>;
19
-
20
- declare namespace ed25519 {
21
- export { signHash$2 as signHash };
22
- }
23
-
24
- /**
25
- * Sign a hash using secp256k1
26
- * @param hash - 32 bytes long
27
- * @param privateKey - private key in hex format
28
- * @returns
29
- */
30
- declare function signHash$1(hash: Uint8Array, privateKey: string): Promise<Uint8Array>;
31
-
32
- declare namespace secp256k1 {
33
- export { signHash$1 as signHash };
34
- }
35
-
36
- declare function signHash(hash: Uint8Array, privateKey: string | Uint8Array, algorithm: SignAlgorithm): Promise<Uint8Array>;
37
-
38
1
  type NonPromise<T> = T extends Promise<unknown> ? never : T;
39
2
 
40
3
  /**
@@ -234,4 +197,4 @@ interface Connectable<T> {
234
197
  }
235
198
  declare function isConnectable<T>(obj: unknown): obj is Connectable<T>;
236
199
 
237
- export { Block, type BlockTag, BlockWithTransactions, type Connectable, type Finality, type Provider, SignAlgorithm, SignedTransaction, type Signer, type TransactionHash, TransactionPending, TransactionReceipt, TransactionRequest, TransactionResponse, blake2b, ed25519, isConnectable, keccak_256, secp256k1, sha2_256, sha3_256, signHash };
200
+ export { Block, type BlockTag, BlockWithTransactions, type Connectable, type Finality, type Provider, SignedTransaction, type Signer, type TransactionHash, TransactionPending, TransactionReceipt, TransactionRequest, TransactionResponse, isConnectable };
package/dist/index.mjs CHANGED
@@ -1,94 +1,3 @@
1
- import { blake2b as blake2b$1 } from '@noble/hashes/blake2b';
2
- import { sha256 } from '@noble/hashes/sha256';
3
- import { keccak_256 as keccak_256$1, sha3_256 as sha3_256$1 } from '@noble/hashes/sha3';
4
- import * as ed25519 from '@noble/ed25519';
5
- import * as secp256k1 from '@noble/secp256k1';
6
-
7
- var __defProp = Object.defineProperty;
8
- var __export = (target, all) => {
9
- for (var name in all)
10
- __defProp(target, name, { get: all[name], enumerable: true });
11
- };
12
- function keccak_256(message) {
13
- return keccak_256$1(message);
14
- }
15
- function blake2b(message) {
16
- return blake2b$1(message);
17
- }
18
- function sha3_256(message) {
19
- return sha3_256$1(message);
20
- }
21
- function sha2_256(message) {
22
- return sha256(message);
23
- }
24
-
25
- // src/sign/constant.ts
26
- var SignAlgorithm = /* @__PURE__ */ ((SignAlgorithm2) => {
27
- SignAlgorithm2[SignAlgorithm2["NATIVE"] = 0] = "NATIVE";
28
- SignAlgorithm2[SignAlgorithm2["SECP256K1"] = 1] = "SECP256K1";
29
- SignAlgorithm2[SignAlgorithm2["ED25519"] = 2] = "ED25519";
30
- return SignAlgorithm2;
31
- })(SignAlgorithm || {});
32
-
33
- // src/sign/ed25519.ts
34
- var ed25519_exports = {};
35
- __export(ed25519_exports, {
36
- signHash: () => signHash
37
- });
38
- async function signHash(hash, privateKey) {
39
- if (hash.length !== 32) {
40
- throw new Error("Hash must be 32 bytes long");
41
- }
42
- const pubKey = await ed25519.getPublicKey(privateKey);
43
- const signature = await ed25519.sign(hash, privateKey);
44
- const isValid = await ed25519.verify(signature, hash, pubKey);
45
- if (!isValid) {
46
- throw new Error("Invalid signature");
47
- }
48
- return signature;
49
- }
50
-
51
- // src/sign/secp256k1.ts
52
- var secp256k1_exports = {};
53
- __export(secp256k1_exports, {
54
- signHash: () => signHash2
55
- });
56
- async function signHash2(hash, privateKey) {
57
- if (hash.length !== 32) {
58
- throw new Error("Hash must be 32 bytes long");
59
- }
60
- const privKey = privateKey.replace("0x", "");
61
- const pubKey = secp256k1.getPublicKey(privKey, false);
62
- const [signature, recoveryId] = await secp256k1.sign(hash, privKey, {
63
- // recovered - true indicates the recovered bit should be included in the result
64
- recovered: true,
65
- // canonical - true makes signatures compatible with libsecp256k1, false makes signatures compatible with openssl
66
- canonical: true,
67
- // der - whether the returned signature should be in DER format. If false, it would be in Compact format (32-byte r + 32-byte s)
68
- der: false,
69
- // extraEntropy - When true, it would automatically be filled with 32 bytes of cryptographically secure entropy. Strongly recommended to pass true to improve security:
70
- extraEntropy: true
71
- });
72
- const isValid = secp256k1.verify(signature, hash, pubKey, { strict: true });
73
- if (!isValid) {
74
- throw new Error("Invalid signature");
75
- }
76
- return signature;
77
- }
78
-
79
- // src/sign/index.ts
80
- async function signHash3(hash, privateKey, algorithm) {
81
- const privKey = typeof privateKey === "string" ? privateKey.replace(/^0x/, "") : Buffer.from(privateKey).toString("hex");
82
- switch (algorithm) {
83
- case 1 /* SECP256K1 */:
84
- return signHash2(hash, privKey);
85
- case 2 /* ED25519 */:
86
- return signHash(hash, privKey);
87
- default:
88
- throw new Error(`Unsupported algorithm: ${algorithm}`);
89
- }
90
- }
91
-
92
1
  // src/transaction.ts
93
2
  var Block = class _Block {
94
3
  constructor(block) {
@@ -162,6 +71,6 @@ function isConnectable(obj) {
162
71
  return typeof fn === "function" && typeof fn.length === "number" && fn.length === 1;
163
72
  }
164
73
 
165
- export { Block, BlockWithTransactions, SignAlgorithm, SignedTransaction, TransactionPending, TransactionReceipt, TransactionRequest, TransactionResponse, blake2b, ed25519_exports as ed25519, isConnectable, keccak_256, secp256k1_exports as secp256k1, sha2_256, sha3_256, signHash3 as signHash };
74
+ export { Block, BlockWithTransactions, SignedTransaction, TransactionPending, TransactionReceipt, TransactionRequest, TransactionResponse, isConnectable };
166
75
  //# sourceMappingURL=out.js.map
167
76
  //# sourceMappingURL=index.mjs.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/hash/index.ts","../src/sign/constant.ts","../src/sign/ed25519.ts","../src/sign/secp256k1.ts","../src/sign/index.ts","../src/transaction.ts","../src/signer.ts"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,IAAI,qBAAoB,GAAG;AAAA,EACtC;AACJ;AAKO,IAAM,qBAAN,MAAM,oBAAmB;AAAA,EAEpB,YAAmB,SAAkB;AAAlB;AAD3B,SAAS,OAAO;AAAA,EAC8B;AAAA,EAC9C,OAAO,KAAQ,KAAmE;AAC9E,WAAO,IAAI,oBAAmB,GAAG;AAAA,EACrC;AACJ;AAKO,IAAM,oBAAN,MAAM,mBAAkB;AAAA,EAEnB,YAAmB,QAAiB;AAAjB;AAD3B,SAAS,OAAO;AAAA,EAC6B;AAAA,EAC7C,OAAO,KAAQ,KAAkE;AAC7E,WAAO,IAAI,mBAAkB,GAAG;AAAA,EACpC;AACJ;AAKO,IAAM,qBAAN,MAAM,oBAAmB;AAAA,EAEpB,YAAmB,SAAkB;AAAlB;AAD3B,SAAS,OAAO;AAAA,EAC8B;AAAA,EAC9C,OAAO,KAAQ,KAAmE;AAC9E,WAAO,IAAI,oBAAmB,GAAG;AAAA,EACrC;AACJ;;;AC7DO,SAAS,cAAiB,KAAqC;AAClE,MAAI,OAAO,QAAQ,YAAY,QAAQ;AAAM,WAAO;AACpD,QAAM,KAAM,IAA8B;AAC1C,SAAO,OAAO,OAAO,cAAc,OAAO,GAAG,WAAW,YAAY,GAAG,WAAW;AACtF","sourcesContent":["import { blake2b as _blake2b } from '@noble/hashes/blake2b'\nimport { sha256 as _sha256 } from '@noble/hashes/sha256'\nimport { keccak_256 as _keccak_256, sha3_256 as _sha3_256 } from '@noble/hashes/sha3'\n\nexport function keccak_256(message: Uint8Array | string): Uint8Array {\n return _keccak_256(message)\n}\n\nexport function blake2b(message: Uint8Array | string): Uint8Array {\n return _blake2b(message)\n}\n\nexport function sha3_256(message: Uint8Array | string): Uint8Array {\n return _sha3_256(message)\n}\n\nexport function sha2_256(message: Uint8Array | string): Uint8Array {\n return _sha256(message)\n}\n","export enum SignAlgorithm {\n NATIVE,\n SECP256K1,\n ED25519,\n}\n","import * as ed25519 from '@noble/ed25519'\n\n/**\n * Sign a hash using ed25519\n * @param hash - 32 bytes long\n * @param privateKey - private key in hex format\n * @returns\n */\nexport async function signHash(hash: Uint8Array, privateKey: string): Promise<Uint8Array> {\n if (hash.length !== 32) {\n throw new Error('Hash must be 32 bytes long')\n }\n\n const pubKey = await ed25519.getPublicKey(privateKey)\n const signature = await ed25519.sign(hash, privateKey)\n const isValid = await ed25519.verify(signature, hash, pubKey)\n if (!isValid) {\n throw new Error('Invalid signature')\n }\n\n return signature\n}\n","import * as secp256k1 from '@noble/secp256k1'\n\n/**\n * Sign a hash using secp256k1\n * @param hash - 32 bytes long\n * @param privateKey - private key in hex format\n * @returns\n */\nexport async function signHash(hash: Uint8Array, privateKey: string): Promise<Uint8Array> {\n if (hash.length !== 32) {\n throw new Error('Hash must be 32 bytes long')\n }\n\n const privKey = privateKey.replace('0x', '')\n const pubKey = secp256k1.getPublicKey(privKey, false)\n\n // refer to: https://github.com/paulmillr/noble-secp256k1/tree/1.7.1#signmsghash-privatekey\n const [signature, recoveryId] = await secp256k1.sign(hash, privKey, {\n // recovered - true indicates the recovered bit should be included in the result\n recovered: true,\n // canonical - true makes signatures compatible with libsecp256k1, false makes signatures compatible with openssl\n canonical: true,\n // der - whether the returned signature should be in DER format. If false, it would be in Compact format (32-byte r + 32-byte s)\n der: false,\n // extraEntropy - When true, it would automatically be filled with 32 bytes of cryptographically secure entropy. Strongly recommended to pass true to improve security:\n extraEntropy: true,\n })\n\n const isValid = secp256k1.verify(signature, hash, pubKey, { strict: true })\n if (!isValid) {\n throw new Error('Invalid signature')\n }\n\n return signature\n}\n","import { SignAlgorithm } from './constant'\nexport * from './constant'\nimport * as ed25519 from './ed25519'\nimport * as secp256k1 from './secp256k1'\n\nexport async function signHash(\n hash: Uint8Array,\n privateKey: string | Uint8Array,\n algorithm: SignAlgorithm\n): Promise<Uint8Array> {\n // privKey should be a hex string without 0x prefix\n // refer to: https://github.com/paulmillr/noble-secp256k1/blob/5ed251242bf065aeb22a54bb42eee1f67e7c77ce/index.ts#L130\n const privKey =\n typeof privateKey === 'string' ? privateKey.replace(/^0x/, '') : Buffer.from(privateKey).toString('hex')\n switch (algorithm) {\n case SignAlgorithm.SECP256K1:\n return secp256k1.signHash(hash, privKey)\n break\n case SignAlgorithm.ED25519:\n return ed25519.signHash(hash, privKey)\n break\n default:\n throw new Error(`Unsupported algorithm: ${algorithm}`)\n }\n}\n\nexport { secp256k1, ed25519 }\n","import { NonPromise } from './promise'\n\n/**\n * By declare a unique field `type` in each class, it ensure that the instance of one class can not\n * be assigned to a variable of another class. Furthermore, it also help to distinguish the type of\n * the instance at runtime.\n * By private the constructor, it ensure that the instance of the class can only be created by the\n * static method `from`, and which can enforce the type of the input parameter should not be a promise.\n * Finally, it will be helpful for the compiler to infer the type of the instance and avoid the mistake.\n */\n\n/**\n * TransactionHash represents a transaction hash.\n */\nexport type TransactionHash = string | number\n\n/**\n * Block represents a block.\n */\nexport class Block {\n readonly type = 'Block'\n private constructor(public block: unknown) {}\n static from<T>(raw: NonPromise<T>): Block {\n return new Block(raw)\n }\n}\n\n/**\n * BlockWithTransactions represents a block with transactions.\n */\nexport class BlockWithTransactions {\n readonly type = 'BlockWithTransactions'\n private constructor(public block: unknown) {}\n static from<T>(raw: NonPromise<T>): BlockWithTransactions {\n return new BlockWithTransactions(raw)\n }\n}\n\n/**\n * BlockTag represents a block tag.\n */\nexport type BlockTag = string | number\n\n/**\n * Finality represents the finality of a block.\n */\nexport type Finality = 'confirmed' | 'finalized'\n\n/**\n * A union type to represent all the possible types of a transaction.\n */\ntype TransactionTypes =\n | TransactionRequest\n | TransactionResponse\n | TransactionReceipt\n | SignedTransaction\n | TransactionPending\n\n/**\n * TransactionRequest represents the request of a transaction.\n */\nexport class TransactionRequest {\n readonly type = 'TransactionRequest'\n private constructor(public request: unknown) {}\n static from<T>(raw: Exclude<NonPromise<T>, TransactionTypes>): TransactionRequest {\n return new TransactionRequest(raw)\n }\n}\n\n/**\n * TransactionResponse represents the response of a transaction.\n */\nexport class TransactionResponse {\n readonly type = 'TransactionResponse'\n private constructor(public response: unknown) {}\n static from<T>(raw: Exclude<NonPromise<T>, TransactionTypes>): TransactionResponse {\n return new TransactionResponse(raw)\n }\n}\n\n/**\n * TransactionReceipt represents the receipt of a transaction.\n */\nexport class TransactionReceipt {\n readonly type = 'TransactionReceipt'\n private constructor(public receipt: unknown) {}\n static from<T>(raw: Exclude<NonPromise<T>, TransactionTypes>): TransactionReceipt {\n return new TransactionReceipt(raw)\n }\n}\n\n/**\n * SignedTransaction represents a signed transaction.\n */\nexport class SignedTransaction {\n readonly type = 'SignedTransaction'\n private constructor(public signed: unknown) {}\n static from<T>(raw: Exclude<NonPromise<T>, TransactionTypes>): SignedTransaction {\n return new SignedTransaction(raw)\n }\n}\n\n/**\n * TransactionPending represents a pending transaction.\n */\nexport class TransactionPending {\n readonly type = 'TransactionPending'\n private constructor(public pending: unknown) {}\n static from<T>(raw: Exclude<NonPromise<T>, TransactionTypes>): TransactionPending {\n return new TransactionPending(raw)\n }\n}\n","import { Provider } from './provider'\nimport { SignedTransaction, TransactionPending, TransactionReceipt, TransactionRequest } from './transaction'\n\nexport interface Signer {\n /**\n * Connect to a provider\n * @param provider\n */\n connect(provider: Provider): Signer\n\n /**\n * Sign a transaction\n * @param transaction\n */\n signTransaction(transaction: TransactionRequest): Promise<SignedTransaction>\n\n /**\n * Send a transaction\n * @param transaction\n * @param sendOptions\n */\n sendTransaction(transaction: SignedTransaction, sendOptions?: unknown): Promise<TransactionPending>\n\n /**\n * Send a transaction and wait for confirmation\n * @param transaction\n * @param opts\n */\n sendAndConfirm(transaction: SignedTransaction, opts?: unknown): Promise<TransactionReceipt>\n\n /**\n * Sign a buffer (e.g. a message hash)\n */\n signBuffer(buffer: Uint8Array): Promise<Uint8Array>\n\n /**\n * returns the address of the signer\n */\n getAddress(): Promise<string>\n\n /**\n * Native signer object\n */\n native: unknown\n}\n\nexport interface Connectable<T> {\n connect<U>(provider: U): T\n}\n\nexport function isConnectable<T>(obj: unknown): obj is Connectable<T> {\n if (typeof obj !== 'object' || obj === null) return false\n const fn = (obj as { connect?: unknown }).connect\n return typeof fn === 'function' && typeof fn.length === 'number' && fn.length === 1\n}\n"]}
1
+ {"version":3,"sources":["../src/transaction.ts","../src/signer.ts"],"names":[],"mappings":";AAmBO,IAAM,QAAN,MAAM,OAAM;AAAA,EAEP,YAAmB,OAAgB;AAAhB;AAD3B,SAAS,OAAO;AAAA,EAC4B;AAAA,EAC5C,OAAO,KAAQ,KAA2B;AACtC,WAAO,IAAI,OAAM,GAAG;AAAA,EACxB;AACJ;AAKO,IAAM,wBAAN,MAAM,uBAAsB;AAAA,EAEvB,YAAmB,OAAgB;AAAhB;AAD3B,SAAS,OAAO;AAAA,EAC4B;AAAA,EAC5C,OAAO,KAAQ,KAA2C;AACtD,WAAO,IAAI,uBAAsB,GAAG;AAAA,EACxC;AACJ;AAyBO,IAAM,qBAAN,MAAM,oBAAmB;AAAA,EAEpB,YAAmB,SAAkB;AAAlB;AAD3B,SAAS,OAAO;AAAA,EAC8B;AAAA,EAC9C,OAAO,KAAQ,KAAmE;AAC9E,WAAO,IAAI,oBAAmB,GAAG;AAAA,EACrC;AACJ;AAKO,IAAM,sBAAN,MAAM,qBAAoB;AAAA,EAErB,YAAmB,UAAmB;AAAnB;AAD3B,SAAS,OAAO;AAAA,EAC+B;AAAA,EAC/C,OAAO,KAAQ,KAAoE;AAC/E,WAAO,IAAI,qBAAoB,GAAG;AAAA,EACtC;AACJ;AAKO,IAAM,qBAAN,MAAM,oBAAmB;AAAA,EAEpB,YAAmB,SAAkB;AAAlB;AAD3B,SAAS,OAAO;AAAA,EAC8B;AAAA,EAC9C,OAAO,KAAQ,KAAmE;AAC9E,WAAO,IAAI,oBAAmB,GAAG;AAAA,EACrC;AACJ;AAKO,IAAM,oBAAN,MAAM,mBAAkB;AAAA,EAEnB,YAAmB,QAAiB;AAAjB;AAD3B,SAAS,OAAO;AAAA,EAC6B;AAAA,EAC7C,OAAO,KAAQ,KAAkE;AAC7E,WAAO,IAAI,mBAAkB,GAAG;AAAA,EACpC;AACJ;AAKO,IAAM,qBAAN,MAAM,oBAAmB;AAAA,EAEpB,YAAmB,SAAkB;AAAlB;AAD3B,SAAS,OAAO;AAAA,EAC8B;AAAA,EAC9C,OAAO,KAAQ,KAAmE;AAC9E,WAAO,IAAI,oBAAmB,GAAG;AAAA,EACrC;AACJ;;;AC7DO,SAAS,cAAiB,KAAqC;AAClE,MAAI,OAAO,QAAQ,YAAY,QAAQ;AAAM,WAAO;AACpD,QAAM,KAAM,IAA8B;AAC1C,SAAO,OAAO,OAAO,cAAc,OAAO,GAAG,WAAW,YAAY,GAAG,WAAW;AACtF","sourcesContent":["import { NonPromise } from './promise'\n\n/**\n * By declare a unique field `type` in each class, it ensure that the instance of one class can not\n * be assigned to a variable of another class. Furthermore, it also help to distinguish the type of\n * the instance at runtime.\n * By private the constructor, it ensure that the instance of the class can only be created by the\n * static method `from`, and which can enforce the type of the input parameter should not be a promise.\n * Finally, it will be helpful for the compiler to infer the type of the instance and avoid the mistake.\n */\n\n/**\n * TransactionHash represents a transaction hash.\n */\nexport type TransactionHash = string | number\n\n/**\n * Block represents a block.\n */\nexport class Block {\n readonly type = 'Block'\n private constructor(public block: unknown) {}\n static from<T>(raw: NonPromise<T>): Block {\n return new Block(raw)\n }\n}\n\n/**\n * BlockWithTransactions represents a block with transactions.\n */\nexport class BlockWithTransactions {\n readonly type = 'BlockWithTransactions'\n private constructor(public block: unknown) {}\n static from<T>(raw: NonPromise<T>): BlockWithTransactions {\n return new BlockWithTransactions(raw)\n }\n}\n\n/**\n * BlockTag represents a block tag.\n */\nexport type BlockTag = string | number\n\n/**\n * Finality represents the finality of a block.\n */\nexport type Finality = 'confirmed' | 'finalized'\n\n/**\n * A union type to represent all the possible types of a transaction.\n */\ntype TransactionTypes =\n | TransactionRequest\n | TransactionResponse\n | TransactionReceipt\n | SignedTransaction\n | TransactionPending\n\n/**\n * TransactionRequest represents the request of a transaction.\n */\nexport class TransactionRequest {\n readonly type = 'TransactionRequest'\n private constructor(public request: unknown) {}\n static from<T>(raw: Exclude<NonPromise<T>, TransactionTypes>): TransactionRequest {\n return new TransactionRequest(raw)\n }\n}\n\n/**\n * TransactionResponse represents the response of a transaction.\n */\nexport class TransactionResponse {\n readonly type = 'TransactionResponse'\n private constructor(public response: unknown) {}\n static from<T>(raw: Exclude<NonPromise<T>, TransactionTypes>): TransactionResponse {\n return new TransactionResponse(raw)\n }\n}\n\n/**\n * TransactionReceipt represents the receipt of a transaction.\n */\nexport class TransactionReceipt {\n readonly type = 'TransactionReceipt'\n private constructor(public receipt: unknown) {}\n static from<T>(raw: Exclude<NonPromise<T>, TransactionTypes>): TransactionReceipt {\n return new TransactionReceipt(raw)\n }\n}\n\n/**\n * SignedTransaction represents a signed transaction.\n */\nexport class SignedTransaction {\n readonly type = 'SignedTransaction'\n private constructor(public signed: unknown) {}\n static from<T>(raw: Exclude<NonPromise<T>, TransactionTypes>): SignedTransaction {\n return new SignedTransaction(raw)\n }\n}\n\n/**\n * TransactionPending represents a pending transaction.\n */\nexport class TransactionPending {\n readonly type = 'TransactionPending'\n private constructor(public pending: unknown) {}\n static from<T>(raw: Exclude<NonPromise<T>, TransactionTypes>): TransactionPending {\n return new TransactionPending(raw)\n }\n}\n","import { Provider } from './provider'\nimport { SignedTransaction, TransactionPending, TransactionReceipt, TransactionRequest } from './transaction'\n\nexport interface Signer {\n /**\n * Connect to a provider\n * @param provider\n */\n connect(provider: Provider): Signer\n\n /**\n * Sign a transaction\n * @param transaction\n */\n signTransaction(transaction: TransactionRequest): Promise<SignedTransaction>\n\n /**\n * Send a transaction\n * @param transaction\n * @param sendOptions\n */\n sendTransaction(transaction: SignedTransaction, sendOptions?: unknown): Promise<TransactionPending>\n\n /**\n * Send a transaction and wait for confirmation\n * @param transaction\n * @param opts\n */\n sendAndConfirm(transaction: SignedTransaction, opts?: unknown): Promise<TransactionReceipt>\n\n /**\n * Sign a buffer (e.g. a message hash)\n */\n signBuffer(buffer: Uint8Array): Promise<Uint8Array>\n\n /**\n * returns the address of the signer\n */\n getAddress(): Promise<string>\n\n /**\n * Native signer object\n */\n native: unknown\n}\n\nexport interface Connectable<T> {\n connect<U>(provider: U): T\n}\n\nexport function isConnectable<T>(obj: unknown): obj is Connectable<T> {\n if (typeof obj !== 'object' || obj === null) return false\n const fn = (obj as { connect?: unknown }).connect\n return typeof fn === 'function' && typeof fn.length === 'number' && fn.length === 1\n}\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@layerzerolabs/lz-core",
3
- "version": "2.3.43",
3
+ "version": "2.3.45-oft-rc.0",
4
4
  "description": "LayerZero Core Library",
5
5
  "license": "BUSL-1.1",
6
6
  "exports": {
@@ -23,6 +23,7 @@
23
23
  "clean-prebuild": "rimraf dist"
24
24
  },
25
25
  "dependencies": {
26
+ "@layerzerolabs/lz-foundation": "^2.3.30-oft-rc.0",
26
27
  "@noble/ed25519": "^1.7.1",
27
28
  "@noble/hashes": "^1.3.2",
28
29
  "@noble/secp256k1": "^1.7.1",
@@ -30,8 +31,8 @@
30
31
  },
31
32
  "devDependencies": {
32
33
  "@jest/globals": "^29.7.0",
33
- "@layerzerolabs/tsup-config-next": "workspace:^",
34
- "@layerzerolabs/typescript-config-next": "workspace:^",
34
+ "@layerzerolabs/tsup-config-next": "^2.3.45-oft-rc.0",
35
+ "@layerzerolabs/typescript-config-next": "^2.3.45-oft-rc.0",
35
36
  "@types/jest": "^29.5.10",
36
37
  "jest": "^29.7.0",
37
38
  "rimraf": "^5.0.5",
@@ -42,4 +43,4 @@
42
43
  "publishConfig": {
43
44
  "access": "public"
44
45
  }
45
- }
46
+ }