signet.js 0.0.7 → 0.0.9-retry
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 +8 -1
- package/browser/index.browser.cjs +3 -0
- package/browser/index.browser.cjs.map +1 -0
- package/browser/index.browser.js +3 -0
- package/browser/index.browser.js.map +1 -0
- package/node/index.node.cjs +3 -0
- package/node/index.node.cjs.map +1 -0
- package/node/index.node.js +3 -0
- package/node/index.node.js.map +1 -0
- package/package.json +19 -18
- package/types/index.d.cts +1048 -0
- package/types/index.d.ts +1048 -0
- package/.eslintrc.json +0 -67
- package/.prettierrc +0 -1
- package/babel.config.js +0 -6
- package/docs/dist/.vocs/icons/arrow-diagonal.svg +0 -3
- package/docs/dist/.vocs/icons/chevron-down.svg +0 -13
- package/docs/dist/.vocs/icons/chevron-up.svg +0 -13
- package/docs/dist/.vocs/icons/link.svg +0 -3
- package/docs/dist/.vocs/search-index-7b499e25.json +0 -1
- package/docs/dist/assets/arbitrary-hash-Cd6eo8ZD.js +0 -309
- package/docs/dist/assets/broadcast-tx-CeTEE9yX.js +0 -8
- package/docs/dist/assets/btc-rpc-adapter-C-qSHpFV.js +0 -226
- package/docs/dist/assets/chain-adapter-interface-B9TpOgQv.js +0 -1280
- package/docs/dist/assets/chain-contract-interface-DEku3k45.js +0 -392
- package/docs/dist/assets/constructor-73n7bp3b.js +0 -161
- package/docs/dist/assets/constructor-Bg7nvLe0.js +0 -14
- package/docs/dist/assets/contract-addresses-BYlrAOs3.js +0 -200
- package/docs/dist/assets/derive-address-and-public-key-DExrKiGV.js +0 -14
- package/docs/dist/assets/finalize-message-signing-W435d71R.js +0 -20
- package/docs/dist/assets/finalize-transaction-signing-BIgJ2dnc.js +0 -36
- package/docs/dist/assets/finalize-transaction-signing-C--HJs8D.js +0 -24
- package/docs/dist/assets/finalize-transaction-signing-CjGmN7d9.js +0 -24
- package/docs/dist/assets/finalize-typed-data-signing-CEOp_GWt.js +0 -21
- package/docs/dist/assets/get-balance-DBC-i6KG.js +0 -13
- package/docs/dist/assets/get-current-signature-deposit-BXm9AzYy.js +0 -6
- package/docs/dist/assets/get-current-signature-deposit-nOw4j1MN.js +0 -6
- package/docs/dist/assets/get-derived-public-key-BXvfo2m2.js +0 -14
- package/docs/dist/assets/get-derived-public-key-DQ1pyiFS.js +0 -14
- package/docs/dist/assets/get-latest-key-version-DWlkMCre.js +0 -6
- package/docs/dist/assets/get-public-key-B4PFoVqu.js +0 -6
- package/docs/dist/assets/get-public-key-B9xkYkD_.js +0 -6
- package/docs/dist/assets/index-BFuwoY4w.js +0 -601
- package/docs/dist/assets/index-C62Mf-vy.js +0 -426
- package/docs/dist/assets/index-D8xhaiVb.js +0 -121
- package/docs/dist/assets/index-DTr0DlO0.js +0 -36
- package/docs/dist/assets/index-V9dXf-ik.js +0 -457
- package/docs/dist/assets/prepare-message-for-signing-DESTq-Hg.js +0 -16
- package/docs/dist/assets/prepare-transaction-for-signing-DIKTU0zj.js +0 -33
- package/docs/dist/assets/prepare-transaction-for-signing-DV_wkZ5g.js +0 -21
- package/docs/dist/assets/prepare-transaction-for-signing-LVDP0COu.js +0 -33
- package/docs/dist/assets/prepare-typed-data-for-signing-CWcmJvw0.js +0 -192
- package/docs/dist/assets/sign-CwtS5LnB.js +0 -13
- package/docs/dist/assets/sign-OQxf9yn7.js +0 -15
- package/docs/dist/assets/signet-quick-start-CQK52nVG.js +0 -350
- package/docs/dist/assets/sponsor-foreign-chain-gas-C9iWXM8Q.js +0 -1
- package/docs/dist/assets/style-CKGXuRqx.css +0 -1
- package/docs/dist/examples/arbitrary-hash/index.html +0 -88
- package/docs/dist/examples/sponsor-foreign-chain-gas/index.html +0 -21
- package/docs/dist/index.html +0 -56
- package/docs/dist/initializeTheme.iife.js +0 -1
- package/docs/dist/introduction/signet-quick-start/index.html +0 -109
- package/docs/dist/primitives/chain-adapter-interface/index.html +0 -515
- package/docs/dist/primitives/chain-contract-interface/index.html +0 -306
- package/docs/dist/primitives/contract-addresses/index.html +0 -97
- package/docs/dist/signet-logo.png +0 -0
- package/docs/dist/signetjs/chain-adapters/bitcoin/btc-rpc-adapter/index.html +0 -148
- package/docs/dist/signetjs/chain-adapters/bitcoin/finalize-transaction-signing/index.html +0 -41
- package/docs/dist/signetjs/chain-adapters/bitcoin/index.html +0 -187
- package/docs/dist/signetjs/chain-adapters/bitcoin/prepare-transaction-for-signing/index.html +0 -34
- package/docs/dist/signetjs/chain-adapters/broadcast-tx/index.html +0 -28
- package/docs/dist/signetjs/chain-adapters/cosmos/finalize-transaction-signing/index.html +0 -41
- package/docs/dist/signetjs/chain-adapters/cosmos/index.html +0 -166
- package/docs/dist/signetjs/chain-adapters/cosmos/prepare-transaction-for-signing/index.html +0 -43
- package/docs/dist/signetjs/chain-adapters/derive-address-and-public-key/index.html +0 -31
- package/docs/dist/signetjs/chain-adapters/evm/finalize-message-signing/index.html +0 -38
- package/docs/dist/signetjs/chain-adapters/evm/finalize-transaction-signing/index.html +0 -41
- package/docs/dist/signetjs/chain-adapters/evm/finalize-typed-data-signing/index.html +0 -39
- package/docs/dist/signetjs/chain-adapters/evm/index.html +0 -129
- package/docs/dist/signetjs/chain-adapters/evm/prepare-message-for-signing/index.html +0 -31
- package/docs/dist/signetjs/chain-adapters/evm/prepare-transaction-for-signing/index.html +0 -34
- package/docs/dist/signetjs/chain-adapters/evm/prepare-typed-data-for-signing/index.html +0 -49
- package/docs/dist/signetjs/chain-adapters/get-balance/index.html +0 -30
- package/docs/dist/signetjs/contracts/evm/constructor/index.html +0 -45
- package/docs/dist/signetjs/contracts/evm/get-current-signature-deposit/index.html +0 -26
- package/docs/dist/signetjs/contracts/evm/get-derived-public-key/index.html +0 -31
- package/docs/dist/signetjs/contracts/evm/get-latest-key-version/index.html +0 -26
- package/docs/dist/signetjs/contracts/evm/get-public-key/index.html +0 -26
- package/docs/dist/signetjs/contracts/evm/sign/index.html +0 -32
- package/docs/dist/signetjs/contracts/near/constructor/index.html +0 -34
- package/docs/dist/signetjs/contracts/near/get-current-signature-deposit/index.html +0 -26
- package/docs/dist/signetjs/contracts/near/get-derived-public-key/index.html +0 -31
- package/docs/dist/signetjs/contracts/near/get-public-key/index.html +0 -26
- package/docs/dist/signetjs/contracts/near/sign/index.html +0 -32
- package/docs/pages/examples/arbitrary-hash.mdx +0 -73
- package/docs/pages/examples/sponsor-foreign-chain-gas.mdx +0 -1
- package/docs/pages/index.mdx +0 -36
- package/docs/pages/introduction/signet-quick-start.mdx +0 -88
- package/docs/pages/primitives/chain-adapter-interface.mdx +0 -45
- package/docs/pages/primitives/chain-contract-interface.mdx +0 -52
- package/docs/pages/primitives/contract-addresses.mdx +0 -27
- package/docs/pages/signetjs/chain-adapters/bitcoin/btc-rpc-adapter.mdx +0 -26
- package/docs/pages/signetjs/chain-adapters/bitcoin/finalize-transaction-signing.mdx +0 -47
- package/docs/pages/signetjs/chain-adapters/bitcoin/index.mdx +0 -119
- package/docs/pages/signetjs/chain-adapters/bitcoin/prepare-transaction-for-signing.mdx +0 -30
- package/docs/pages/signetjs/chain-adapters/broadcast-tx.mdx +0 -23
- package/docs/pages/signetjs/chain-adapters/cosmos/finalize-transaction-signing.mdx +0 -53
- package/docs/pages/signetjs/chain-adapters/cosmos/index.mdx +0 -108
- package/docs/pages/signetjs/chain-adapters/cosmos/prepare-transaction-for-signing.mdx +0 -39
- package/docs/pages/signetjs/chain-adapters/derive-address-and-public-key.mdx +0 -28
- package/docs/pages/signetjs/chain-adapters/evm/finalize-message-signing.mdx +0 -33
- package/docs/pages/signetjs/chain-adapters/evm/finalize-transaction-signing.mdx +0 -44
- package/docs/pages/signetjs/chain-adapters/evm/finalize-typed-data-signing.mdx +0 -34
- package/docs/pages/signetjs/chain-adapters/evm/index.mdx +0 -84
- package/docs/pages/signetjs/chain-adapters/evm/prepare-message-for-signing.mdx +0 -26
- package/docs/pages/signetjs/chain-adapters/evm/prepare-transaction-for-signing.mdx +0 -30
- package/docs/pages/signetjs/chain-adapters/evm/prepare-typed-data-for-signing.mdx +0 -44
- package/docs/pages/signetjs/chain-adapters/get-balance.mdx +0 -26
- package/docs/pages/signetjs/contracts/evm/constructor.mdx +0 -38
- package/docs/pages/signetjs/contracts/evm/get-current-signature-deposit.mdx +0 -17
- package/docs/pages/signetjs/contracts/evm/get-derived-public-key.mdx +0 -28
- package/docs/pages/signetjs/contracts/evm/get-latest-key-version.mdx +0 -17
- package/docs/pages/signetjs/contracts/evm/get-public-key.mdx +0 -17
- package/docs/pages/signetjs/contracts/evm/sign.mdx +0 -36
- package/docs/pages/signetjs/contracts/near/constructor.mdx +0 -29
- package/docs/pages/signetjs/contracts/near/get-current-signature-deposit.mdx +0 -17
- package/docs/pages/signetjs/contracts/near/get-derived-public-key.mdx +0 -28
- package/docs/pages/signetjs/contracts/near/get-public-key.mdx +0 -17
- package/docs/pages/signetjs/contracts/near/sign.mdx +0 -32
- package/docs/public/signet-logo.png +0 -0
- package/docs/snippets/code/chains.ts +0 -42
- package/docs/snippets/code/contract.ts +0 -44
- package/docs/snippets/code/evm/contract.ts +0 -24
- package/docs/snippets/code/evm/env.ts +0 -16
- package/docs/snippets/code/near/env.ts +0 -13
- package/hardhat.config.mts +0 -19
- package/src/chain-adapters/Bitcoin/BTCRpcAdapter/BTCRpcAdapter.ts +0 -15
- package/src/chain-adapters/Bitcoin/BTCRpcAdapter/Mempool/Mempool.ts +0 -101
- package/src/chain-adapters/Bitcoin/BTCRpcAdapter/Mempool/index.ts +0 -1
- package/src/chain-adapters/Bitcoin/BTCRpcAdapter/Mempool/types.ts +0 -72
- package/src/chain-adapters/Bitcoin/BTCRpcAdapter/index.ts +0 -6
- package/src/chain-adapters/Bitcoin/Bitcoin.ts +0 -287
- package/src/chain-adapters/Bitcoin/index.ts +0 -13
- package/src/chain-adapters/Bitcoin/types.ts +0 -48
- package/src/chain-adapters/Bitcoin/utils.ts +0 -14
- package/src/chain-adapters/ChainAdapter.ts +0 -92
- package/src/chain-adapters/Cosmos/Cosmos.ts +0 -258
- package/src/chain-adapters/Cosmos/index.ts +0 -8
- package/src/chain-adapters/Cosmos/types.ts +0 -35
- package/src/chain-adapters/Cosmos/utils.ts +0 -45
- package/src/chain-adapters/EVM/EVM.test.ts +0 -238
- package/src/chain-adapters/EVM/EVM.ts +0 -337
- package/src/chain-adapters/EVM/index.ts +0 -11
- package/src/chain-adapters/EVM/types.ts +0 -53
- package/src/chain-adapters/EVM/utils.ts +0 -27
- package/src/chain-adapters/index.ts +0 -5
- package/src/constants.ts +0 -62
- package/src/contracts/ChainSignatureContract.ts +0 -65
- package/src/contracts/evm/ChainSignaturesContract.ts +0 -323
- package/src/contracts/evm/ChainSignaturesContractABI.ts +0 -359
- package/src/contracts/evm/errors.ts +0 -52
- package/src/contracts/evm/index.ts +0 -10
- package/src/contracts/evm/types.ts +0 -39
- package/src/contracts/evm/utils.ts +0 -41
- package/src/contracts/index.ts +0 -4
- package/src/contracts/near/ChainSignatureContract.ts +0 -196
- package/src/contracts/near/account.ts +0 -42
- package/src/contracts/near/constants.ts +0 -4
- package/src/contracts/near/index.ts +0 -10
- package/src/contracts/near/signAndSend/index.ts +0 -1
- package/src/contracts/near/signAndSend/keypair.ts +0 -178
- package/src/contracts/near/transaction.ts +0 -202
- package/src/contracts/near/types.ts +0 -71
- package/src/index.ts +0 -5
- package/src/types.ts +0 -46
- package/src/utils/cryptography.ts +0 -141
- package/src/utils/index.ts +0 -1
- package/src/utils/publicKey.ts +0 -17
- package/tsconfig.eslint.json +0 -8
- package/tsconfig.json +0 -126
- package/tsup.config.ts +0 -58
- package/vitest.config.ts +0 -19
- package/vocs.config.ts +0 -213
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
# Constructor
|
|
2
|
-
|
|
3
|
-
Creates a new instance of the NEAR Chain Signature Contract.
|
|
4
|
-
|
|
5
|
-
## Usage
|
|
6
|
-
|
|
7
|
-
```ts twoslash
|
|
8
|
-
import { contracts } from 'signet.js'
|
|
9
|
-
import { KeyPair } from '@near-js/crypto'
|
|
10
|
-
|
|
11
|
-
const contract = new contracts.near.ChainSignatureContract({
|
|
12
|
-
networkId: 'testnet',
|
|
13
|
-
contractId: 'chainsig.testnet',
|
|
14
|
-
accountId: 'your-account.testnet',
|
|
15
|
-
keypair: KeyPair.fromString('ed25519:your-private-key'),
|
|
16
|
-
})
|
|
17
|
-
```
|
|
18
|
-
|
|
19
|
-
## Parameters
|
|
20
|
-
|
|
21
|
-
| Parameter | Type | Description |
|
|
22
|
-
| ------------------------------ | ---------------------------- | ------------------------------------------------------------------------------- |
|
|
23
|
-
| `args` | `ChainSignatureContractArgs` | Configuration options for the contract |
|
|
24
|
-
| `args.networkId` | `NearNetworkIds` | The NEAR network ID ('mainnet', 'testnet', etc.) |
|
|
25
|
-
| `args.contractId` | `ChainSignatureContractIds` | The contract ID of the Chain Signatures contract |
|
|
26
|
-
| `args.accountId?` | `string` | Optional account ID to use for transactions. Defaults to a placeholder account |
|
|
27
|
-
| `args.keypair?` | `KeyPair` | Optional keypair to use for transactions. Defaults to a random keypair |
|
|
28
|
-
| `args.rootPublicKey?` | `NajPublicKey` | Optional root public key. If not provided, it will be fetched from the contract |
|
|
29
|
-
| `args.sendTransactionOptions?` | `SendTransactionOptions` | Optional configuration for sending transactions |
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
# getCurrentSignatureDeposit
|
|
2
|
-
|
|
3
|
-
Retrieves the current signature deposit amount required by the contract.
|
|
4
|
-
|
|
5
|
-
## Usage
|
|
6
|
-
|
|
7
|
-
```ts twoslash
|
|
8
|
-
// [!include ~/snippets/code/contract.ts]
|
|
9
|
-
// ---cut---
|
|
10
|
-
const deposit = await nearChainSigContract.getCurrentSignatureDeposit()
|
|
11
|
-
```
|
|
12
|
-
|
|
13
|
-
## Returns
|
|
14
|
-
|
|
15
|
-
| Type | Description |
|
|
16
|
-
| ------------- | ------------------------------------------------- |
|
|
17
|
-
| `Promise<BN>` | The current signature deposit amount in yoctoNEAR |
|
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
# getDerivedPublicKey
|
|
2
|
-
|
|
3
|
-
Derives a public key from a predecessor ID and derivation path.
|
|
4
|
-
|
|
5
|
-
## Usage
|
|
6
|
-
|
|
7
|
-
```ts twoslash
|
|
8
|
-
// [!include ~/snippets/code/contract.ts]
|
|
9
|
-
// ---cut---
|
|
10
|
-
const publicKey = await nearChainSigContract.getDerivedPublicKey({
|
|
11
|
-
path: 'my_derivation_path',
|
|
12
|
-
predecessor: 'your-account.testnet',
|
|
13
|
-
})
|
|
14
|
-
```
|
|
15
|
-
|
|
16
|
-
## Parameters
|
|
17
|
-
|
|
18
|
-
| Parameter | Type | Description |
|
|
19
|
-
| ------------------ | -------- | --------------------------------------- |
|
|
20
|
-
| `args` | `object` | Arguments for deriving the public key |
|
|
21
|
-
| `args.path` | `string` | The derivation path to use |
|
|
22
|
-
| `args.predecessor` | `string` | The account ID requesting the signature |
|
|
23
|
-
|
|
24
|
-
## Returns
|
|
25
|
-
|
|
26
|
-
| Type | Description |
|
|
27
|
-
| --------------------------------- | -------------------------------------------------- |
|
|
28
|
-
| `Promise<UncompressedPubKeySEC1>` | The derived public key in SEC1 uncompressed format |
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
# getPublicKey
|
|
2
|
-
|
|
3
|
-
Retrieves the root public key from the contract.
|
|
4
|
-
|
|
5
|
-
## Usage
|
|
6
|
-
|
|
7
|
-
```ts twoslash
|
|
8
|
-
// [!include ~/snippets/code/contract.ts]
|
|
9
|
-
// ---cut---
|
|
10
|
-
const publicKey = await nearChainSigContract.getPublicKey()
|
|
11
|
-
```
|
|
12
|
-
|
|
13
|
-
## Returns
|
|
14
|
-
|
|
15
|
-
| Type | Description |
|
|
16
|
-
| --------------------------------- | ----------------------------------------------- |
|
|
17
|
-
| `Promise<UncompressedPubKeySEC1>` | The root public key in SEC1 uncompressed format |
|
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
# sign
|
|
2
|
-
|
|
3
|
-
Signs data using the Chain Signatures contract.
|
|
4
|
-
|
|
5
|
-
## Usage
|
|
6
|
-
|
|
7
|
-
```ts twoslash
|
|
8
|
-
// [!include ~/snippets/code/contract.ts]
|
|
9
|
-
// ---cut---
|
|
10
|
-
const signature = await nearChainSigContract.sign({
|
|
11
|
-
path: 'my_derivation_path',
|
|
12
|
-
payload: Array.from(new Uint8Array(32).fill(1)), // 32-byte array
|
|
13
|
-
key_version: 0,
|
|
14
|
-
})
|
|
15
|
-
```
|
|
16
|
-
|
|
17
|
-
## Parameters
|
|
18
|
-
|
|
19
|
-
| Parameter | Type | Description |
|
|
20
|
-
| ------------------ | ---------- | ----------------------------------------- |
|
|
21
|
-
| `args` | `SignArgs` | Arguments for signing data |
|
|
22
|
-
| `args.path` | `string` | The derivation path to use |
|
|
23
|
-
| `args.predecessor` | `string` | The account ID requesting the signature |
|
|
24
|
-
| `args.payload` | `string` | The data to sign (32-byte hex string) |
|
|
25
|
-
| `options?` | `object` | Optional configuration for signing |
|
|
26
|
-
| `options.nonce?` | `number` | Optional nonce to use for the transaction |
|
|
27
|
-
|
|
28
|
-
## Returns
|
|
29
|
-
|
|
30
|
-
| Type | Description |
|
|
31
|
-
| ----------------------- | --------------------------- |
|
|
32
|
-
| `Promise<RSVSignature>` | The signature in RSV format |
|
|
Binary file
|
|
@@ -1,42 +0,0 @@
|
|
|
1
|
-
import { createPublicClient, createWalletClient, http } from 'viem'
|
|
2
|
-
import { privateKeyToAccount } from 'viem/accounts'
|
|
3
|
-
import { sepolia } from 'viem/chains'
|
|
4
|
-
import { chainAdapters, contracts, constants } from 'signet.js'
|
|
5
|
-
|
|
6
|
-
const account = privateKeyToAccount(process.env.PRIVATE_KEY as `0x${string}`)
|
|
7
|
-
|
|
8
|
-
const publicClient = createPublicClient({
|
|
9
|
-
chain: sepolia,
|
|
10
|
-
transport: http(),
|
|
11
|
-
})
|
|
12
|
-
|
|
13
|
-
const walletClient = createWalletClient({
|
|
14
|
-
account,
|
|
15
|
-
chain: sepolia,
|
|
16
|
-
transport: http(),
|
|
17
|
-
})
|
|
18
|
-
|
|
19
|
-
const chainSigContract = new contracts.evm.ChainSignatureContract({
|
|
20
|
-
publicClient,
|
|
21
|
-
walletClient,
|
|
22
|
-
contractAddress: constants.CONTRACT_ADDRESSES.ETHEREUM
|
|
23
|
-
.TESTNET_DEV as `0x${string}`,
|
|
24
|
-
})
|
|
25
|
-
|
|
26
|
-
const evmChain = new chainAdapters.evm.EVM({
|
|
27
|
-
rpcUrl: 'https://sepolia.infura.io/v3/YOUR-PROJECT-ID',
|
|
28
|
-
contract: chainSigContract,
|
|
29
|
-
})
|
|
30
|
-
|
|
31
|
-
const cosmosChain = new chainAdapters.cosmos.Cosmos({
|
|
32
|
-
chainId: 'cosmoshub-4',
|
|
33
|
-
contract: chainSigContract,
|
|
34
|
-
})
|
|
35
|
-
|
|
36
|
-
const btcChain = new chainAdapters.btc.Bitcoin({
|
|
37
|
-
network: 'testnet',
|
|
38
|
-
btcRpcAdapter: new chainAdapters.btc.BTCRpcAdapters.Mempool(
|
|
39
|
-
'https://mempool.space/api'
|
|
40
|
-
),
|
|
41
|
-
contract: chainSigContract,
|
|
42
|
-
})
|
|
@@ -1,44 +0,0 @@
|
|
|
1
|
-
import { contracts, constants } from 'signet.js'
|
|
2
|
-
import { createPublicClient, createWalletClient, http } from 'viem'
|
|
3
|
-
import { privateKeyToAccount } from 'viem/accounts'
|
|
4
|
-
import { sepolia } from 'viem/chains'
|
|
5
|
-
import { KeyPair, type KeyPairString } from '@near-js/crypto'
|
|
6
|
-
|
|
7
|
-
// Initialize NEAR connection with credentials from environment
|
|
8
|
-
const accountId = process.env.NEAR_ACCOUNT_ID
|
|
9
|
-
const privateKey = process.env.NEAR_PRIVATE_KEY as KeyPairString
|
|
10
|
-
|
|
11
|
-
if (!accountId || !privateKey) {
|
|
12
|
-
throw new Error(
|
|
13
|
-
'NEAR_ACCOUNT_ID and NEAR_PRIVATE_KEY must be set in environment'
|
|
14
|
-
)
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
const keypair = KeyPair.fromString(privateKey)
|
|
18
|
-
|
|
19
|
-
const account = privateKeyToAccount(process.env.PRIVATE_KEY as `0x${string}`)
|
|
20
|
-
|
|
21
|
-
const publicClient = createPublicClient({
|
|
22
|
-
chain: sepolia,
|
|
23
|
-
transport: http(),
|
|
24
|
-
})
|
|
25
|
-
|
|
26
|
-
const walletClient = createWalletClient({
|
|
27
|
-
account,
|
|
28
|
-
chain: sepolia,
|
|
29
|
-
transport: http(),
|
|
30
|
-
})
|
|
31
|
-
|
|
32
|
-
const evmChainSigContract = new contracts.evm.ChainSignatureContract({
|
|
33
|
-
publicClient,
|
|
34
|
-
walletClient,
|
|
35
|
-
contractAddress: constants.CONTRACT_ADDRESSES.ETHEREUM
|
|
36
|
-
.TESTNET_DEV as `0x${string}`,
|
|
37
|
-
})
|
|
38
|
-
|
|
39
|
-
const nearChainSigContract = new contracts.near.ChainSignatureContract({
|
|
40
|
-
networkId: 'testnet',
|
|
41
|
-
contractId: constants.CONTRACT_ADDRESSES.NEAR.TESTNET,
|
|
42
|
-
accountId,
|
|
43
|
-
keypair,
|
|
44
|
-
})
|
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
import { contracts, constants } from 'signet.js'
|
|
2
|
-
import { createPublicClient, createWalletClient, http } from 'viem'
|
|
3
|
-
import { privateKeyToAccount } from 'viem/accounts'
|
|
4
|
-
import { sepolia } from 'viem/chains'
|
|
5
|
-
|
|
6
|
-
const account = privateKeyToAccount(process.env.PRIVATE_KEY as `0x${string}`)
|
|
7
|
-
|
|
8
|
-
const publicClient = createPublicClient({
|
|
9
|
-
chain: sepolia,
|
|
10
|
-
transport: http(),
|
|
11
|
-
})
|
|
12
|
-
|
|
13
|
-
const walletClient = createWalletClient({
|
|
14
|
-
account,
|
|
15
|
-
chain: sepolia,
|
|
16
|
-
transport: http(),
|
|
17
|
-
})
|
|
18
|
-
|
|
19
|
-
const evmChainSigContract = new contracts.evm.ChainSignatureContract({
|
|
20
|
-
publicClient,
|
|
21
|
-
walletClient,
|
|
22
|
-
contractAddress: constants.CONTRACT_ADDRESSES.ETHEREUM
|
|
23
|
-
.TESTNET_DEV as `0x${string}`,
|
|
24
|
-
})
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
import { createPublicClient, createWalletClient, http } from 'viem'
|
|
2
|
-
import { privateKeyToAccount } from 'viem/accounts'
|
|
3
|
-
import { sepolia } from 'viem/chains'
|
|
4
|
-
|
|
5
|
-
const account = privateKeyToAccount(process.env.PRIVATE_KEY as `0x${string}`)
|
|
6
|
-
|
|
7
|
-
const publicClient = createPublicClient({
|
|
8
|
-
chain: sepolia,
|
|
9
|
-
transport: http(),
|
|
10
|
-
})
|
|
11
|
-
|
|
12
|
-
const walletClient = createWalletClient({
|
|
13
|
-
account,
|
|
14
|
-
chain: sepolia,
|
|
15
|
-
transport: http(),
|
|
16
|
-
})
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
import { KeyPair, type KeyPairString } from '@near-js/crypto'
|
|
2
|
-
|
|
3
|
-
// Initialize NEAR connection with credentials from environment
|
|
4
|
-
const accountId = process.env.NEAR_ACCOUNT_ID
|
|
5
|
-
const privateKey = process.env.NEAR_PRIVATE_KEY as KeyPairString
|
|
6
|
-
|
|
7
|
-
if (!accountId || !privateKey) {
|
|
8
|
-
throw new Error(
|
|
9
|
-
'NEAR_ACCOUNT_ID and NEAR_PRIVATE_KEY must be set in environment'
|
|
10
|
-
)
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
const keypair = KeyPair.fromString(privateKey)
|
package/hardhat.config.mts
DELETED
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
import '@nomicfoundation/hardhat-toolbox'
|
|
2
|
-
|
|
3
|
-
const config = {
|
|
4
|
-
solidity: '0.8.24',
|
|
5
|
-
networks: {
|
|
6
|
-
hardhat: {
|
|
7
|
-
mining: {
|
|
8
|
-
auto: true,
|
|
9
|
-
interval: 1000,
|
|
10
|
-
},
|
|
11
|
-
},
|
|
12
|
-
localhost: {
|
|
13
|
-
url: 'http://127.0.0.1:8545',
|
|
14
|
-
chainId: 31337,
|
|
15
|
-
},
|
|
16
|
-
},
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
export default config
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
BTCTransaction,
|
|
3
|
-
BTCInput,
|
|
4
|
-
BTCOutput,
|
|
5
|
-
} from '@chain-adapters/Bitcoin/types'
|
|
6
|
-
|
|
7
|
-
export abstract class BTCRpcAdapter {
|
|
8
|
-
abstract selectUTXOs(
|
|
9
|
-
from: string,
|
|
10
|
-
targets: BTCOutput[]
|
|
11
|
-
): Promise<{ inputs: BTCInput[]; outputs: BTCOutput[] }>
|
|
12
|
-
abstract broadcastTransaction(transactionHex: string): Promise<string>
|
|
13
|
-
abstract getBalance(address: string): Promise<number>
|
|
14
|
-
abstract getTransaction(txid: string): Promise<BTCTransaction>
|
|
15
|
-
}
|
|
@@ -1,101 +0,0 @@
|
|
|
1
|
-
// There is no types for coinselect
|
|
2
|
-
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
3
|
-
// @ts-expect-error
|
|
4
|
-
|
|
5
|
-
import coinselect from 'coinselect'
|
|
6
|
-
|
|
7
|
-
import { BTCRpcAdapter } from '@chain-adapters/Bitcoin/BTCRpcAdapter/BTCRpcAdapter'
|
|
8
|
-
import {
|
|
9
|
-
type BTCFeeRecommendation,
|
|
10
|
-
type UTXO,
|
|
11
|
-
} from '@chain-adapters/Bitcoin/BTCRpcAdapter/Mempool/types'
|
|
12
|
-
import type {
|
|
13
|
-
BTCTransaction,
|
|
14
|
-
BTCInput,
|
|
15
|
-
BTCOutput,
|
|
16
|
-
} from '@chain-adapters/Bitcoin/types'
|
|
17
|
-
|
|
18
|
-
export class Mempool extends BTCRpcAdapter {
|
|
19
|
-
private readonly providerUrl: string
|
|
20
|
-
|
|
21
|
-
constructor(providerUrl: string) {
|
|
22
|
-
super()
|
|
23
|
-
this.providerUrl = providerUrl
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
private async fetchFeeRate(confirmationTarget = 6): Promise<number> {
|
|
27
|
-
const response = await fetch(`${this.providerUrl}/v1/fees/recommended`)
|
|
28
|
-
const data = (await response.json()) as BTCFeeRecommendation
|
|
29
|
-
|
|
30
|
-
if (confirmationTarget <= 1) {
|
|
31
|
-
return data.fastestFee
|
|
32
|
-
} else if (confirmationTarget <= 3) {
|
|
33
|
-
return data.halfHourFee
|
|
34
|
-
} else if (confirmationTarget <= 6) {
|
|
35
|
-
return data.hourFee
|
|
36
|
-
} else {
|
|
37
|
-
return data.economyFee
|
|
38
|
-
}
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
private async fetchUTXOs(address: string): Promise<UTXO[]> {
|
|
42
|
-
try {
|
|
43
|
-
const response = await fetch(
|
|
44
|
-
`${this.providerUrl}/address/${address}/utxo`
|
|
45
|
-
)
|
|
46
|
-
return (await response.json()) as UTXO[]
|
|
47
|
-
} catch (error) {
|
|
48
|
-
console.error('Failed to fetch UTXOs:', error)
|
|
49
|
-
return []
|
|
50
|
-
}
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
async selectUTXOs(
|
|
54
|
-
from: string,
|
|
55
|
-
targets: BTCOutput[],
|
|
56
|
-
confirmationTarget = 6
|
|
57
|
-
): Promise<{ inputs: BTCInput[]; outputs: BTCOutput[] }> {
|
|
58
|
-
const utxos = await this.fetchUTXOs(from)
|
|
59
|
-
const feeRate = await this.fetchFeeRate(confirmationTarget)
|
|
60
|
-
|
|
61
|
-
// Add a small amount to the fee rate to ensure the transaction is confirmed
|
|
62
|
-
const ret = coinselect(utxos, targets, Math.ceil(feeRate + 1))
|
|
63
|
-
|
|
64
|
-
if (!ret.inputs || !ret.outputs) {
|
|
65
|
-
throw new Error(
|
|
66
|
-
'Invalid transaction: coinselect failed to find a suitable set of inputs and outputs. This could be due to insufficient funds, or no inputs being available that meet the criteria.'
|
|
67
|
-
)
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
return {
|
|
71
|
-
inputs: ret.inputs,
|
|
72
|
-
outputs: ret.outputs,
|
|
73
|
-
}
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
async broadcastTransaction(transactionHex: string): Promise<string> {
|
|
77
|
-
const response = await fetch(`${this.providerUrl}/tx`, {
|
|
78
|
-
method: 'POST',
|
|
79
|
-
body: transactionHex,
|
|
80
|
-
})
|
|
81
|
-
|
|
82
|
-
if (response.ok) {
|
|
83
|
-
return await response.text()
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
throw new Error(`Failed to broadcast transaction: ${await response.text()}`)
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
async getBalance(address: string): Promise<number> {
|
|
90
|
-
const response = await fetch(`${this.providerUrl}/address/${address}`)
|
|
91
|
-
const data = (await response.json()) as {
|
|
92
|
-
chain_stats: { funded_txo_sum: number; spent_txo_sum: number }
|
|
93
|
-
}
|
|
94
|
-
return data.chain_stats.funded_txo_sum - data.chain_stats.spent_txo_sum
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
async getTransaction(txid: string): Promise<BTCTransaction> {
|
|
98
|
-
const response = await fetch(`${this.providerUrl}/tx/${txid}`)
|
|
99
|
-
return (await response.json()) as BTCTransaction
|
|
100
|
-
}
|
|
101
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export { Mempool } from './Mempool'
|
|
@@ -1,72 +0,0 @@
|
|
|
1
|
-
export interface BTCFeeRecommendation {
|
|
2
|
-
fastestFee: number
|
|
3
|
-
halfHourFee: number
|
|
4
|
-
hourFee: number
|
|
5
|
-
economyFee: number
|
|
6
|
-
minimumFee: number
|
|
7
|
-
}
|
|
8
|
-
|
|
9
|
-
interface BTCAddressStats {
|
|
10
|
-
funded_txo_count: number
|
|
11
|
-
funded_txo_sum: number
|
|
12
|
-
spent_txo_count: number
|
|
13
|
-
spent_txo_sum: number
|
|
14
|
-
tx_count: number
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
export interface BTCAddressInfo {
|
|
18
|
-
address: string
|
|
19
|
-
chain_stats: BTCAddressStats
|
|
20
|
-
mempool_stats: BTCAddressStats
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
export interface Transaction {
|
|
24
|
-
txid: string
|
|
25
|
-
version: number
|
|
26
|
-
locktime: number
|
|
27
|
-
vin: Array<{
|
|
28
|
-
txid: string
|
|
29
|
-
vout: number
|
|
30
|
-
prevout: {
|
|
31
|
-
scriptpubkey: string
|
|
32
|
-
scriptpubkey_asm: string
|
|
33
|
-
scriptpubkey_type: string
|
|
34
|
-
scriptpubkey_address: string
|
|
35
|
-
value: number
|
|
36
|
-
}
|
|
37
|
-
scriptsig: string
|
|
38
|
-
scriptsig_asm: string
|
|
39
|
-
witness: string[]
|
|
40
|
-
is_coinbase: boolean
|
|
41
|
-
sequence: number
|
|
42
|
-
}>
|
|
43
|
-
vout: Array<{
|
|
44
|
-
scriptpubkey: string
|
|
45
|
-
scriptpubkey_asm: string
|
|
46
|
-
scriptpubkey_type: string
|
|
47
|
-
scriptpubkey_address: string
|
|
48
|
-
value: number
|
|
49
|
-
}>
|
|
50
|
-
size: number
|
|
51
|
-
weight: number
|
|
52
|
-
sigops?: number
|
|
53
|
-
fee: number
|
|
54
|
-
status: {
|
|
55
|
-
confirmed: boolean
|
|
56
|
-
block_height: number
|
|
57
|
-
block_hash: string
|
|
58
|
-
block_time: number
|
|
59
|
-
}
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
export interface UTXO {
|
|
63
|
-
txid: string
|
|
64
|
-
vout: number
|
|
65
|
-
status: {
|
|
66
|
-
confirmed: boolean
|
|
67
|
-
block_height: number
|
|
68
|
-
block_hash: string
|
|
69
|
-
block_time: number
|
|
70
|
-
}
|
|
71
|
-
value: number
|
|
72
|
-
}
|