@layerzerolabs/lz-core 2.3.44 → 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 +8 -0
- package/dist/index.cjs +0 -120
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.mts +1 -38
- package/dist/index.d.ts +1 -38
- package/dist/index.mjs +1 -92
- package/dist/index.mjs.map +1 -1
- package/package.json +4 -3
package/CHANGELOG.md
CHANGED
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
|
package/dist/index.cjs.map
CHANGED
|
@@ -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;AAEO,SAAS,SAAS,SAA0C;AAC/D,SAAO,UAAU,OAAO;AAC5B;AAEO,SAAS,SAAS,SAA0C;AAC/D,SAAO,QAAQ,OAAO;AAC1B;;;AClBO,IAAK,gBAAL,kBAAKA,mBAAL;AACH,EAAAA,8BA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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;A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F","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,
|
|
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,
|
|
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,
|
|
74
|
+
export { Block, BlockWithTransactions, SignedTransaction, TransactionPending, TransactionReceipt, TransactionRequest, TransactionResponse, isConnectable };
|
|
166
75
|
//# sourceMappingURL=out.js.map
|
|
167
76
|
//# sourceMappingURL=index.mjs.map
|
package/dist/index.mjs.map
CHANGED
|
@@ -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,YAA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AAmE;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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,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.
|
|
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": "^2.3.
|
|
34
|
-
"@layerzerolabs/typescript-config-next": "^2.3.
|
|
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",
|