@sequence0/sdk 1.1.2 → 2.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -1
- package/dist/chains/algorand.d.ts +44 -0
- package/dist/chains/algorand.d.ts.map +1 -0
- package/dist/chains/algorand.js +148 -0
- package/dist/chains/algorand.js.map +1 -0
- package/dist/chains/aptos.d.ts +39 -0
- package/dist/chains/aptos.d.ts.map +1 -0
- package/dist/chains/aptos.js +168 -0
- package/dist/chains/aptos.js.map +1 -0
- package/dist/chains/cardano.d.ts +42 -0
- package/dist/chains/cardano.d.ts.map +1 -0
- package/dist/chains/cardano.js +188 -0
- package/dist/chains/cardano.js.map +1 -0
- package/dist/chains/cosmos.d.ts +42 -0
- package/dist/chains/cosmos.d.ts.map +1 -0
- package/dist/chains/cosmos.js +216 -0
- package/dist/chains/cosmos.js.map +1 -0
- package/dist/chains/dogecoin-litecoin.d.ts +57 -0
- package/dist/chains/dogecoin-litecoin.d.ts.map +1 -0
- package/dist/chains/dogecoin-litecoin.js +521 -0
- package/dist/chains/dogecoin-litecoin.js.map +1 -0
- package/dist/chains/ethereum.d.ts.map +1 -1
- package/dist/chains/ethereum.js +16 -0
- package/dist/chains/ethereum.js.map +1 -1
- package/dist/chains/hedera.d.ts +113 -0
- package/dist/chains/hedera.d.ts.map +1 -0
- package/dist/chains/hedera.js +302 -0
- package/dist/chains/hedera.js.map +1 -0
- package/dist/chains/icp.d.ts +95 -0
- package/dist/chains/icp.d.ts.map +1 -0
- package/dist/chains/icp.js +520 -0
- package/dist/chains/icp.js.map +1 -0
- package/dist/chains/kaspa.d.ts +152 -0
- package/dist/chains/kaspa.d.ts.map +1 -0
- package/dist/chains/kaspa.js +790 -0
- package/dist/chains/kaspa.js.map +1 -0
- package/dist/chains/multiversx.d.ts +143 -0
- package/dist/chains/multiversx.d.ts.map +1 -0
- package/dist/chains/multiversx.js +524 -0
- package/dist/chains/multiversx.js.map +1 -0
- package/dist/chains/near.d.ts +40 -0
- package/dist/chains/near.d.ts.map +1 -0
- package/dist/chains/near.js +170 -0
- package/dist/chains/near.js.map +1 -0
- package/dist/chains/polkadot.d.ts +43 -0
- package/dist/chains/polkadot.d.ts.map +1 -0
- package/dist/chains/polkadot.js +179 -0
- package/dist/chains/polkadot.js.map +1 -0
- package/dist/chains/ripple.d.ts +41 -0
- package/dist/chains/ripple.d.ts.map +1 -0
- package/dist/chains/ripple.js +190 -0
- package/dist/chains/ripple.js.map +1 -0
- package/dist/chains/stellar.d.ts +40 -0
- package/dist/chains/stellar.d.ts.map +1 -0
- package/dist/chains/stellar.js +156 -0
- package/dist/chains/stellar.js.map +1 -0
- package/dist/chains/sui.d.ts +44 -0
- package/dist/chains/sui.d.ts.map +1 -0
- package/dist/chains/sui.js +157 -0
- package/dist/chains/sui.js.map +1 -0
- package/dist/chains/tezos.d.ts +43 -0
- package/dist/chains/tezos.d.ts.map +1 -0
- package/dist/chains/tezos.js +162 -0
- package/dist/chains/tezos.js.map +1 -0
- package/dist/chains/ton.d.ts +40 -0
- package/dist/chains/ton.d.ts.map +1 -0
- package/dist/chains/ton.js +168 -0
- package/dist/chains/ton.js.map +1 -0
- package/dist/chains/tron.d.ts +41 -0
- package/dist/chains/tron.d.ts.map +1 -0
- package/dist/chains/tron.js +124 -0
- package/dist/chains/tron.js.map +1 -0
- package/dist/core/atomic.d.ts +76 -0
- package/dist/core/atomic.d.ts.map +1 -0
- package/dist/core/atomic.js +39 -0
- package/dist/core/atomic.js.map +1 -0
- package/dist/core/client.d.ts +238 -0
- package/dist/core/client.d.ts.map +1 -1
- package/dist/core/client.js +536 -4
- package/dist/core/client.js.map +1 -1
- package/dist/core/delegation.d.ts +184 -0
- package/dist/core/delegation.d.ts.map +1 -0
- package/dist/core/delegation.js +37 -0
- package/dist/core/delegation.js.map +1 -0
- package/dist/core/programmable.d.ts +66 -0
- package/dist/core/programmable.d.ts.map +1 -0
- package/dist/core/programmable.js +36 -0
- package/dist/core/programmable.js.map +1 -0
- package/dist/core/solvency.d.ts +223 -0
- package/dist/core/solvency.d.ts.map +1 -0
- package/dist/core/solvency.js +267 -0
- package/dist/core/solvency.js.map +1 -0
- package/dist/core/types.d.ts +172 -1
- package/dist/core/types.d.ts.map +1 -1
- package/dist/core/universal-account.d.ts +438 -0
- package/dist/core/universal-account.d.ts.map +1 -0
- package/dist/core/universal-account.js +597 -0
- package/dist/core/universal-account.js.map +1 -0
- package/dist/core/witness.d.ts +197 -0
- package/dist/core/witness.d.ts.map +1 -0
- package/dist/core/witness.js +298 -0
- package/dist/core/witness.js.map +1 -0
- package/dist/erc4337/types.js +2 -2
- package/dist/index.d.ts +30 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +91 -4
- package/dist/index.js.map +1 -1
- package/dist/settlement/settlement.d.ts +152 -0
- package/dist/settlement/settlement.d.ts.map +1 -0
- package/dist/settlement/settlement.js +172 -0
- package/dist/settlement/settlement.js.map +1 -0
- package/dist/utils/eip712.js +2 -2
- package/dist/utils/fee.d.ts +2 -2
- package/dist/utils/fee.js +2 -2
- package/dist/utils/optional-deps.d.ts +9 -0
- package/dist/utils/optional-deps.d.ts.map +1 -0
- package/dist/utils/optional-deps.js +21 -0
- package/dist/utils/optional-deps.js.map +1 -0
- package/dist/utils/validation.d.ts.map +1 -1
- package/dist/utils/validation.js +6 -1
- package/dist/utils/validation.js.map +1 -1
- package/dist/wallet/wallet.d.ts +52 -0
- package/dist/wallet/wallet.d.ts.map +1 -1
- package/dist/wallet/wallet.js +265 -33
- package/dist/wallet/wallet.js.map +1 -1
- package/package.json +35 -1
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Hedera Chain Adapter
|
|
3
|
+
*
|
|
4
|
+
* Hedera supports a fully EVM-compatible JSON-RPC relay (Hashio),
|
|
5
|
+
* so this adapter is a thin wrapper around ethers.js pointed at
|
|
6
|
+
* Hedera's relay endpoint. Builds EIP-1559 transactions, attaches
|
|
7
|
+
* secp256k1 ECDSA signatures from the FROST threshold signing
|
|
8
|
+
* network, and broadcasts via the Hedera JSON-RPC relay.
|
|
9
|
+
*
|
|
10
|
+
* Curve: secp256k1 (ECDSA)
|
|
11
|
+
* Native token: HBAR (1 HBAR = 1e8 tinybars, 1e18 weibars via EVM relay)
|
|
12
|
+
*
|
|
13
|
+
* Hedera EVM relay uses standard 18-decimal wei denomination
|
|
14
|
+
* (like Ethereum), even though native HBAR uses 8-decimal tinybars.
|
|
15
|
+
* All values passed to buildTransaction should be in weibars (1e18).
|
|
16
|
+
*
|
|
17
|
+
* No external dependencies beyond ethers.js (already a core SDK dep).
|
|
18
|
+
*/
|
|
19
|
+
import { ChainAdapter, HederaTransaction } from '../core/types';
|
|
20
|
+
export declare class HederaAdapter implements ChainAdapter {
|
|
21
|
+
private provider;
|
|
22
|
+
private network;
|
|
23
|
+
private chainId;
|
|
24
|
+
private mirrorUrl;
|
|
25
|
+
constructor(network?: 'mainnet' | 'testnet', apiUrl?: string);
|
|
26
|
+
getRpcUrl(): string;
|
|
27
|
+
/**
|
|
28
|
+
* Build an unsigned EVM transaction for the Hedera JSON-RPC relay.
|
|
29
|
+
*
|
|
30
|
+
* The Hedera EVM relay is fully EIP-1559 compatible. Values are in
|
|
31
|
+
* weibars (1e18 per HBAR), consistent with standard EVM tooling.
|
|
32
|
+
*
|
|
33
|
+
* If a HederaTransaction is passed (with amount in tinybars), it is
|
|
34
|
+
* automatically converted to weibars for the EVM relay.
|
|
35
|
+
*
|
|
36
|
+
* @returns hex-encoded unsigned serialized transaction (RLP)
|
|
37
|
+
*/
|
|
38
|
+
buildTransaction(tx: HederaTransaction, fromAddress: string): Promise<string>;
|
|
39
|
+
/**
|
|
40
|
+
* Attach a secp256k1 ECDSA signature to the unsigned transaction.
|
|
41
|
+
*
|
|
42
|
+
* Expects a 65-byte signature: r (32) || s (32) || v (1).
|
|
43
|
+
* Same format as Ethereum — the Hedera EVM relay accepts
|
|
44
|
+
* standard signed EVM transactions.
|
|
45
|
+
*/
|
|
46
|
+
attachSignature(unsignedTx: string, signature: string): Promise<string>;
|
|
47
|
+
/**
|
|
48
|
+
* Broadcast a signed transaction via the Hedera JSON-RPC relay.
|
|
49
|
+
*
|
|
50
|
+
* The relay forwards the EVM transaction to the Hedera network
|
|
51
|
+
* where it is executed as a native HBAR transfer or contract call.
|
|
52
|
+
*
|
|
53
|
+
* @returns transaction hash
|
|
54
|
+
*/
|
|
55
|
+
broadcast(signedTx: string): Promise<string>;
|
|
56
|
+
/**
|
|
57
|
+
* Get HBAR balance via the EVM relay.
|
|
58
|
+
*
|
|
59
|
+
* Returns balance in weibars (1e18 per HBAR), consistent with
|
|
60
|
+
* the EVM relay denomination. Divide by 1e18 for HBAR.
|
|
61
|
+
*/
|
|
62
|
+
getBalance(address: string): Promise<string>;
|
|
63
|
+
/**
|
|
64
|
+
* Get HBAR balance in tinybars via the Mirror Node REST API.
|
|
65
|
+
*
|
|
66
|
+
* This uses the native Hedera denomination (1 HBAR = 1e8 tinybars)
|
|
67
|
+
* for applications that need the native format.
|
|
68
|
+
*/
|
|
69
|
+
getBalanceTinybars(accountId: string): Promise<string>;
|
|
70
|
+
/**
|
|
71
|
+
* Resolve a Hedera account ID (0.0.XXXXX) to an EVM address.
|
|
72
|
+
*
|
|
73
|
+
* If the input is already a 0x-prefixed EVM address, returns it as-is.
|
|
74
|
+
* Otherwise queries the Mirror Node to look up the EVM address.
|
|
75
|
+
*/
|
|
76
|
+
resolveAddress(address: string): Promise<string>;
|
|
77
|
+
/**
|
|
78
|
+
* Convert a Hedera account ID (0.0.XXXXX) to a "long-zero" EVM address.
|
|
79
|
+
*
|
|
80
|
+
* For accounts without an explicit EVM alias, Hedera maps account IDs
|
|
81
|
+
* to EVM addresses by zero-padding the account number into 20 bytes.
|
|
82
|
+
* e.g. 0.0.12345 -> 0x0000000000000000000000000000000000003039
|
|
83
|
+
*
|
|
84
|
+
* For accounts with an EVM alias, queries the Mirror Node.
|
|
85
|
+
*/
|
|
86
|
+
private accountIdToEvmAddress;
|
|
87
|
+
/**
|
|
88
|
+
* Look up account info from the Mirror Node REST API.
|
|
89
|
+
*/
|
|
90
|
+
getAccountInfo(accountId: string): Promise<Record<string, unknown> | null>;
|
|
91
|
+
/**
|
|
92
|
+
* Get transaction details from the Mirror Node REST API.
|
|
93
|
+
*/
|
|
94
|
+
getTransactionInfo(txId: string): Promise<Record<string, unknown> | null>;
|
|
95
|
+
/** Estimate gas for a transaction */
|
|
96
|
+
estimateGas(tx: HederaTransaction, fromAddress: string): Promise<bigint>;
|
|
97
|
+
/** Get current gas price from the relay */
|
|
98
|
+
getGasPrice(): Promise<{
|
|
99
|
+
maxFeePerGas: bigint;
|
|
100
|
+
maxPriorityFeePerGas: bigint;
|
|
101
|
+
}>;
|
|
102
|
+
/** Get current block number from the relay */
|
|
103
|
+
getBlockNumber(): Promise<number>;
|
|
104
|
+
/** Get transaction receipt from the relay */
|
|
105
|
+
getTransactionReceipt(hash: string): Promise<any>;
|
|
106
|
+
/** Wait for transaction confirmation */
|
|
107
|
+
waitForTransaction(hash: string, confirmations?: number): Promise<any>;
|
|
108
|
+
}
|
|
109
|
+
/** Create a mainnet Hedera adapter */
|
|
110
|
+
export declare function createHederaAdapter(apiUrl?: string): HederaAdapter;
|
|
111
|
+
/** Create a testnet Hedera adapter */
|
|
112
|
+
export declare function createHederaTestnetAdapter(apiUrl?: string): HederaAdapter;
|
|
113
|
+
//# sourceMappingURL=hedera.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"hedera.d.ts","sourceRoot":"","sources":["../../src/chains/hedera.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;GAiBG;AAGH,OAAO,EAAE,YAAY,EAAE,iBAAiB,EAAE,MAAM,eAAe,CAAC;AAqBhE,qBAAa,aAAc,YAAW,YAAY;IAC9C,OAAO,CAAC,QAAQ,CAAkB;IAClC,OAAO,CAAC,OAAO,CAAS;IACxB,OAAO,CAAC,OAAO,C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c,IAAI,OAAO,CAAC,MAAM,CAAC;IAIvC,6CAA6C;IACvC,qBAAqB,CAAC,IAAI,EAAE,MAAM;IAIxC,wCAAwC;IAClC,kBAAkB,CAAC,IAAI,EAAE,MAAM,EAAE,aAAa,SAAI;CAG3D;AAED,sCAAsC;AACtC,wBAAgB,mBAAmB,CAAC,MAAM,CAAC,EAAE,MAAM,GAAG,aAAa,CAElE;AAED,sCAAsC;AACtC,wBAAgB,0BAA0B,CAAC,MAAM,CAAC,EAAE,MAAM,GAAG,aAAa,CAEzE"}
|
|
@@ -0,0 +1,302 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Hedera Chain Adapter
|
|
4
|
+
*
|
|
5
|
+
* Hedera supports a fully EVM-compatible JSON-RPC relay (Hashio),
|
|
6
|
+
* so this adapter is a thin wrapper around ethers.js pointed at
|
|
7
|
+
* Hedera's relay endpoint. Builds EIP-1559 transactions, attaches
|
|
8
|
+
* secp256k1 ECDSA signatures from the FROST threshold signing
|
|
9
|
+
* network, and broadcasts via the Hedera JSON-RPC relay.
|
|
10
|
+
*
|
|
11
|
+
* Curve: secp256k1 (ECDSA)
|
|
12
|
+
* Native token: HBAR (1 HBAR = 1e8 tinybars, 1e18 weibars via EVM relay)
|
|
13
|
+
*
|
|
14
|
+
* Hedera EVM relay uses standard 18-decimal wei denomination
|
|
15
|
+
* (like Ethereum), even though native HBAR uses 8-decimal tinybars.
|
|
16
|
+
* All values passed to buildTransaction should be in weibars (1e18).
|
|
17
|
+
*
|
|
18
|
+
* No external dependencies beyond ethers.js (already a core SDK dep).
|
|
19
|
+
*/
|
|
20
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
21
|
+
exports.HederaAdapter = void 0;
|
|
22
|
+
exports.createHederaAdapter = createHederaAdapter;
|
|
23
|
+
exports.createHederaTestnetAdapter = createHederaTestnetAdapter;
|
|
24
|
+
const ethers_1 = require("ethers");
|
|
25
|
+
const errors_1 = require("../utils/errors");
|
|
26
|
+
/** EVM relay endpoints */
|
|
27
|
+
const DEFAULT_EVM_RELAYS = {
|
|
28
|
+
mainnet: 'https://mainnet.hashio.io/api',
|
|
29
|
+
testnet: 'https://testnet.hashio.io/api',
|
|
30
|
+
};
|
|
31
|
+
/** Mirror node REST API endpoints (used for Hedera-native queries) */
|
|
32
|
+
const DEFAULT_MIRROR_URLS = {
|
|
33
|
+
mainnet: 'https://mainnet-public.mirrornode.hedera.com',
|
|
34
|
+
testnet: 'https://testnet.mirrornode.hedera.com',
|
|
35
|
+
};
|
|
36
|
+
/** Hedera EVM chain IDs */
|
|
37
|
+
const CHAIN_IDS = {
|
|
38
|
+
mainnet: 295,
|
|
39
|
+
testnet: 296,
|
|
40
|
+
};
|
|
41
|
+
class HederaAdapter {
|
|
42
|
+
constructor(network = 'mainnet', apiUrl) {
|
|
43
|
+
this.network = network;
|
|
44
|
+
this.chainId = CHAIN_IDS[network];
|
|
45
|
+
this.mirrorUrl = DEFAULT_MIRROR_URLS[network];
|
|
46
|
+
const relayUrl = apiUrl || DEFAULT_EVM_RELAYS[network];
|
|
47
|
+
this.provider = new ethers_1.JsonRpcProvider(relayUrl);
|
|
48
|
+
}
|
|
49
|
+
getRpcUrl() {
|
|
50
|
+
// @ts-ignore - accessing internal URL
|
|
51
|
+
return this.provider._getConnection?.().url || DEFAULT_EVM_RELAYS[this.network];
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* Build an unsigned EVM transaction for the Hedera JSON-RPC relay.
|
|
55
|
+
*
|
|
56
|
+
* The Hedera EVM relay is fully EIP-1559 compatible. Values are in
|
|
57
|
+
* weibars (1e18 per HBAR), consistent with standard EVM tooling.
|
|
58
|
+
*
|
|
59
|
+
* If a HederaTransaction is passed (with amount in tinybars), it is
|
|
60
|
+
* automatically converted to weibars for the EVM relay.
|
|
61
|
+
*
|
|
62
|
+
* @returns hex-encoded unsigned serialized transaction (RLP)
|
|
63
|
+
*/
|
|
64
|
+
async buildTransaction(tx, fromAddress) {
|
|
65
|
+
try {
|
|
66
|
+
// Convert Hedera account ID to EVM address if needed
|
|
67
|
+
const toAddress = await this.resolveAddress(tx.to);
|
|
68
|
+
const fromAddr = await this.resolveAddress(fromAddress);
|
|
69
|
+
// Convert tinybars to weibars: 1 HBAR = 1e8 tinybars = 1e18 weibars
|
|
70
|
+
// So 1 tinybar = 1e10 weibars
|
|
71
|
+
const amountTinybars = BigInt(tx.amount);
|
|
72
|
+
const amountWeibars = amountTinybars * 10000000000n;
|
|
73
|
+
// Auto-fill nonce
|
|
74
|
+
const nonce = await this.provider.getTransactionCount(fromAddr, 'latest');
|
|
75
|
+
// Fetch fee data from the relay
|
|
76
|
+
const feeData = await this.provider.getFeeData();
|
|
77
|
+
// Estimate gas (simple transfer default: 80000 for Hedera)
|
|
78
|
+
const gasLimit = await this.provider.estimateGas({
|
|
79
|
+
from: fromAddr,
|
|
80
|
+
to: toAddress,
|
|
81
|
+
value: amountWeibars,
|
|
82
|
+
data: tx.memo ? ('0x' + Buffer.from(tx.memo).toString('hex')) : '0x',
|
|
83
|
+
}).catch(() => 80000n);
|
|
84
|
+
// Build EIP-1559 transaction
|
|
85
|
+
const txObj = {
|
|
86
|
+
to: toAddress,
|
|
87
|
+
value: amountWeibars,
|
|
88
|
+
data: tx.memo ? ('0x' + Buffer.from(tx.memo).toString('hex')) : '0x',
|
|
89
|
+
nonce,
|
|
90
|
+
gasLimit,
|
|
91
|
+
chainId: this.chainId,
|
|
92
|
+
type: 2,
|
|
93
|
+
maxFeePerGas: feeData.maxFeePerGas || 300000000000n,
|
|
94
|
+
maxPriorityFeePerGas: feeData.maxPriorityFeePerGas || 2000000000n,
|
|
95
|
+
};
|
|
96
|
+
// Serialize unsigned TX
|
|
97
|
+
const unsignedTx = ethers_1.Transaction.from(txObj);
|
|
98
|
+
return unsignedTx.unsignedSerialized;
|
|
99
|
+
}
|
|
100
|
+
catch (e) {
|
|
101
|
+
if (e instanceof errors_1.ChainError)
|
|
102
|
+
throw e;
|
|
103
|
+
throw new errors_1.ChainError(`Failed to build Hedera transaction: ${e.message}`, 'hedera');
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
/**
|
|
107
|
+
* Attach a secp256k1 ECDSA signature to the unsigned transaction.
|
|
108
|
+
*
|
|
109
|
+
* Expects a 65-byte signature: r (32) || s (32) || v (1).
|
|
110
|
+
* Same format as Ethereum — the Hedera EVM relay accepts
|
|
111
|
+
* standard signed EVM transactions.
|
|
112
|
+
*/
|
|
113
|
+
async attachSignature(unsignedTx, signature) {
|
|
114
|
+
try {
|
|
115
|
+
const sig = signature.startsWith('0x') ? signature.slice(2) : signature;
|
|
116
|
+
const r = '0x' + sig.slice(0, 64);
|
|
117
|
+
const s = '0x' + sig.slice(64, 128);
|
|
118
|
+
const v = parseInt(sig.slice(128, 130), 16) || 27;
|
|
119
|
+
const tx = ethers_1.Transaction.from(unsignedTx);
|
|
120
|
+
tx.signature = ethers_1.Signature.from({ r, s, v });
|
|
121
|
+
return tx.serialized;
|
|
122
|
+
}
|
|
123
|
+
catch (e) {
|
|
124
|
+
throw new errors_1.ChainError(`Failed to attach Hedera signature: ${e.message}`, 'hedera');
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
/**
|
|
128
|
+
* Broadcast a signed transaction via the Hedera JSON-RPC relay.
|
|
129
|
+
*
|
|
130
|
+
* The relay forwards the EVM transaction to the Hedera network
|
|
131
|
+
* where it is executed as a native HBAR transfer or contract call.
|
|
132
|
+
*
|
|
133
|
+
* @returns transaction hash
|
|
134
|
+
*/
|
|
135
|
+
async broadcast(signedTx) {
|
|
136
|
+
try {
|
|
137
|
+
const response = await this.provider.broadcastTransaction(signedTx);
|
|
138
|
+
return response.hash;
|
|
139
|
+
}
|
|
140
|
+
catch (e) {
|
|
141
|
+
throw new errors_1.ChainError(`Failed to broadcast Hedera tx: ${e.message}`, 'hedera');
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
/**
|
|
145
|
+
* Get HBAR balance via the EVM relay.
|
|
146
|
+
*
|
|
147
|
+
* Returns balance in weibars (1e18 per HBAR), consistent with
|
|
148
|
+
* the EVM relay denomination. Divide by 1e18 for HBAR.
|
|
149
|
+
*/
|
|
150
|
+
async getBalance(address) {
|
|
151
|
+
try {
|
|
152
|
+
const addr = await this.resolveAddress(address);
|
|
153
|
+
const balance = await this.provider.getBalance(addr);
|
|
154
|
+
return balance.toString();
|
|
155
|
+
}
|
|
156
|
+
catch {
|
|
157
|
+
return '0';
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
/**
|
|
161
|
+
* Get HBAR balance in tinybars via the Mirror Node REST API.
|
|
162
|
+
*
|
|
163
|
+
* This uses the native Hedera denomination (1 HBAR = 1e8 tinybars)
|
|
164
|
+
* for applications that need the native format.
|
|
165
|
+
*/
|
|
166
|
+
async getBalanceTinybars(accountId) {
|
|
167
|
+
try {
|
|
168
|
+
const url = `${this.mirrorUrl}/api/v1/balances?account.id=${accountId}`;
|
|
169
|
+
const response = await fetch(url);
|
|
170
|
+
if (!response.ok) {
|
|
171
|
+
throw new Error(`Mirror node returned ${response.status}`);
|
|
172
|
+
}
|
|
173
|
+
const data = await response.json();
|
|
174
|
+
if (data.balances && data.balances.length > 0) {
|
|
175
|
+
return data.balances[0].balance.toString();
|
|
176
|
+
}
|
|
177
|
+
return '0';
|
|
178
|
+
}
|
|
179
|
+
catch {
|
|
180
|
+
return '0';
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
/**
|
|
184
|
+
* Resolve a Hedera account ID (0.0.XXXXX) to an EVM address.
|
|
185
|
+
*
|
|
186
|
+
* If the input is already a 0x-prefixed EVM address, returns it as-is.
|
|
187
|
+
* Otherwise queries the Mirror Node to look up the EVM address.
|
|
188
|
+
*/
|
|
189
|
+
async resolveAddress(address) {
|
|
190
|
+
// Already an EVM address
|
|
191
|
+
if (address.startsWith('0x') && address.length === 42) {
|
|
192
|
+
return address;
|
|
193
|
+
}
|
|
194
|
+
// Hedera account ID format: 0.0.XXXXX
|
|
195
|
+
if (/^\d+\.\d+\.\d+$/.test(address)) {
|
|
196
|
+
return this.accountIdToEvmAddress(address);
|
|
197
|
+
}
|
|
198
|
+
// Return as-is and let the relay handle it
|
|
199
|
+
return address;
|
|
200
|
+
}
|
|
201
|
+
/**
|
|
202
|
+
* Convert a Hedera account ID (0.0.XXXXX) to a "long-zero" EVM address.
|
|
203
|
+
*
|
|
204
|
+
* For accounts without an explicit EVM alias, Hedera maps account IDs
|
|
205
|
+
* to EVM addresses by zero-padding the account number into 20 bytes.
|
|
206
|
+
* e.g. 0.0.12345 -> 0x0000000000000000000000000000000000003039
|
|
207
|
+
*
|
|
208
|
+
* For accounts with an EVM alias, queries the Mirror Node.
|
|
209
|
+
*/
|
|
210
|
+
async accountIdToEvmAddress(accountId) {
|
|
211
|
+
try {
|
|
212
|
+
// Try Mirror Node first to get the real EVM address
|
|
213
|
+
const url = `${this.mirrorUrl}/api/v1/accounts/${accountId}`;
|
|
214
|
+
const response = await fetch(url);
|
|
215
|
+
if (response.ok) {
|
|
216
|
+
const data = await response.json();
|
|
217
|
+
if (data.evm_address) {
|
|
218
|
+
return data.evm_address;
|
|
219
|
+
}
|
|
220
|
+
}
|
|
221
|
+
}
|
|
222
|
+
catch {
|
|
223
|
+
// Fall through to long-zero conversion
|
|
224
|
+
}
|
|
225
|
+
// Long-zero address fallback: pad the account number
|
|
226
|
+
const parts = accountId.split('.');
|
|
227
|
+
const accountNum = parseInt(parts[2], 10);
|
|
228
|
+
return '0x' + accountNum.toString(16).padStart(40, '0');
|
|
229
|
+
}
|
|
230
|
+
/**
|
|
231
|
+
* Look up account info from the Mirror Node REST API.
|
|
232
|
+
*/
|
|
233
|
+
async getAccountInfo(accountId) {
|
|
234
|
+
try {
|
|
235
|
+
const url = `${this.mirrorUrl}/api/v1/accounts/${accountId}`;
|
|
236
|
+
const response = await fetch(url);
|
|
237
|
+
if (!response.ok)
|
|
238
|
+
return null;
|
|
239
|
+
return await response.json();
|
|
240
|
+
}
|
|
241
|
+
catch {
|
|
242
|
+
return null;
|
|
243
|
+
}
|
|
244
|
+
}
|
|
245
|
+
/**
|
|
246
|
+
* Get transaction details from the Mirror Node REST API.
|
|
247
|
+
*/
|
|
248
|
+
async getTransactionInfo(txId) {
|
|
249
|
+
try {
|
|
250
|
+
const url = `${this.mirrorUrl}/api/v1/transactions/${txId}`;
|
|
251
|
+
const response = await fetch(url);
|
|
252
|
+
if (!response.ok)
|
|
253
|
+
return null;
|
|
254
|
+
return await response.json();
|
|
255
|
+
}
|
|
256
|
+
catch {
|
|
257
|
+
return null;
|
|
258
|
+
}
|
|
259
|
+
}
|
|
260
|
+
/** Estimate gas for a transaction */
|
|
261
|
+
async estimateGas(tx, fromAddress) {
|
|
262
|
+
const fromAddr = await this.resolveAddress(fromAddress);
|
|
263
|
+
const toAddr = await this.resolveAddress(tx.to);
|
|
264
|
+
const amountWeibars = BigInt(tx.amount) * 10000000000n;
|
|
265
|
+
return this.provider.estimateGas({
|
|
266
|
+
from: fromAddr,
|
|
267
|
+
to: toAddr,
|
|
268
|
+
value: amountWeibars,
|
|
269
|
+
data: tx.memo ? ('0x' + Buffer.from(tx.memo).toString('hex')) : '0x',
|
|
270
|
+
});
|
|
271
|
+
}
|
|
272
|
+
/** Get current gas price from the relay */
|
|
273
|
+
async getGasPrice() {
|
|
274
|
+
const feeData = await this.provider.getFeeData();
|
|
275
|
+
return {
|
|
276
|
+
maxFeePerGas: feeData.maxFeePerGas || 300000000000n,
|
|
277
|
+
maxPriorityFeePerGas: feeData.maxPriorityFeePerGas || 2000000000n,
|
|
278
|
+
};
|
|
279
|
+
}
|
|
280
|
+
/** Get current block number from the relay */
|
|
281
|
+
async getBlockNumber() {
|
|
282
|
+
return this.provider.getBlockNumber();
|
|
283
|
+
}
|
|
284
|
+
/** Get transaction receipt from the relay */
|
|
285
|
+
async getTransactionReceipt(hash) {
|
|
286
|
+
return this.provider.getTransactionReceipt(hash);
|
|
287
|
+
}
|
|
288
|
+
/** Wait for transaction confirmation */
|
|
289
|
+
async waitForTransaction(hash, confirmations = 1) {
|
|
290
|
+
return this.provider.waitForTransaction(hash, confirmations);
|
|
291
|
+
}
|
|
292
|
+
}
|
|
293
|
+
exports.HederaAdapter = HederaAdapter;
|
|
294
|
+
/** Create a mainnet Hedera adapter */
|
|
295
|
+
function createHederaAdapter(apiUrl) {
|
|
296
|
+
return new HederaAdapter('mainnet', apiUrl);
|
|
297
|
+
}
|
|
298
|
+
/** Create a testnet Hedera adapter */
|
|
299
|
+
function createHederaTestnetAdapter(apiUrl) {
|
|
300
|
+
return new HederaAdapter('testnet', apiUrl);
|
|
301
|
+
}
|
|
302
|
+
//# sourceMappingURL=hedera.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"hedera.js","sourceRoot":"","sources":["../../src/chains/hedera.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;GAiBG;;;AAqTH,kDAEC;AAGD,gEAEC;AA1TD,mCAAiE;AAEjE,4CAA6C;AAE7C,0BAA0B;AAC1B,MAAM,kBAAkB,GAA2B;IAC/C,OAAO,EAAE,+BAA+B;IACxC,OAAO,EAAE,+BAA+B;CAC3C,CAAC;AAEF,sEAAsE;AACtE,MAAM,mBAAmB,GAA2B;IAChD,OAAO,EAAE,8CAA8C;IACvD,OAAO,EAAE,uCAAuC;CACnD,CAAC;AAEF,2BAA2B;AAC3B,MAAM,SAAS,GAA2B;IACtC,OAAO,EAAE,GAAG;IACZ,OAAO,EAAE,GAAG;CACf,CAAC;AAEF,MAAa,aAAa;IAMtB,YAAY,UAAiC,SAAS,EAAE,MAAe;QACnE,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC;QACvB,IAAI,CAAC,OAAO,GAAG,SAAS,CAAC,OAAO,CAAC,CAAC;QAClC,IAAI,CAAC,SAAS,GAAG,mBAAmB,CAAC,OAAO,CAAC,CAAC;QAC9C,MAAM,QAAQ,GAAG,MAAM,IAAI,kBAAkB,CAAC,OAAO,CA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,CAAC,qBAAqB,CAAC,IAAI,CAAC,CAAC;IACrD,CAAC;IAED,wCAAwC;IACxC,KAAK,CAAC,kBAAkB,CAAC,IAAY,EAAE,aAAa,GAAG,CAAC;QACpD,OAAO,IAAI,CAAC,QAAQ,CAAC,kBAAkB,CAAC,IAAI,EAAE,aAAa,CAAC,CAAC;IACjE,CAAC;CACJ;AA1RD,sCA0RC;AAED,sCAAsC;AACtC,SAAgB,mBAAmB,CAAC,MAAe;IAC/C,OAAO,IAAI,aAAa,CAAC,SAAS,EAAE,MAAM,CAAC,CAAC;AAChD,CAAC;AAED,sCAAsC;AACtC,SAAgB,0BAA0B,CAAC,MAAe;IACtD,OAAO,IAAI,aAAa,CAAC,SAAS,EAAE,MAAM,CAAC,CAAC;AAChD,CAAC"}
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Internet Computer (ICP) Chain Adapter
|
|
3
|
+
*
|
|
4
|
+
* Builds ICP ledger transfer requests, computes the signing payload
|
|
5
|
+
* as SHA-256 of the request envelope, attaches secp256k1 ECDSA
|
|
6
|
+
* signatures from the FROST threshold signing network, and
|
|
7
|
+
* broadcasts via the IC HTTP API.
|
|
8
|
+
*
|
|
9
|
+
* Curve: secp256k1 (ECDSA)
|
|
10
|
+
* Native token: ICP (1 ICP = 1e8 e8s)
|
|
11
|
+
* API: IC HTTP API at https://ic0.app
|
|
12
|
+
*
|
|
13
|
+
* No external dependencies — uses raw HTTP calls and built-in crypto.
|
|
14
|
+
*
|
|
15
|
+
* The ICP transaction model is canister-call based. A transfer is a
|
|
16
|
+
* call to the ICP ledger canister (ryjl3-tyaaa-aaaaa-aaaba-cai) with
|
|
17
|
+
* the "transfer" method. The signing payload is the SHA-256 hash of
|
|
18
|
+
* the CBOR-encoded request ID derived from the request content map.
|
|
19
|
+
*/
|
|
20
|
+
import { ChainAdapter, IcpTransaction } from '../core/types';
|
|
21
|
+
export declare class IcpAdapter implements ChainAdapter {
|
|
22
|
+
private apiUrl;
|
|
23
|
+
private network;
|
|
24
|
+
constructor(network?: 'mainnet' | 'local', apiUrl?: string);
|
|
25
|
+
getRpcUrl(): string;
|
|
26
|
+
/**
|
|
27
|
+
* Build an unsigned ICP ledger transfer request.
|
|
28
|
+
*
|
|
29
|
+
* Constructs the transfer call content map, computes the request ID
|
|
30
|
+
* (signing payload), and returns the hex-encoded payload containing
|
|
31
|
+
* all information needed for signing and broadcast.
|
|
32
|
+
*
|
|
33
|
+
* The signing payload is: SHA-256(domain_separator || request_id)
|
|
34
|
+
* where domain_separator = "\x0Aic-request"
|
|
35
|
+
*
|
|
36
|
+
* @param tx - ICP transfer details (to, amount in e8s, optional memo/fee)
|
|
37
|
+
* @param fromAddress - Sender's principal or account ID (hex)
|
|
38
|
+
* @returns hex-encoded JSON payload with signingHash and request data
|
|
39
|
+
*/
|
|
40
|
+
buildTransaction(tx: IcpTransaction, fromAddress: string): Promise<string>;
|
|
41
|
+
/**
|
|
42
|
+
* Extract the signing payload (SHA-256 hash) from the build output.
|
|
43
|
+
*
|
|
44
|
+
* The signing payload is the SHA-256 of (domain_separator || request_id).
|
|
45
|
+
* This is the 32-byte hash that the FROST network signs with secp256k1.
|
|
46
|
+
*/
|
|
47
|
+
getSigningPayload(unsignedTx: string): string;
|
|
48
|
+
/**
|
|
49
|
+
* Attach a secp256k1 ECDSA signature to the ICP request envelope.
|
|
50
|
+
*
|
|
51
|
+
* The IC expects the signature in DER-encoded format within a
|
|
52
|
+
* CBOR envelope. We store the 65-byte raw signature (r||s||v)
|
|
53
|
+
* and convert during broadcast.
|
|
54
|
+
*/
|
|
55
|
+
attachSignature(unsignedTx: string, signature: string): Promise<string>;
|
|
56
|
+
/**
|
|
57
|
+
* Broadcast a signed ICP transaction via the IC HTTP API.
|
|
58
|
+
*
|
|
59
|
+
* Submits the signed request envelope to:
|
|
60
|
+
* POST /api/v2/canister/{canister_id}/call
|
|
61
|
+
*
|
|
62
|
+
* The IC returns a 202 Accepted on success with the request ID
|
|
63
|
+
* that can be polled for status.
|
|
64
|
+
*
|
|
65
|
+
* @returns request ID (hex) which serves as the transaction identifier
|
|
66
|
+
*/
|
|
67
|
+
broadcast(signedTx: string): Promise<string>;
|
|
68
|
+
/**
|
|
69
|
+
* Get ICP balance in e8s (1 ICP = 1e8 e8s).
|
|
70
|
+
*
|
|
71
|
+
* Queries the ledger canister using the read_state/query endpoint
|
|
72
|
+
* with the "icrc1_balance_of" method.
|
|
73
|
+
*
|
|
74
|
+
* @param address - Principal ID or account ID (hex)
|
|
75
|
+
* @returns balance in e8s as string
|
|
76
|
+
*/
|
|
77
|
+
getBalance(address: string): Promise<string>;
|
|
78
|
+
/**
|
|
79
|
+
* Check the status of a submitted request.
|
|
80
|
+
*
|
|
81
|
+
* After broadcast, callers can poll this method with the request ID
|
|
82
|
+
* to check whether the transfer was accepted by the ledger canister.
|
|
83
|
+
*
|
|
84
|
+
* @param requestId - hex-encoded request ID from broadcast()
|
|
85
|
+
* @returns status string: 'received', 'processing', 'replied', 'rejected', 'done', or 'unknown'
|
|
86
|
+
*/
|
|
87
|
+
getRequestStatus(requestId: string): Promise<string>;
|
|
88
|
+
/**
|
|
89
|
+
* Get the ICP ledger canister ID.
|
|
90
|
+
*/
|
|
91
|
+
getLedgerCanisterId(): string;
|
|
92
|
+
}
|
|
93
|
+
/** Create a mainnet ICP adapter */
|
|
94
|
+
export declare function createIcpAdapter(apiUrl?: string): IcpAdapter;
|
|
95
|
+
//# sourceMappingURL=icp.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"icp.d.ts","sourceRoot":"","sources":["../../src/chains/icp.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;GAkBG;AAGH,OAAO,EAAE,YAAY,EAAE,cAAc,EAAE,MAAM,eAAe,CAAC;AAgJ7D,qBAAa,UAAW,YAAW,YAAY;IAC3C,OAAO,CAAC,MAAM,CAAS;IACvB,OAAO,CAAC,OAAO,CAAS;gBAEZ,OAAO,GAAE,SAAS,GAAG,OAAmB,EAAE,MAAM,CAAC,EAAE,MAAM;IAKrE,SAAS,IAAI,MAAM;IAInB;;;;;;;;;;;;;OAaG;IACG,gBAAgB,CAAC,EAAE,EAAE,cAAc,EAAE,WAAW,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC;IAoEhF;;;;;OAKG;IACH,iBAAiB,CAAC,UAAU,EAAE,MAAM,GAAG,MAAM;IAS7C;;;;;;OAMG;IACG,eAAe,CAAC,UAAU,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC;IAmB7E;;;;;;;;;;OAUG;IACG,SAAS,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC;IA+DlD;;;;;;;;OAQG;IACG,UAAU,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC;IA2DlD;;;;;;;;OAQG;IACG,gBAAgB,CAAC,SAAS,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC;IAmD1D;;OAEG;IACH,mBAAmB,IAAI,MAAM;CAGhC;AA0FD,mCAAmC;AACnC,wBAAgB,gBAAgB,CAAC,MAAM,CAAC,EAAE,MAAM,GAAG,UAAU,CAE5D"}
|