@layerzerolabs/lz-core 3.0.15 → 3.0.16
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 +6 -0
- package/README.md +157 -1
- package/dist/index.cjs +42 -0
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.mts +149 -44
- package/dist/index.d.ts +149 -44
- package/dist/index.mjs +42 -0
- package/dist/index.mjs.map +1 -1
- package/package.json +3 -10
package/CHANGELOG.md
CHANGED
package/README.md
CHANGED
|
@@ -1,8 +1,164 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @layerzerolabs/lz-core
|
|
2
2
|
|
|
3
3
|
This package defines the core interface for the tooling stack, containing only neutral interfaces that are unrelated to the LayerZero protocol.
|
|
4
4
|
|
|
5
|
+
## Features
|
|
6
|
+
|
|
5
7
|
- `Transaction` Interface: Used for expressing transactions in different stages.
|
|
6
8
|
- `Provider` Interface: Defines the connectors to a chain node.
|
|
7
9
|
- `Signer` Interface: Handles message and transaction signing.
|
|
8
10
|
- The `signHash` function is implemented in this package instead of `lz-utilities` or `lz-foundation` to minimize dependencies.
|
|
11
|
+
|
|
12
|
+
## Installation
|
|
13
|
+
|
|
14
|
+
To install the LayerZero Core package, you can use npm or yarn:
|
|
15
|
+
|
|
16
|
+
```sh
|
|
17
|
+
npm install @layerzerolabs/lz-core
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
or
|
|
21
|
+
|
|
22
|
+
```sh
|
|
23
|
+
yarn add @layerzerolabs/lz-core
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
## Usage
|
|
27
|
+
|
|
28
|
+
### Transaction Interfaces
|
|
29
|
+
|
|
30
|
+
#### TransactionRequest
|
|
31
|
+
|
|
32
|
+
Represents the request of a transaction.
|
|
33
|
+
|
|
34
|
+
```typescript
|
|
35
|
+
import { TransactionRequest } from "@layerzerolabs/lz-core";
|
|
36
|
+
|
|
37
|
+
const request = TransactionRequest.from({
|
|
38
|
+
to: "0xRecipientAddress",
|
|
39
|
+
value: "1000000000000000000", // 1 ETH
|
|
40
|
+
});
|
|
41
|
+
console.log(`Transaction Request: ${JSON.stringify(request)}`);
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
#### TransactionResponse
|
|
45
|
+
|
|
46
|
+
Represents the response of a transaction.
|
|
47
|
+
|
|
48
|
+
```typescript
|
|
49
|
+
import { TransactionResponse } from "@layerzerolabs/lz-core";
|
|
50
|
+
|
|
51
|
+
const response = TransactionResponse.from({
|
|
52
|
+
hash: "0xTransactionHash",
|
|
53
|
+
status: 1,
|
|
54
|
+
});
|
|
55
|
+
console.log(`Transaction Response: ${JSON.stringify(response)}`);
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
### Provider Interface
|
|
59
|
+
|
|
60
|
+
Defines the connectors to a chain node.
|
|
61
|
+
|
|
62
|
+
```typescript
|
|
63
|
+
import { Provider } from "@layerzerolabs/lz-core";
|
|
64
|
+
|
|
65
|
+
class MyProvider implements Provider {
|
|
66
|
+
url = "https://mainnet.infura.io/v3/YOUR_INFURA_PROJECT_ID";
|
|
67
|
+
|
|
68
|
+
async getBlock(blockTag) {
|
|
69
|
+
// Implementation to get block
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
async getBlockWithTransactions(blockTag) {
|
|
73
|
+
// Implementation to get block with transactions
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
async getTransaction(txHash) {
|
|
77
|
+
// Implementation to get transaction
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
async getTransactionReceipt(txHash) {
|
|
81
|
+
// Implementation to get transaction receipt
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
async getBlockNumber() {
|
|
85
|
+
// Implementation to get block number
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
async getSlot(commitment) {
|
|
89
|
+
// Implementation to get slot
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
async getTransactionCount(addressOrName, blockTag) {
|
|
93
|
+
// Implementation to get transaction count
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
async getBalance(address) {
|
|
97
|
+
// Implementation to get balance
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
async getBlockTimestamp(blockTag) {
|
|
101
|
+
// Implementation to get block timestamp
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
async sendTransaction(transaction, sendOptions) {
|
|
105
|
+
// Implementation to send transaction
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
async confirmTransaction(pending, opts) {
|
|
109
|
+
// Implementation to confirm transaction
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
async sendAndConfirm(transaction, opts) {
|
|
113
|
+
// Implementation to send and confirm transaction
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
readonly native = {}; // Native provider instance
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
const provider = new MyProvider();
|
|
120
|
+
console.log(`Provider URL: ${provider.url}`);
|
|
121
|
+
```
|
|
122
|
+
|
|
123
|
+
### Signer Interface
|
|
124
|
+
|
|
125
|
+
Handles message and transaction signing.
|
|
126
|
+
|
|
127
|
+
```typescript
|
|
128
|
+
import { Signer, TransactionRequest, SignedTransaction, TransactionPending, TransactionReceipt } from "@layerzerolabs/lz-core";
|
|
129
|
+
|
|
130
|
+
class MySigner implements Signer {
|
|
131
|
+
async connect(provider) {
|
|
132
|
+
// Implementation to connect to provider
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
async buildTransaction(buildTxRequest) {
|
|
136
|
+
// Implementation to build transaction
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
async signTransaction(transaction) {
|
|
140
|
+
// Implementation to sign transaction
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
async sendTransaction(transaction, sendOptions) {
|
|
144
|
+
// Implementation to send transaction
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
async sendAndConfirm(transaction, opts) {
|
|
148
|
+
// Implementation to send and confirm transaction
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
async signBuffer(buffer) {
|
|
152
|
+
// Implementation to sign buffer
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
async getAddress() {
|
|
156
|
+
// Implementation to get address
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
native = {}; // Native signer instance
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
const signer = new MySigner();
|
|
163
|
+
console.log(`Signer Address: ${await signer.getAddress()}`);
|
|
164
|
+
```
|
package/dist/index.cjs
CHANGED
|
@@ -6,6 +6,12 @@ var Block = class _Block {
|
|
|
6
6
|
this.block = block;
|
|
7
7
|
this.type = "Block";
|
|
8
8
|
}
|
|
9
|
+
/**
|
|
10
|
+
* Creates an instance of Block from a non-promise value.
|
|
11
|
+
*
|
|
12
|
+
* @param {NonPromise<T>} raw - The raw value to create the Block from.
|
|
13
|
+
* @returns {Block} The created Block instance.
|
|
14
|
+
*/
|
|
9
15
|
static from(raw) {
|
|
10
16
|
return new _Block(raw);
|
|
11
17
|
}
|
|
@@ -15,6 +21,12 @@ var BlockWithTransactions = class _BlockWithTransactions {
|
|
|
15
21
|
this.block = block;
|
|
16
22
|
this.type = "BlockWithTransactions";
|
|
17
23
|
}
|
|
24
|
+
/**
|
|
25
|
+
* Creates an instance of BlockWithTransactions from a non-promise value.
|
|
26
|
+
*
|
|
27
|
+
* @param {NonPromise<T>} raw - The raw value to create the BlockWithTransactions from.
|
|
28
|
+
* @returns {BlockWithTransactions} The created BlockWithTransactions instance.
|
|
29
|
+
*/
|
|
18
30
|
static from(raw) {
|
|
19
31
|
return new _BlockWithTransactions(raw);
|
|
20
32
|
}
|
|
@@ -24,6 +36,12 @@ var TransactionRequest = class _TransactionRequest {
|
|
|
24
36
|
this.request = request;
|
|
25
37
|
this.type = "TransactionRequest";
|
|
26
38
|
}
|
|
39
|
+
/**
|
|
40
|
+
* Creates an instance of TransactionRequest from a non-promise value.
|
|
41
|
+
*
|
|
42
|
+
* @param {Exclude<NonPromise<T>, TransactionTypes>} raw - The raw value to create the TransactionRequest from.
|
|
43
|
+
* @returns {TransactionRequest} The created TransactionRequest instance.
|
|
44
|
+
*/
|
|
27
45
|
static from(raw) {
|
|
28
46
|
return new _TransactionRequest(raw);
|
|
29
47
|
}
|
|
@@ -33,6 +51,12 @@ var TransactionResponse = class _TransactionResponse {
|
|
|
33
51
|
this.response = response;
|
|
34
52
|
this.type = "TransactionResponse";
|
|
35
53
|
}
|
|
54
|
+
/**
|
|
55
|
+
* Creates an instance of TransactionResponse from a non-promise value.
|
|
56
|
+
*
|
|
57
|
+
* @param {Exclude<NonPromise<T>, TransactionTypes>} raw - The raw value to create the TransactionResponse from.
|
|
58
|
+
* @returns {TransactionResponse} The created TransactionResponse instance.
|
|
59
|
+
*/
|
|
36
60
|
static from(raw) {
|
|
37
61
|
return new _TransactionResponse(raw);
|
|
38
62
|
}
|
|
@@ -42,6 +66,12 @@ var TransactionReceipt = class _TransactionReceipt {
|
|
|
42
66
|
this.receipt = receipt;
|
|
43
67
|
this.type = "TransactionReceipt";
|
|
44
68
|
}
|
|
69
|
+
/**
|
|
70
|
+
* Creates an instance of TransactionReceipt from a non-promise value.
|
|
71
|
+
*
|
|
72
|
+
* @param {Exclude<NonPromise<T>, TransactionTypes>} raw - The raw value to create the TransactionReceipt from.
|
|
73
|
+
* @returns {TransactionReceipt} The created TransactionReceipt instance.
|
|
74
|
+
*/
|
|
45
75
|
static from(raw) {
|
|
46
76
|
return new _TransactionReceipt(raw);
|
|
47
77
|
}
|
|
@@ -51,6 +81,12 @@ var SignedTransaction = class _SignedTransaction {
|
|
|
51
81
|
this.signed = signed;
|
|
52
82
|
this.type = "SignedTransaction";
|
|
53
83
|
}
|
|
84
|
+
/**
|
|
85
|
+
* Creates an instance of SignedTransaction from a non-promise value.
|
|
86
|
+
*
|
|
87
|
+
* @param {Exclude<NonPromise<T>, TransactionTypes>} raw - The raw value to create the SignedTransaction from.
|
|
88
|
+
* @returns {SignedTransaction} The created SignedTransaction instance.
|
|
89
|
+
*/
|
|
54
90
|
static from(raw) {
|
|
55
91
|
return new _SignedTransaction(raw);
|
|
56
92
|
}
|
|
@@ -60,6 +96,12 @@ var TransactionPending = class _TransactionPending {
|
|
|
60
96
|
this.pending = pending;
|
|
61
97
|
this.type = "TransactionPending";
|
|
62
98
|
}
|
|
99
|
+
/**
|
|
100
|
+
* Creates an instance of TransactionPending from a non-promise value.
|
|
101
|
+
*
|
|
102
|
+
* @param {Exclude<NonPromise<T>, TransactionTypes>} raw - The raw value to create the TransactionPending from.
|
|
103
|
+
* @returns {TransactionPending} The created TransactionPending instance.
|
|
104
|
+
*/
|
|
63
105
|
static from(raw) {
|
|
64
106
|
return new _TransactionPending(raw);
|
|
65
107
|
}
|
package/dist/index.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
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;;;ACtDO,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<T = unknown> {\n /**\n * Connect to a provider\n * @param provider\n */\n connect(provider: Provider): Signer<T>\n\n /**\n * Sign a transaction\n * @param buildTxRequest\n */\n buildTransaction(buildTxRequest: T): Promise<TransactionRequest>\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 * this function NEED to return a Promise because ethers.Signer.getAddress() return a Promise<string>\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;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAQ5C,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;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAQ5C,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;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAQ9C,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;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAQ/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;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAQ9C,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;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAQ7C,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;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAQ9C,OAAO,KAAQ,KAAmE;AAC9E,WAAO,IAAI,oBAAmB,GAAG;AAAA,EACrC;AACJ;;;AChEO,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\n /**\n * Creates an instance of Block from a non-promise value.\n *\n * @param {NonPromise<T>} raw - The raw value to create the Block from.\n * @returns {Block} The created Block instance.\n */\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\n /**\n * Creates an instance of BlockWithTransactions from a non-promise value.\n *\n * @param {NonPromise<T>} raw - The raw value to create the BlockWithTransactions from.\n * @returns {BlockWithTransactions} The created BlockWithTransactions instance.\n */\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\n /**\n * Creates an instance of TransactionRequest from a non-promise value.\n *\n * @param {Exclude<NonPromise<T>, TransactionTypes>} raw - The raw value to create the TransactionRequest from.\n * @returns {TransactionRequest} The created TransactionRequest instance.\n */\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\n /**\n * Creates an instance of TransactionResponse from a non-promise value.\n *\n * @param {Exclude<NonPromise<T>, TransactionTypes>} raw - The raw value to create the TransactionResponse from.\n * @returns {TransactionResponse} The created TransactionResponse instance.\n */\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\n /**\n * Creates an instance of TransactionReceipt from a non-promise value.\n *\n * @param {Exclude<NonPromise<T>, TransactionTypes>} raw - The raw value to create the TransactionReceipt from.\n * @returns {TransactionReceipt} The created TransactionReceipt instance.\n */\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\n /**\n * Creates an instance of SignedTransaction from a non-promise value.\n *\n * @param {Exclude<NonPromise<T>, TransactionTypes>} raw - The raw value to create the SignedTransaction from.\n * @returns {SignedTransaction} The created SignedTransaction instance.\n */\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\n /**\n * Creates an instance of TransactionPending from a non-promise value.\n *\n * @param {Exclude<NonPromise<T>, TransactionTypes>} raw - The raw value to create the TransactionPending from.\n * @returns {TransactionPending} The created TransactionPending instance.\n */\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\n/**\n * Interface representing a signer.\n *\n * @template T - The type of the transaction request.\n */\nexport interface Signer<T = unknown> {\n /**\n * Connect to a provider.\n *\n * @param {Provider} provider - The provider to connect to.\n * @returns {Signer<T>} The connected signer.\n */\n connect(provider: Provider): Signer<T>\n\n /**\n * Build a transaction.\n *\n * @param {T} buildTxRequest - The transaction request to build.\n * @returns {Promise<TransactionRequest>} A promise that resolves to the built transaction request.\n */\n buildTransaction(buildTxRequest: T): Promise<TransactionRequest>\n\n /**\n * Sign a transaction.\n *\n * @param {TransactionRequest} transaction - The transaction request to sign.\n * @returns {Promise<SignedTransaction>} A promise that resolves to the signed transaction.\n */\n signTransaction(transaction: TransactionRequest): Promise<SignedTransaction>\n\n /**\n * Send a transaction.\n *\n * @param {SignedTransaction} transaction - The signed transaction to send.\n * @param {unknown} [sendOptions] - Optional parameters for sending the transaction.\n * @returns {Promise<TransactionPending>} A promise that resolves to the pending transaction.\n */\n sendTransaction(transaction: SignedTransaction, sendOptions?: unknown): Promise<TransactionPending>\n\n /**\n * Send a transaction and wait for confirmation.\n *\n * @param {SignedTransaction} transaction - The signed transaction to send.\n * @param {unknown} [opts] - Optional parameters for sending and confirming the transaction.\n * @returns {Promise<TransactionReceipt>} A promise that resolves to the transaction receipt.\n */\n sendAndConfirm(transaction: SignedTransaction, opts?: unknown): Promise<TransactionReceipt>\n\n /**\n * Sign a buffer (e.g. a message hash).\n *\n * @param {Uint8Array} buffer - The buffer to sign.\n * @returns {Promise<Uint8Array>} A promise that resolves to the signed buffer.\n */\n signBuffer(buffer: Uint8Array): Promise<Uint8Array>\n\n /**\n * Get the address of the signer.\n * this function NEED to return a Promise because ethers.Signer.getAddress() return a Promise<string>\n *\n * @returns {Promise<string>} A promise that resolves to the address of the signer.\n */\n getAddress(): Promise<string>\n\n /**\n * Native signer object\n */\n native: unknown\n}\n\n/**\n * Interface representing a connectable object.\n *\n * @template T - The type of the connectable object.\n */\nexport interface Connectable<T> {\n /**\n * Connect to a provider.\n *\n * @template U - The type of the provider.\n * @param {U} provider - The provider to connect to.\n * @returns {T} The connected object.\n */\n connect<U>(provider: U): T\n}\n\n/**\n * Check if an object is connectable.\n *\n * @template T - The type of the connectable object.\n * @param {unknown} obj - The object to check.\n * @returns {obj is Connectable<T>} True if the object is connectable, false otherwise.\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,3 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A utility type that excludes `Promise` types.
|
|
3
|
+
*
|
|
4
|
+
* @template T - The type to be checked.
|
|
5
|
+
* @typeParam T - The type to be checked.
|
|
6
|
+
* @returns `T` if `T` is not a `Promise`, otherwise `never`.
|
|
7
|
+
*/
|
|
1
8
|
type NonPromise<T> = T extends Promise<unknown> ? never : T;
|
|
2
9
|
|
|
3
10
|
/**
|
|
@@ -19,6 +26,12 @@ declare class Block {
|
|
|
19
26
|
block: unknown;
|
|
20
27
|
readonly type = "Block";
|
|
21
28
|
private constructor();
|
|
29
|
+
/**
|
|
30
|
+
* Creates an instance of Block from a non-promise value.
|
|
31
|
+
*
|
|
32
|
+
* @param {NonPromise<T>} raw - The raw value to create the Block from.
|
|
33
|
+
* @returns {Block} The created Block instance.
|
|
34
|
+
*/
|
|
22
35
|
static from<T>(raw: NonPromise<T>): Block;
|
|
23
36
|
}
|
|
24
37
|
/**
|
|
@@ -28,6 +41,12 @@ declare class BlockWithTransactions {
|
|
|
28
41
|
block: unknown;
|
|
29
42
|
readonly type = "BlockWithTransactions";
|
|
30
43
|
private constructor();
|
|
44
|
+
/**
|
|
45
|
+
* Creates an instance of BlockWithTransactions from a non-promise value.
|
|
46
|
+
*
|
|
47
|
+
* @param {NonPromise<T>} raw - The raw value to create the BlockWithTransactions from.
|
|
48
|
+
* @returns {BlockWithTransactions} The created BlockWithTransactions instance.
|
|
49
|
+
*/
|
|
31
50
|
static from<T>(raw: NonPromise<T>): BlockWithTransactions;
|
|
32
51
|
}
|
|
33
52
|
/**
|
|
@@ -49,6 +68,12 @@ declare class TransactionRequest {
|
|
|
49
68
|
request: unknown;
|
|
50
69
|
readonly type = "TransactionRequest";
|
|
51
70
|
private constructor();
|
|
71
|
+
/**
|
|
72
|
+
* Creates an instance of TransactionRequest from a non-promise value.
|
|
73
|
+
*
|
|
74
|
+
* @param {Exclude<NonPromise<T>, TransactionTypes>} raw - The raw value to create the TransactionRequest from.
|
|
75
|
+
* @returns {TransactionRequest} The created TransactionRequest instance.
|
|
76
|
+
*/
|
|
52
77
|
static from<T>(raw: Exclude<NonPromise<T>, TransactionTypes>): TransactionRequest;
|
|
53
78
|
}
|
|
54
79
|
/**
|
|
@@ -58,6 +83,12 @@ declare class TransactionResponse {
|
|
|
58
83
|
response: unknown;
|
|
59
84
|
readonly type = "TransactionResponse";
|
|
60
85
|
private constructor();
|
|
86
|
+
/**
|
|
87
|
+
* Creates an instance of TransactionResponse from a non-promise value.
|
|
88
|
+
*
|
|
89
|
+
* @param {Exclude<NonPromise<T>, TransactionTypes>} raw - The raw value to create the TransactionResponse from.
|
|
90
|
+
* @returns {TransactionResponse} The created TransactionResponse instance.
|
|
91
|
+
*/
|
|
61
92
|
static from<T>(raw: Exclude<NonPromise<T>, TransactionTypes>): TransactionResponse;
|
|
62
93
|
}
|
|
63
94
|
/**
|
|
@@ -67,6 +98,12 @@ declare class TransactionReceipt {
|
|
|
67
98
|
receipt: unknown;
|
|
68
99
|
readonly type = "TransactionReceipt";
|
|
69
100
|
private constructor();
|
|
101
|
+
/**
|
|
102
|
+
* Creates an instance of TransactionReceipt from a non-promise value.
|
|
103
|
+
*
|
|
104
|
+
* @param {Exclude<NonPromise<T>, TransactionTypes>} raw - The raw value to create the TransactionReceipt from.
|
|
105
|
+
* @returns {TransactionReceipt} The created TransactionReceipt instance.
|
|
106
|
+
*/
|
|
70
107
|
static from<T>(raw: Exclude<NonPromise<T>, TransactionTypes>): TransactionReceipt;
|
|
71
108
|
}
|
|
72
109
|
/**
|
|
@@ -76,6 +113,12 @@ declare class SignedTransaction {
|
|
|
76
113
|
signed: unknown;
|
|
77
114
|
readonly type = "SignedTransaction";
|
|
78
115
|
private constructor();
|
|
116
|
+
/**
|
|
117
|
+
* Creates an instance of SignedTransaction from a non-promise value.
|
|
118
|
+
*
|
|
119
|
+
* @param {Exclude<NonPromise<T>, TransactionTypes>} raw - The raw value to create the SignedTransaction from.
|
|
120
|
+
* @returns {SignedTransaction} The created SignedTransaction instance.
|
|
121
|
+
*/
|
|
79
122
|
static from<T>(raw: Exclude<NonPromise<T>, TransactionTypes>): SignedTransaction;
|
|
80
123
|
}
|
|
81
124
|
/**
|
|
@@ -85,66 +128,85 @@ declare class TransactionPending {
|
|
|
85
128
|
pending: unknown;
|
|
86
129
|
readonly type = "TransactionPending";
|
|
87
130
|
private constructor();
|
|
131
|
+
/**
|
|
132
|
+
* Creates an instance of TransactionPending from a non-promise value.
|
|
133
|
+
*
|
|
134
|
+
* @param {Exclude<NonPromise<T>, TransactionTypes>} raw - The raw value to create the TransactionPending from.
|
|
135
|
+
* @returns {TransactionPending} The created TransactionPending instance.
|
|
136
|
+
*/
|
|
88
137
|
static from<T>(raw: Exclude<NonPromise<T>, TransactionTypes>): TransactionPending;
|
|
89
138
|
}
|
|
90
139
|
|
|
140
|
+
/**
|
|
141
|
+
* Interface representing a blockchain provider.
|
|
142
|
+
*/
|
|
91
143
|
interface Provider {
|
|
92
144
|
/**
|
|
93
|
-
*
|
|
94
|
-
* @returns string
|
|
145
|
+
* The URL of the provider.
|
|
146
|
+
* @returns {string} The URL of the provider.
|
|
95
147
|
*/
|
|
96
148
|
url: string;
|
|
97
149
|
/**
|
|
98
|
-
* Get the block specified by blockTag
|
|
99
|
-
* @param {BlockTag}
|
|
100
|
-
* @returns
|
|
150
|
+
* Get the block specified by blockTag.
|
|
151
|
+
* @param {BlockTag} blockTag - The block tag to specify the block.
|
|
152
|
+
* @returns {Promise<Block>} A promise that resolves to the block.
|
|
101
153
|
*/
|
|
102
154
|
getBlock(blockTag: BlockTag): Promise<Block>;
|
|
155
|
+
/**
|
|
156
|
+
* Get the block with transactions specified by blockTag.
|
|
157
|
+
* @param {BlockTag} blockTag - The block tag to specify the block.
|
|
158
|
+
* @returns {Promise<BlockWithTransactions>} A promise that resolves to the block with transactions.
|
|
159
|
+
*/
|
|
103
160
|
getBlockWithTransactions(blockTag: BlockTag): Promise<BlockWithTransactions>;
|
|
104
161
|
/**
|
|
105
|
-
* Get information about a transaction
|
|
106
|
-
* @param {string} txHash
|
|
107
|
-
* @returns
|
|
162
|
+
* Get information about a transaction.
|
|
163
|
+
* @param {string} txHash - The hash of the transaction.
|
|
164
|
+
* @returns {Promise<TransactionResponse>} A promise that resolves to the transaction response.
|
|
108
165
|
*/
|
|
109
166
|
getTransaction(txHash: string): Promise<TransactionResponse>;
|
|
110
167
|
/**
|
|
111
|
-
* Get the receipt of a transaction
|
|
112
|
-
* @param txHash
|
|
168
|
+
* Get the receipt of a transaction.
|
|
169
|
+
* @param {string} txHash - The hash of the transaction.
|
|
170
|
+
* @returns {Promise<TransactionReceipt>} A promise that resolves to the transaction receipt.
|
|
113
171
|
*/
|
|
114
172
|
getTransactionReceipt(txHash: string): Promise<TransactionReceipt>;
|
|
115
173
|
/**
|
|
116
|
-
* Get the current block number
|
|
117
|
-
* @returns Promise<number> the current block number
|
|
174
|
+
* Get the current block number.
|
|
175
|
+
* @returns {Promise<number>} A promise that resolves to the current block number.
|
|
118
176
|
*/
|
|
119
177
|
getBlockNumber(): Promise<number>;
|
|
120
178
|
/**
|
|
121
|
-
* Get the current slot number for commitment
|
|
122
|
-
* @param commitment
|
|
179
|
+
* Get the current slot number for commitment.
|
|
180
|
+
* @param {Finality} [commitment] - The commitment level.
|
|
181
|
+
* @returns {Promise<number>} A promise that resolves to the current slot number.
|
|
123
182
|
*/
|
|
124
183
|
getSlot(commitment?: Finality): Promise<number>;
|
|
125
184
|
/**
|
|
126
|
-
* Get the number of transactions sent from this address
|
|
127
|
-
* @param {string|Promise<string>} addressOrName The address to get the
|
|
128
|
-
* @param {BlockTag|Promise<BlockTag>} [blockTag] The block tag to get the
|
|
129
|
-
* @returns Promise<number>
|
|
185
|
+
* Get the number of transactions sent from this address.
|
|
186
|
+
* @param {string | Promise<string>} addressOrName - The address to get the number of transactions from.
|
|
187
|
+
* @param {BlockTag | Promise<BlockTag>} [blockTag] - The block tag to get the number of transactions from.
|
|
188
|
+
* @returns {Promise<number>} A promise that resolves to the number of transactions sent from this address.
|
|
130
189
|
*/
|
|
131
190
|
getTransactionCount(addressOrName: string | Promise<string>, blockTag?: BlockTag | Promise<BlockTag>): Promise<number>;
|
|
132
191
|
/**
|
|
133
|
-
* Get the balance of an address
|
|
134
|
-
* @param address
|
|
192
|
+
* Get the balance of an address.
|
|
193
|
+
* @param {string} address - The address to get the balance of.
|
|
194
|
+
* @returns {Promise<string>} A promise that resolves to the balance of the address.
|
|
135
195
|
*/
|
|
136
196
|
getBalance(address: string): Promise<string>;
|
|
137
197
|
/**
|
|
138
|
-
* Gets the UNIX timestamp for the block identified by blockTag.
|
|
139
|
-
* seconds since the Unix Epoch on January 1st, 1970 at UTC.
|
|
140
|
-
*
|
|
141
|
-
* @
|
|
198
|
+
* Gets the UNIX timestamp for the block identified by blockTag.
|
|
199
|
+
* The UNIX timestamp is defined as the count of seconds since the Unix Epoch on January 1st, 1970 at UTC.
|
|
200
|
+
* If blockTag is not provided, the latest block is used.
|
|
201
|
+
* @param {BlockTag} blockTag - The block tag to specify the block.
|
|
202
|
+
* @returns {Promise<number>} A promise that resolves to the UNIX timestamp of the block identified by blockTag.
|
|
142
203
|
*/
|
|
143
204
|
getBlockTimestamp(blockTag: BlockTag): Promise<number>;
|
|
144
205
|
/**
|
|
145
|
-
*
|
|
146
|
-
* @param transaction
|
|
147
|
-
* @param sendOptions
|
|
206
|
+
* Send a signed transaction in bytes to the blockchain.
|
|
207
|
+
* @param {SignedTransaction} transaction - The signed transaction to send.
|
|
208
|
+
* @param {unknown} [sendOptions] - Optional parameters for sending the transaction.
|
|
209
|
+
* @returns {Promise<TransactionPending>} A promise that resolves to the pending transaction.
|
|
148
210
|
*/
|
|
149
211
|
sendTransaction(transaction: SignedTransaction, sendOptions?: unknown): Promise<TransactionPending>;
|
|
150
212
|
/**
|
|
@@ -155,49 +217,73 @@ interface Provider {
|
|
|
155
217
|
*/
|
|
156
218
|
confirmTransaction(pending: TransactionPending, opts?: unknown): Promise<TransactionReceipt>;
|
|
157
219
|
/**
|
|
158
|
-
* Send a transaction and wait for confirmation
|
|
159
|
-
* @param transaction
|
|
160
|
-
* @param opts
|
|
220
|
+
* Send a transaction and wait for confirmation.
|
|
221
|
+
* @param {SignedTransaction} transaction - The signed transaction to send.
|
|
222
|
+
* @param {unknown} [opts] - Optional parameters for sending and confirming the transaction.
|
|
223
|
+
* @returns {Promise<TransactionReceipt>} A promise that resolves to the transaction receipt.
|
|
161
224
|
*/
|
|
162
225
|
sendAndConfirm(transaction: SignedTransaction, opts?: unknown): Promise<TransactionReceipt>;
|
|
226
|
+
/**
|
|
227
|
+
* The native provider instance.
|
|
228
|
+
*/
|
|
163
229
|
readonly native: unknown;
|
|
164
230
|
}
|
|
165
231
|
|
|
232
|
+
/**
|
|
233
|
+
* Interface representing a signer.
|
|
234
|
+
*
|
|
235
|
+
* @template T - The type of the transaction request.
|
|
236
|
+
*/
|
|
166
237
|
interface Signer<T = unknown> {
|
|
167
238
|
/**
|
|
168
|
-
* Connect to a provider
|
|
169
|
-
*
|
|
239
|
+
* Connect to a provider.
|
|
240
|
+
*
|
|
241
|
+
* @param {Provider} provider - The provider to connect to.
|
|
242
|
+
* @returns {Signer<T>} The connected signer.
|
|
170
243
|
*/
|
|
171
244
|
connect(provider: Provider): Signer<T>;
|
|
172
245
|
/**
|
|
173
|
-
*
|
|
174
|
-
*
|
|
246
|
+
* Build a transaction.
|
|
247
|
+
*
|
|
248
|
+
* @param {T} buildTxRequest - The transaction request to build.
|
|
249
|
+
* @returns {Promise<TransactionRequest>} A promise that resolves to the built transaction request.
|
|
175
250
|
*/
|
|
176
251
|
buildTransaction(buildTxRequest: T): Promise<TransactionRequest>;
|
|
177
252
|
/**
|
|
178
|
-
* Sign a transaction
|
|
179
|
-
*
|
|
253
|
+
* Sign a transaction.
|
|
254
|
+
*
|
|
255
|
+
* @param {TransactionRequest} transaction - The transaction request to sign.
|
|
256
|
+
* @returns {Promise<SignedTransaction>} A promise that resolves to the signed transaction.
|
|
180
257
|
*/
|
|
181
258
|
signTransaction(transaction: TransactionRequest): Promise<SignedTransaction>;
|
|
182
259
|
/**
|
|
183
|
-
* Send a transaction
|
|
184
|
-
*
|
|
185
|
-
* @param
|
|
260
|
+
* Send a transaction.
|
|
261
|
+
*
|
|
262
|
+
* @param {SignedTransaction} transaction - The signed transaction to send.
|
|
263
|
+
* @param {unknown} [sendOptions] - Optional parameters for sending the transaction.
|
|
264
|
+
* @returns {Promise<TransactionPending>} A promise that resolves to the pending transaction.
|
|
186
265
|
*/
|
|
187
266
|
sendTransaction(transaction: SignedTransaction, sendOptions?: unknown): Promise<TransactionPending>;
|
|
188
267
|
/**
|
|
189
|
-
* Send a transaction and wait for confirmation
|
|
190
|
-
*
|
|
191
|
-
* @param
|
|
268
|
+
* Send a transaction and wait for confirmation.
|
|
269
|
+
*
|
|
270
|
+
* @param {SignedTransaction} transaction - The signed transaction to send.
|
|
271
|
+
* @param {unknown} [opts] - Optional parameters for sending and confirming the transaction.
|
|
272
|
+
* @returns {Promise<TransactionReceipt>} A promise that resolves to the transaction receipt.
|
|
192
273
|
*/
|
|
193
274
|
sendAndConfirm(transaction: SignedTransaction, opts?: unknown): Promise<TransactionReceipt>;
|
|
194
275
|
/**
|
|
195
|
-
* Sign a buffer (e.g. a message hash)
|
|
276
|
+
* Sign a buffer (e.g. a message hash).
|
|
277
|
+
*
|
|
278
|
+
* @param {Uint8Array} buffer - The buffer to sign.
|
|
279
|
+
* @returns {Promise<Uint8Array>} A promise that resolves to the signed buffer.
|
|
196
280
|
*/
|
|
197
281
|
signBuffer(buffer: Uint8Array): Promise<Uint8Array>;
|
|
198
282
|
/**
|
|
199
|
-
*
|
|
283
|
+
* Get the address of the signer.
|
|
200
284
|
* this function NEED to return a Promise because ethers.Signer.getAddress() return a Promise<string>
|
|
285
|
+
*
|
|
286
|
+
* @returns {Promise<string>} A promise that resolves to the address of the signer.
|
|
201
287
|
*/
|
|
202
288
|
getAddress(): Promise<string>;
|
|
203
289
|
/**
|
|
@@ -205,9 +291,28 @@ interface Signer<T = unknown> {
|
|
|
205
291
|
*/
|
|
206
292
|
native: unknown;
|
|
207
293
|
}
|
|
294
|
+
/**
|
|
295
|
+
* Interface representing a connectable object.
|
|
296
|
+
*
|
|
297
|
+
* @template T - The type of the connectable object.
|
|
298
|
+
*/
|
|
208
299
|
interface Connectable<T> {
|
|
300
|
+
/**
|
|
301
|
+
* Connect to a provider.
|
|
302
|
+
*
|
|
303
|
+
* @template U - The type of the provider.
|
|
304
|
+
* @param {U} provider - The provider to connect to.
|
|
305
|
+
* @returns {T} The connected object.
|
|
306
|
+
*/
|
|
209
307
|
connect<U>(provider: U): T;
|
|
210
308
|
}
|
|
309
|
+
/**
|
|
310
|
+
* Check if an object is connectable.
|
|
311
|
+
*
|
|
312
|
+
* @template T - The type of the connectable object.
|
|
313
|
+
* @param {unknown} obj - The object to check.
|
|
314
|
+
* @returns {obj is Connectable<T>} True if the object is connectable, false otherwise.
|
|
315
|
+
*/
|
|
211
316
|
declare function isConnectable<T>(obj: unknown): obj is Connectable<T>;
|
|
212
317
|
|
|
213
318
|
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,3 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A utility type that excludes `Promise` types.
|
|
3
|
+
*
|
|
4
|
+
* @template T - The type to be checked.
|
|
5
|
+
* @typeParam T - The type to be checked.
|
|
6
|
+
* @returns `T` if `T` is not a `Promise`, otherwise `never`.
|
|
7
|
+
*/
|
|
1
8
|
type NonPromise<T> = T extends Promise<unknown> ? never : T;
|
|
2
9
|
|
|
3
10
|
/**
|
|
@@ -19,6 +26,12 @@ declare class Block {
|
|
|
19
26
|
block: unknown;
|
|
20
27
|
readonly type = "Block";
|
|
21
28
|
private constructor();
|
|
29
|
+
/**
|
|
30
|
+
* Creates an instance of Block from a non-promise value.
|
|
31
|
+
*
|
|
32
|
+
* @param {NonPromise<T>} raw - The raw value to create the Block from.
|
|
33
|
+
* @returns {Block} The created Block instance.
|
|
34
|
+
*/
|
|
22
35
|
static from<T>(raw: NonPromise<T>): Block;
|
|
23
36
|
}
|
|
24
37
|
/**
|
|
@@ -28,6 +41,12 @@ declare class BlockWithTransactions {
|
|
|
28
41
|
block: unknown;
|
|
29
42
|
readonly type = "BlockWithTransactions";
|
|
30
43
|
private constructor();
|
|
44
|
+
/**
|
|
45
|
+
* Creates an instance of BlockWithTransactions from a non-promise value.
|
|
46
|
+
*
|
|
47
|
+
* @param {NonPromise<T>} raw - The raw value to create the BlockWithTransactions from.
|
|
48
|
+
* @returns {BlockWithTransactions} The created BlockWithTransactions instance.
|
|
49
|
+
*/
|
|
31
50
|
static from<T>(raw: NonPromise<T>): BlockWithTransactions;
|
|
32
51
|
}
|
|
33
52
|
/**
|
|
@@ -49,6 +68,12 @@ declare class TransactionRequest {
|
|
|
49
68
|
request: unknown;
|
|
50
69
|
readonly type = "TransactionRequest";
|
|
51
70
|
private constructor();
|
|
71
|
+
/**
|
|
72
|
+
* Creates an instance of TransactionRequest from a non-promise value.
|
|
73
|
+
*
|
|
74
|
+
* @param {Exclude<NonPromise<T>, TransactionTypes>} raw - The raw value to create the TransactionRequest from.
|
|
75
|
+
* @returns {TransactionRequest} The created TransactionRequest instance.
|
|
76
|
+
*/
|
|
52
77
|
static from<T>(raw: Exclude<NonPromise<T>, TransactionTypes>): TransactionRequest;
|
|
53
78
|
}
|
|
54
79
|
/**
|
|
@@ -58,6 +83,12 @@ declare class TransactionResponse {
|
|
|
58
83
|
response: unknown;
|
|
59
84
|
readonly type = "TransactionResponse";
|
|
60
85
|
private constructor();
|
|
86
|
+
/**
|
|
87
|
+
* Creates an instance of TransactionResponse from a non-promise value.
|
|
88
|
+
*
|
|
89
|
+
* @param {Exclude<NonPromise<T>, TransactionTypes>} raw - The raw value to create the TransactionResponse from.
|
|
90
|
+
* @returns {TransactionResponse} The created TransactionResponse instance.
|
|
91
|
+
*/
|
|
61
92
|
static from<T>(raw: Exclude<NonPromise<T>, TransactionTypes>): TransactionResponse;
|
|
62
93
|
}
|
|
63
94
|
/**
|
|
@@ -67,6 +98,12 @@ declare class TransactionReceipt {
|
|
|
67
98
|
receipt: unknown;
|
|
68
99
|
readonly type = "TransactionReceipt";
|
|
69
100
|
private constructor();
|
|
101
|
+
/**
|
|
102
|
+
* Creates an instance of TransactionReceipt from a non-promise value.
|
|
103
|
+
*
|
|
104
|
+
* @param {Exclude<NonPromise<T>, TransactionTypes>} raw - The raw value to create the TransactionReceipt from.
|
|
105
|
+
* @returns {TransactionReceipt} The created TransactionReceipt instance.
|
|
106
|
+
*/
|
|
70
107
|
static from<T>(raw: Exclude<NonPromise<T>, TransactionTypes>): TransactionReceipt;
|
|
71
108
|
}
|
|
72
109
|
/**
|
|
@@ -76,6 +113,12 @@ declare class SignedTransaction {
|
|
|
76
113
|
signed: unknown;
|
|
77
114
|
readonly type = "SignedTransaction";
|
|
78
115
|
private constructor();
|
|
116
|
+
/**
|
|
117
|
+
* Creates an instance of SignedTransaction from a non-promise value.
|
|
118
|
+
*
|
|
119
|
+
* @param {Exclude<NonPromise<T>, TransactionTypes>} raw - The raw value to create the SignedTransaction from.
|
|
120
|
+
* @returns {SignedTransaction} The created SignedTransaction instance.
|
|
121
|
+
*/
|
|
79
122
|
static from<T>(raw: Exclude<NonPromise<T>, TransactionTypes>): SignedTransaction;
|
|
80
123
|
}
|
|
81
124
|
/**
|
|
@@ -85,66 +128,85 @@ declare class TransactionPending {
|
|
|
85
128
|
pending: unknown;
|
|
86
129
|
readonly type = "TransactionPending";
|
|
87
130
|
private constructor();
|
|
131
|
+
/**
|
|
132
|
+
* Creates an instance of TransactionPending from a non-promise value.
|
|
133
|
+
*
|
|
134
|
+
* @param {Exclude<NonPromise<T>, TransactionTypes>} raw - The raw value to create the TransactionPending from.
|
|
135
|
+
* @returns {TransactionPending} The created TransactionPending instance.
|
|
136
|
+
*/
|
|
88
137
|
static from<T>(raw: Exclude<NonPromise<T>, TransactionTypes>): TransactionPending;
|
|
89
138
|
}
|
|
90
139
|
|
|
140
|
+
/**
|
|
141
|
+
* Interface representing a blockchain provider.
|
|
142
|
+
*/
|
|
91
143
|
interface Provider {
|
|
92
144
|
/**
|
|
93
|
-
*
|
|
94
|
-
* @returns string
|
|
145
|
+
* The URL of the provider.
|
|
146
|
+
* @returns {string} The URL of the provider.
|
|
95
147
|
*/
|
|
96
148
|
url: string;
|
|
97
149
|
/**
|
|
98
|
-
* Get the block specified by blockTag
|
|
99
|
-
* @param {BlockTag}
|
|
100
|
-
* @returns
|
|
150
|
+
* Get the block specified by blockTag.
|
|
151
|
+
* @param {BlockTag} blockTag - The block tag to specify the block.
|
|
152
|
+
* @returns {Promise<Block>} A promise that resolves to the block.
|
|
101
153
|
*/
|
|
102
154
|
getBlock(blockTag: BlockTag): Promise<Block>;
|
|
155
|
+
/**
|
|
156
|
+
* Get the block with transactions specified by blockTag.
|
|
157
|
+
* @param {BlockTag} blockTag - The block tag to specify the block.
|
|
158
|
+
* @returns {Promise<BlockWithTransactions>} A promise that resolves to the block with transactions.
|
|
159
|
+
*/
|
|
103
160
|
getBlockWithTransactions(blockTag: BlockTag): Promise<BlockWithTransactions>;
|
|
104
161
|
/**
|
|
105
|
-
* Get information about a transaction
|
|
106
|
-
* @param {string} txHash
|
|
107
|
-
* @returns
|
|
162
|
+
* Get information about a transaction.
|
|
163
|
+
* @param {string} txHash - The hash of the transaction.
|
|
164
|
+
* @returns {Promise<TransactionResponse>} A promise that resolves to the transaction response.
|
|
108
165
|
*/
|
|
109
166
|
getTransaction(txHash: string): Promise<TransactionResponse>;
|
|
110
167
|
/**
|
|
111
|
-
* Get the receipt of a transaction
|
|
112
|
-
* @param txHash
|
|
168
|
+
* Get the receipt of a transaction.
|
|
169
|
+
* @param {string} txHash - The hash of the transaction.
|
|
170
|
+
* @returns {Promise<TransactionReceipt>} A promise that resolves to the transaction receipt.
|
|
113
171
|
*/
|
|
114
172
|
getTransactionReceipt(txHash: string): Promise<TransactionReceipt>;
|
|
115
173
|
/**
|
|
116
|
-
* Get the current block number
|
|
117
|
-
* @returns Promise<number> the current block number
|
|
174
|
+
* Get the current block number.
|
|
175
|
+
* @returns {Promise<number>} A promise that resolves to the current block number.
|
|
118
176
|
*/
|
|
119
177
|
getBlockNumber(): Promise<number>;
|
|
120
178
|
/**
|
|
121
|
-
* Get the current slot number for commitment
|
|
122
|
-
* @param commitment
|
|
179
|
+
* Get the current slot number for commitment.
|
|
180
|
+
* @param {Finality} [commitment] - The commitment level.
|
|
181
|
+
* @returns {Promise<number>} A promise that resolves to the current slot number.
|
|
123
182
|
*/
|
|
124
183
|
getSlot(commitment?: Finality): Promise<number>;
|
|
125
184
|
/**
|
|
126
|
-
* Get the number of transactions sent from this address
|
|
127
|
-
* @param {string|Promise<string>} addressOrName The address to get the
|
|
128
|
-
* @param {BlockTag|Promise<BlockTag>} [blockTag] The block tag to get the
|
|
129
|
-
* @returns Promise<number>
|
|
185
|
+
* Get the number of transactions sent from this address.
|
|
186
|
+
* @param {string | Promise<string>} addressOrName - The address to get the number of transactions from.
|
|
187
|
+
* @param {BlockTag | Promise<BlockTag>} [blockTag] - The block tag to get the number of transactions from.
|
|
188
|
+
* @returns {Promise<number>} A promise that resolves to the number of transactions sent from this address.
|
|
130
189
|
*/
|
|
131
190
|
getTransactionCount(addressOrName: string | Promise<string>, blockTag?: BlockTag | Promise<BlockTag>): Promise<number>;
|
|
132
191
|
/**
|
|
133
|
-
* Get the balance of an address
|
|
134
|
-
* @param address
|
|
192
|
+
* Get the balance of an address.
|
|
193
|
+
* @param {string} address - The address to get the balance of.
|
|
194
|
+
* @returns {Promise<string>} A promise that resolves to the balance of the address.
|
|
135
195
|
*/
|
|
136
196
|
getBalance(address: string): Promise<string>;
|
|
137
197
|
/**
|
|
138
|
-
* Gets the UNIX timestamp for the block identified by blockTag.
|
|
139
|
-
* seconds since the Unix Epoch on January 1st, 1970 at UTC.
|
|
140
|
-
*
|
|
141
|
-
* @
|
|
198
|
+
* Gets the UNIX timestamp for the block identified by blockTag.
|
|
199
|
+
* The UNIX timestamp is defined as the count of seconds since the Unix Epoch on January 1st, 1970 at UTC.
|
|
200
|
+
* If blockTag is not provided, the latest block is used.
|
|
201
|
+
* @param {BlockTag} blockTag - The block tag to specify the block.
|
|
202
|
+
* @returns {Promise<number>} A promise that resolves to the UNIX timestamp of the block identified by blockTag.
|
|
142
203
|
*/
|
|
143
204
|
getBlockTimestamp(blockTag: BlockTag): Promise<number>;
|
|
144
205
|
/**
|
|
145
|
-
*
|
|
146
|
-
* @param transaction
|
|
147
|
-
* @param sendOptions
|
|
206
|
+
* Send a signed transaction in bytes to the blockchain.
|
|
207
|
+
* @param {SignedTransaction} transaction - The signed transaction to send.
|
|
208
|
+
* @param {unknown} [sendOptions] - Optional parameters for sending the transaction.
|
|
209
|
+
* @returns {Promise<TransactionPending>} A promise that resolves to the pending transaction.
|
|
148
210
|
*/
|
|
149
211
|
sendTransaction(transaction: SignedTransaction, sendOptions?: unknown): Promise<TransactionPending>;
|
|
150
212
|
/**
|
|
@@ -155,49 +217,73 @@ interface Provider {
|
|
|
155
217
|
*/
|
|
156
218
|
confirmTransaction(pending: TransactionPending, opts?: unknown): Promise<TransactionReceipt>;
|
|
157
219
|
/**
|
|
158
|
-
* Send a transaction and wait for confirmation
|
|
159
|
-
* @param transaction
|
|
160
|
-
* @param opts
|
|
220
|
+
* Send a transaction and wait for confirmation.
|
|
221
|
+
* @param {SignedTransaction} transaction - The signed transaction to send.
|
|
222
|
+
* @param {unknown} [opts] - Optional parameters for sending and confirming the transaction.
|
|
223
|
+
* @returns {Promise<TransactionReceipt>} A promise that resolves to the transaction receipt.
|
|
161
224
|
*/
|
|
162
225
|
sendAndConfirm(transaction: SignedTransaction, opts?: unknown): Promise<TransactionReceipt>;
|
|
226
|
+
/**
|
|
227
|
+
* The native provider instance.
|
|
228
|
+
*/
|
|
163
229
|
readonly native: unknown;
|
|
164
230
|
}
|
|
165
231
|
|
|
232
|
+
/**
|
|
233
|
+
* Interface representing a signer.
|
|
234
|
+
*
|
|
235
|
+
* @template T - The type of the transaction request.
|
|
236
|
+
*/
|
|
166
237
|
interface Signer<T = unknown> {
|
|
167
238
|
/**
|
|
168
|
-
* Connect to a provider
|
|
169
|
-
*
|
|
239
|
+
* Connect to a provider.
|
|
240
|
+
*
|
|
241
|
+
* @param {Provider} provider - The provider to connect to.
|
|
242
|
+
* @returns {Signer<T>} The connected signer.
|
|
170
243
|
*/
|
|
171
244
|
connect(provider: Provider): Signer<T>;
|
|
172
245
|
/**
|
|
173
|
-
*
|
|
174
|
-
*
|
|
246
|
+
* Build a transaction.
|
|
247
|
+
*
|
|
248
|
+
* @param {T} buildTxRequest - The transaction request to build.
|
|
249
|
+
* @returns {Promise<TransactionRequest>} A promise that resolves to the built transaction request.
|
|
175
250
|
*/
|
|
176
251
|
buildTransaction(buildTxRequest: T): Promise<TransactionRequest>;
|
|
177
252
|
/**
|
|
178
|
-
* Sign a transaction
|
|
179
|
-
*
|
|
253
|
+
* Sign a transaction.
|
|
254
|
+
*
|
|
255
|
+
* @param {TransactionRequest} transaction - The transaction request to sign.
|
|
256
|
+
* @returns {Promise<SignedTransaction>} A promise that resolves to the signed transaction.
|
|
180
257
|
*/
|
|
181
258
|
signTransaction(transaction: TransactionRequest): Promise<SignedTransaction>;
|
|
182
259
|
/**
|
|
183
|
-
* Send a transaction
|
|
184
|
-
*
|
|
185
|
-
* @param
|
|
260
|
+
* Send a transaction.
|
|
261
|
+
*
|
|
262
|
+
* @param {SignedTransaction} transaction - The signed transaction to send.
|
|
263
|
+
* @param {unknown} [sendOptions] - Optional parameters for sending the transaction.
|
|
264
|
+
* @returns {Promise<TransactionPending>} A promise that resolves to the pending transaction.
|
|
186
265
|
*/
|
|
187
266
|
sendTransaction(transaction: SignedTransaction, sendOptions?: unknown): Promise<TransactionPending>;
|
|
188
267
|
/**
|
|
189
|
-
* Send a transaction and wait for confirmation
|
|
190
|
-
*
|
|
191
|
-
* @param
|
|
268
|
+
* Send a transaction and wait for confirmation.
|
|
269
|
+
*
|
|
270
|
+
* @param {SignedTransaction} transaction - The signed transaction to send.
|
|
271
|
+
* @param {unknown} [opts] - Optional parameters for sending and confirming the transaction.
|
|
272
|
+
* @returns {Promise<TransactionReceipt>} A promise that resolves to the transaction receipt.
|
|
192
273
|
*/
|
|
193
274
|
sendAndConfirm(transaction: SignedTransaction, opts?: unknown): Promise<TransactionReceipt>;
|
|
194
275
|
/**
|
|
195
|
-
* Sign a buffer (e.g. a message hash)
|
|
276
|
+
* Sign a buffer (e.g. a message hash).
|
|
277
|
+
*
|
|
278
|
+
* @param {Uint8Array} buffer - The buffer to sign.
|
|
279
|
+
* @returns {Promise<Uint8Array>} A promise that resolves to the signed buffer.
|
|
196
280
|
*/
|
|
197
281
|
signBuffer(buffer: Uint8Array): Promise<Uint8Array>;
|
|
198
282
|
/**
|
|
199
|
-
*
|
|
283
|
+
* Get the address of the signer.
|
|
200
284
|
* this function NEED to return a Promise because ethers.Signer.getAddress() return a Promise<string>
|
|
285
|
+
*
|
|
286
|
+
* @returns {Promise<string>} A promise that resolves to the address of the signer.
|
|
201
287
|
*/
|
|
202
288
|
getAddress(): Promise<string>;
|
|
203
289
|
/**
|
|
@@ -205,9 +291,28 @@ interface Signer<T = unknown> {
|
|
|
205
291
|
*/
|
|
206
292
|
native: unknown;
|
|
207
293
|
}
|
|
294
|
+
/**
|
|
295
|
+
* Interface representing a connectable object.
|
|
296
|
+
*
|
|
297
|
+
* @template T - The type of the connectable object.
|
|
298
|
+
*/
|
|
208
299
|
interface Connectable<T> {
|
|
300
|
+
/**
|
|
301
|
+
* Connect to a provider.
|
|
302
|
+
*
|
|
303
|
+
* @template U - The type of the provider.
|
|
304
|
+
* @param {U} provider - The provider to connect to.
|
|
305
|
+
* @returns {T} The connected object.
|
|
306
|
+
*/
|
|
209
307
|
connect<U>(provider: U): T;
|
|
210
308
|
}
|
|
309
|
+
/**
|
|
310
|
+
* Check if an object is connectable.
|
|
311
|
+
*
|
|
312
|
+
* @template T - The type of the connectable object.
|
|
313
|
+
* @param {unknown} obj - The object to check.
|
|
314
|
+
* @returns {obj is Connectable<T>} True if the object is connectable, false otherwise.
|
|
315
|
+
*/
|
|
211
316
|
declare function isConnectable<T>(obj: unknown): obj is Connectable<T>;
|
|
212
317
|
|
|
213
318
|
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
|
@@ -4,6 +4,12 @@ var Block = class _Block {
|
|
|
4
4
|
this.block = block;
|
|
5
5
|
this.type = "Block";
|
|
6
6
|
}
|
|
7
|
+
/**
|
|
8
|
+
* Creates an instance of Block from a non-promise value.
|
|
9
|
+
*
|
|
10
|
+
* @param {NonPromise<T>} raw - The raw value to create the Block from.
|
|
11
|
+
* @returns {Block} The created Block instance.
|
|
12
|
+
*/
|
|
7
13
|
static from(raw) {
|
|
8
14
|
return new _Block(raw);
|
|
9
15
|
}
|
|
@@ -13,6 +19,12 @@ var BlockWithTransactions = class _BlockWithTransactions {
|
|
|
13
19
|
this.block = block;
|
|
14
20
|
this.type = "BlockWithTransactions";
|
|
15
21
|
}
|
|
22
|
+
/**
|
|
23
|
+
* Creates an instance of BlockWithTransactions from a non-promise value.
|
|
24
|
+
*
|
|
25
|
+
* @param {NonPromise<T>} raw - The raw value to create the BlockWithTransactions from.
|
|
26
|
+
* @returns {BlockWithTransactions} The created BlockWithTransactions instance.
|
|
27
|
+
*/
|
|
16
28
|
static from(raw) {
|
|
17
29
|
return new _BlockWithTransactions(raw);
|
|
18
30
|
}
|
|
@@ -22,6 +34,12 @@ var TransactionRequest = class _TransactionRequest {
|
|
|
22
34
|
this.request = request;
|
|
23
35
|
this.type = "TransactionRequest";
|
|
24
36
|
}
|
|
37
|
+
/**
|
|
38
|
+
* Creates an instance of TransactionRequest from a non-promise value.
|
|
39
|
+
*
|
|
40
|
+
* @param {Exclude<NonPromise<T>, TransactionTypes>} raw - The raw value to create the TransactionRequest from.
|
|
41
|
+
* @returns {TransactionRequest} The created TransactionRequest instance.
|
|
42
|
+
*/
|
|
25
43
|
static from(raw) {
|
|
26
44
|
return new _TransactionRequest(raw);
|
|
27
45
|
}
|
|
@@ -31,6 +49,12 @@ var TransactionResponse = class _TransactionResponse {
|
|
|
31
49
|
this.response = response;
|
|
32
50
|
this.type = "TransactionResponse";
|
|
33
51
|
}
|
|
52
|
+
/**
|
|
53
|
+
* Creates an instance of TransactionResponse from a non-promise value.
|
|
54
|
+
*
|
|
55
|
+
* @param {Exclude<NonPromise<T>, TransactionTypes>} raw - The raw value to create the TransactionResponse from.
|
|
56
|
+
* @returns {TransactionResponse} The created TransactionResponse instance.
|
|
57
|
+
*/
|
|
34
58
|
static from(raw) {
|
|
35
59
|
return new _TransactionResponse(raw);
|
|
36
60
|
}
|
|
@@ -40,6 +64,12 @@ var TransactionReceipt = class _TransactionReceipt {
|
|
|
40
64
|
this.receipt = receipt;
|
|
41
65
|
this.type = "TransactionReceipt";
|
|
42
66
|
}
|
|
67
|
+
/**
|
|
68
|
+
* Creates an instance of TransactionReceipt from a non-promise value.
|
|
69
|
+
*
|
|
70
|
+
* @param {Exclude<NonPromise<T>, TransactionTypes>} raw - The raw value to create the TransactionReceipt from.
|
|
71
|
+
* @returns {TransactionReceipt} The created TransactionReceipt instance.
|
|
72
|
+
*/
|
|
43
73
|
static from(raw) {
|
|
44
74
|
return new _TransactionReceipt(raw);
|
|
45
75
|
}
|
|
@@ -49,6 +79,12 @@ var SignedTransaction = class _SignedTransaction {
|
|
|
49
79
|
this.signed = signed;
|
|
50
80
|
this.type = "SignedTransaction";
|
|
51
81
|
}
|
|
82
|
+
/**
|
|
83
|
+
* Creates an instance of SignedTransaction from a non-promise value.
|
|
84
|
+
*
|
|
85
|
+
* @param {Exclude<NonPromise<T>, TransactionTypes>} raw - The raw value to create the SignedTransaction from.
|
|
86
|
+
* @returns {SignedTransaction} The created SignedTransaction instance.
|
|
87
|
+
*/
|
|
52
88
|
static from(raw) {
|
|
53
89
|
return new _SignedTransaction(raw);
|
|
54
90
|
}
|
|
@@ -58,6 +94,12 @@ var TransactionPending = class _TransactionPending {
|
|
|
58
94
|
this.pending = pending;
|
|
59
95
|
this.type = "TransactionPending";
|
|
60
96
|
}
|
|
97
|
+
/**
|
|
98
|
+
* Creates an instance of TransactionPending from a non-promise value.
|
|
99
|
+
*
|
|
100
|
+
* @param {Exclude<NonPromise<T>, TransactionTypes>} raw - The raw value to create the TransactionPending from.
|
|
101
|
+
* @returns {TransactionPending} The created TransactionPending instance.
|
|
102
|
+
*/
|
|
61
103
|
static from(raw) {
|
|
62
104
|
return new _TransactionPending(raw);
|
|
63
105
|
}
|
package/dist/index.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
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;;;ACtDO,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<T = unknown> {\n /**\n * Connect to a provider\n * @param provider\n */\n connect(provider: Provider): Signer<T>\n\n /**\n * Sign a transaction\n * @param buildTxRequest\n */\n buildTransaction(buildTxRequest: T): Promise<TransactionRequest>\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 * this function NEED to return a Promise because ethers.Signer.getAddress() return a Promise<string>\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;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAQ5C,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;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAQ5C,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;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAQ9C,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;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAQ/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;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAQ9C,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;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAQ7C,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;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAQ9C,OAAO,KAAQ,KAAmE;AAC9E,WAAO,IAAI,oBAAmB,GAAG;AAAA,EACrC;AACJ;;;AChEO,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\n /**\n * Creates an instance of Block from a non-promise value.\n *\n * @param {NonPromise<T>} raw - The raw value to create the Block from.\n * @returns {Block} The created Block instance.\n */\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\n /**\n * Creates an instance of BlockWithTransactions from a non-promise value.\n *\n * @param {NonPromise<T>} raw - The raw value to create the BlockWithTransactions from.\n * @returns {BlockWithTransactions} The created BlockWithTransactions instance.\n */\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\n /**\n * Creates an instance of TransactionRequest from a non-promise value.\n *\n * @param {Exclude<NonPromise<T>, TransactionTypes>} raw - The raw value to create the TransactionRequest from.\n * @returns {TransactionRequest} The created TransactionRequest instance.\n */\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\n /**\n * Creates an instance of TransactionResponse from a non-promise value.\n *\n * @param {Exclude<NonPromise<T>, TransactionTypes>} raw - The raw value to create the TransactionResponse from.\n * @returns {TransactionResponse} The created TransactionResponse instance.\n */\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\n /**\n * Creates an instance of TransactionReceipt from a non-promise value.\n *\n * @param {Exclude<NonPromise<T>, TransactionTypes>} raw - The raw value to create the TransactionReceipt from.\n * @returns {TransactionReceipt} The created TransactionReceipt instance.\n */\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\n /**\n * Creates an instance of SignedTransaction from a non-promise value.\n *\n * @param {Exclude<NonPromise<T>, TransactionTypes>} raw - The raw value to create the SignedTransaction from.\n * @returns {SignedTransaction} The created SignedTransaction instance.\n */\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\n /**\n * Creates an instance of TransactionPending from a non-promise value.\n *\n * @param {Exclude<NonPromise<T>, TransactionTypes>} raw - The raw value to create the TransactionPending from.\n * @returns {TransactionPending} The created TransactionPending instance.\n */\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\n/**\n * Interface representing a signer.\n *\n * @template T - The type of the transaction request.\n */\nexport interface Signer<T = unknown> {\n /**\n * Connect to a provider.\n *\n * @param {Provider} provider - The provider to connect to.\n * @returns {Signer<T>} The connected signer.\n */\n connect(provider: Provider): Signer<T>\n\n /**\n * Build a transaction.\n *\n * @param {T} buildTxRequest - The transaction request to build.\n * @returns {Promise<TransactionRequest>} A promise that resolves to the built transaction request.\n */\n buildTransaction(buildTxRequest: T): Promise<TransactionRequest>\n\n /**\n * Sign a transaction.\n *\n * @param {TransactionRequest} transaction - The transaction request to sign.\n * @returns {Promise<SignedTransaction>} A promise that resolves to the signed transaction.\n */\n signTransaction(transaction: TransactionRequest): Promise<SignedTransaction>\n\n /**\n * Send a transaction.\n *\n * @param {SignedTransaction} transaction - The signed transaction to send.\n * @param {unknown} [sendOptions] - Optional parameters for sending the transaction.\n * @returns {Promise<TransactionPending>} A promise that resolves to the pending transaction.\n */\n sendTransaction(transaction: SignedTransaction, sendOptions?: unknown): Promise<TransactionPending>\n\n /**\n * Send a transaction and wait for confirmation.\n *\n * @param {SignedTransaction} transaction - The signed transaction to send.\n * @param {unknown} [opts] - Optional parameters for sending and confirming the transaction.\n * @returns {Promise<TransactionReceipt>} A promise that resolves to the transaction receipt.\n */\n sendAndConfirm(transaction: SignedTransaction, opts?: unknown): Promise<TransactionReceipt>\n\n /**\n * Sign a buffer (e.g. a message hash).\n *\n * @param {Uint8Array} buffer - The buffer to sign.\n * @returns {Promise<Uint8Array>} A promise that resolves to the signed buffer.\n */\n signBuffer(buffer: Uint8Array): Promise<Uint8Array>\n\n /**\n * Get the address of the signer.\n * this function NEED to return a Promise because ethers.Signer.getAddress() return a Promise<string>\n *\n * @returns {Promise<string>} A promise that resolves to the address of the signer.\n */\n getAddress(): Promise<string>\n\n /**\n * Native signer object\n */\n native: unknown\n}\n\n/**\n * Interface representing a connectable object.\n *\n * @template T - The type of the connectable object.\n */\nexport interface Connectable<T> {\n /**\n * Connect to a provider.\n *\n * @template U - The type of the provider.\n * @param {U} provider - The provider to connect to.\n * @returns {T} The connected object.\n */\n connect<U>(provider: U): T\n}\n\n/**\n * Check if an object is connectable.\n *\n * @template T - The type of the connectable object.\n * @param {unknown} obj - The object to check.\n * @returns {obj is Connectable<T>} True if the object is connectable, false otherwise.\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": "3.0.
|
|
3
|
+
"version": "3.0.16",
|
|
4
4
|
"description": "LayerZero Core Library",
|
|
5
5
|
"license": "BUSL-1.1",
|
|
6
6
|
"exports": {
|
|
@@ -22,17 +22,10 @@
|
|
|
22
22
|
"clean": "$npm_execpath clean-prebuild && rimraf .turbo",
|
|
23
23
|
"clean-prebuild": "rimraf dist"
|
|
24
24
|
},
|
|
25
|
-
"dependencies": {
|
|
26
|
-
"@layerzerolabs/lz-foundation": "^3.0.15",
|
|
27
|
-
"@noble/ed25519": "^1.7.1",
|
|
28
|
-
"@noble/hashes": "^1.3.2",
|
|
29
|
-
"@noble/secp256k1": "^1.7.1",
|
|
30
|
-
"tiny-invariant": "^1.3.1"
|
|
31
|
-
},
|
|
32
25
|
"devDependencies": {
|
|
33
26
|
"@jest/globals": "^29.7.0",
|
|
34
|
-
"@layerzerolabs/tsup-config-next": "^3.0.
|
|
35
|
-
"@layerzerolabs/typescript-config-next": "^3.0.
|
|
27
|
+
"@layerzerolabs/tsup-config-next": "^3.0.16",
|
|
28
|
+
"@layerzerolabs/typescript-config-next": "^3.0.16",
|
|
36
29
|
"@types/jest": "^29.5.10",
|
|
37
30
|
"jest": "^29.7.0",
|
|
38
31
|
"rimraf": "^5.0.5",
|