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.
Files changed (183) hide show
  1. package/README.md +8 -1
  2. package/browser/index.browser.cjs +3 -0
  3. package/browser/index.browser.cjs.map +1 -0
  4. package/browser/index.browser.js +3 -0
  5. package/browser/index.browser.js.map +1 -0
  6. package/node/index.node.cjs +3 -0
  7. package/node/index.node.cjs.map +1 -0
  8. package/node/index.node.js +3 -0
  9. package/node/index.node.js.map +1 -0
  10. package/package.json +19 -18
  11. package/types/index.d.cts +1048 -0
  12. package/types/index.d.ts +1048 -0
  13. package/.eslintrc.json +0 -67
  14. package/.prettierrc +0 -1
  15. package/babel.config.js +0 -6
  16. package/docs/dist/.vocs/icons/arrow-diagonal.svg +0 -3
  17. package/docs/dist/.vocs/icons/chevron-down.svg +0 -13
  18. package/docs/dist/.vocs/icons/chevron-up.svg +0 -13
  19. package/docs/dist/.vocs/icons/link.svg +0 -3
  20. package/docs/dist/.vocs/search-index-7b499e25.json +0 -1
  21. package/docs/dist/assets/arbitrary-hash-Cd6eo8ZD.js +0 -309
  22. package/docs/dist/assets/broadcast-tx-CeTEE9yX.js +0 -8
  23. package/docs/dist/assets/btc-rpc-adapter-C-qSHpFV.js +0 -226
  24. package/docs/dist/assets/chain-adapter-interface-B9TpOgQv.js +0 -1280
  25. package/docs/dist/assets/chain-contract-interface-DEku3k45.js +0 -392
  26. package/docs/dist/assets/constructor-73n7bp3b.js +0 -161
  27. package/docs/dist/assets/constructor-Bg7nvLe0.js +0 -14
  28. package/docs/dist/assets/contract-addresses-BYlrAOs3.js +0 -200
  29. package/docs/dist/assets/derive-address-and-public-key-DExrKiGV.js +0 -14
  30. package/docs/dist/assets/finalize-message-signing-W435d71R.js +0 -20
  31. package/docs/dist/assets/finalize-transaction-signing-BIgJ2dnc.js +0 -36
  32. package/docs/dist/assets/finalize-transaction-signing-C--HJs8D.js +0 -24
  33. package/docs/dist/assets/finalize-transaction-signing-CjGmN7d9.js +0 -24
  34. package/docs/dist/assets/finalize-typed-data-signing-CEOp_GWt.js +0 -21
  35. package/docs/dist/assets/get-balance-DBC-i6KG.js +0 -13
  36. package/docs/dist/assets/get-current-signature-deposit-BXm9AzYy.js +0 -6
  37. package/docs/dist/assets/get-current-signature-deposit-nOw4j1MN.js +0 -6
  38. package/docs/dist/assets/get-derived-public-key-BXvfo2m2.js +0 -14
  39. package/docs/dist/assets/get-derived-public-key-DQ1pyiFS.js +0 -14
  40. package/docs/dist/assets/get-latest-key-version-DWlkMCre.js +0 -6
  41. package/docs/dist/assets/get-public-key-B4PFoVqu.js +0 -6
  42. package/docs/dist/assets/get-public-key-B9xkYkD_.js +0 -6
  43. package/docs/dist/assets/index-BFuwoY4w.js +0 -601
  44. package/docs/dist/assets/index-C62Mf-vy.js +0 -426
  45. package/docs/dist/assets/index-D8xhaiVb.js +0 -121
  46. package/docs/dist/assets/index-DTr0DlO0.js +0 -36
  47. package/docs/dist/assets/index-V9dXf-ik.js +0 -457
  48. package/docs/dist/assets/prepare-message-for-signing-DESTq-Hg.js +0 -16
  49. package/docs/dist/assets/prepare-transaction-for-signing-DIKTU0zj.js +0 -33
  50. package/docs/dist/assets/prepare-transaction-for-signing-DV_wkZ5g.js +0 -21
  51. package/docs/dist/assets/prepare-transaction-for-signing-LVDP0COu.js +0 -33
  52. package/docs/dist/assets/prepare-typed-data-for-signing-CWcmJvw0.js +0 -192
  53. package/docs/dist/assets/sign-CwtS5LnB.js +0 -13
  54. package/docs/dist/assets/sign-OQxf9yn7.js +0 -15
  55. package/docs/dist/assets/signet-quick-start-CQK52nVG.js +0 -350
  56. package/docs/dist/assets/sponsor-foreign-chain-gas-C9iWXM8Q.js +0 -1
  57. package/docs/dist/assets/style-CKGXuRqx.css +0 -1
  58. package/docs/dist/examples/arbitrary-hash/index.html +0 -88
  59. package/docs/dist/examples/sponsor-foreign-chain-gas/index.html +0 -21
  60. package/docs/dist/index.html +0 -56
  61. package/docs/dist/initializeTheme.iife.js +0 -1
  62. package/docs/dist/introduction/signet-quick-start/index.html +0 -109
  63. package/docs/dist/primitives/chain-adapter-interface/index.html +0 -515
  64. package/docs/dist/primitives/chain-contract-interface/index.html +0 -306
  65. package/docs/dist/primitives/contract-addresses/index.html +0 -97
  66. package/docs/dist/signet-logo.png +0 -0
  67. package/docs/dist/signetjs/chain-adapters/bitcoin/btc-rpc-adapter/index.html +0 -148
  68. package/docs/dist/signetjs/chain-adapters/bitcoin/finalize-transaction-signing/index.html +0 -41
  69. package/docs/dist/signetjs/chain-adapters/bitcoin/index.html +0 -187
  70. package/docs/dist/signetjs/chain-adapters/bitcoin/prepare-transaction-for-signing/index.html +0 -34
  71. package/docs/dist/signetjs/chain-adapters/broadcast-tx/index.html +0 -28
  72. package/docs/dist/signetjs/chain-adapters/cosmos/finalize-transaction-signing/index.html +0 -41
  73. package/docs/dist/signetjs/chain-adapters/cosmos/index.html +0 -166
  74. package/docs/dist/signetjs/chain-adapters/cosmos/prepare-transaction-for-signing/index.html +0 -43
  75. package/docs/dist/signetjs/chain-adapters/derive-address-and-public-key/index.html +0 -31
  76. package/docs/dist/signetjs/chain-adapters/evm/finalize-message-signing/index.html +0 -38
  77. package/docs/dist/signetjs/chain-adapters/evm/finalize-transaction-signing/index.html +0 -41
  78. package/docs/dist/signetjs/chain-adapters/evm/finalize-typed-data-signing/index.html +0 -39
  79. package/docs/dist/signetjs/chain-adapters/evm/index.html +0 -129
  80. package/docs/dist/signetjs/chain-adapters/evm/prepare-message-for-signing/index.html +0 -31
  81. package/docs/dist/signetjs/chain-adapters/evm/prepare-transaction-for-signing/index.html +0 -34
  82. package/docs/dist/signetjs/chain-adapters/evm/prepare-typed-data-for-signing/index.html +0 -49
  83. package/docs/dist/signetjs/chain-adapters/get-balance/index.html +0 -30
  84. package/docs/dist/signetjs/contracts/evm/constructor/index.html +0 -45
  85. package/docs/dist/signetjs/contracts/evm/get-current-signature-deposit/index.html +0 -26
  86. package/docs/dist/signetjs/contracts/evm/get-derived-public-key/index.html +0 -31
  87. package/docs/dist/signetjs/contracts/evm/get-latest-key-version/index.html +0 -26
  88. package/docs/dist/signetjs/contracts/evm/get-public-key/index.html +0 -26
  89. package/docs/dist/signetjs/contracts/evm/sign/index.html +0 -32
  90. package/docs/dist/signetjs/contracts/near/constructor/index.html +0 -34
  91. package/docs/dist/signetjs/contracts/near/get-current-signature-deposit/index.html +0 -26
  92. package/docs/dist/signetjs/contracts/near/get-derived-public-key/index.html +0 -31
  93. package/docs/dist/signetjs/contracts/near/get-public-key/index.html +0 -26
  94. package/docs/dist/signetjs/contracts/near/sign/index.html +0 -32
  95. package/docs/pages/examples/arbitrary-hash.mdx +0 -73
  96. package/docs/pages/examples/sponsor-foreign-chain-gas.mdx +0 -1
  97. package/docs/pages/index.mdx +0 -36
  98. package/docs/pages/introduction/signet-quick-start.mdx +0 -88
  99. package/docs/pages/primitives/chain-adapter-interface.mdx +0 -45
  100. package/docs/pages/primitives/chain-contract-interface.mdx +0 -52
  101. package/docs/pages/primitives/contract-addresses.mdx +0 -27
  102. package/docs/pages/signetjs/chain-adapters/bitcoin/btc-rpc-adapter.mdx +0 -26
  103. package/docs/pages/signetjs/chain-adapters/bitcoin/finalize-transaction-signing.mdx +0 -47
  104. package/docs/pages/signetjs/chain-adapters/bitcoin/index.mdx +0 -119
  105. package/docs/pages/signetjs/chain-adapters/bitcoin/prepare-transaction-for-signing.mdx +0 -30
  106. package/docs/pages/signetjs/chain-adapters/broadcast-tx.mdx +0 -23
  107. package/docs/pages/signetjs/chain-adapters/cosmos/finalize-transaction-signing.mdx +0 -53
  108. package/docs/pages/signetjs/chain-adapters/cosmos/index.mdx +0 -108
  109. package/docs/pages/signetjs/chain-adapters/cosmos/prepare-transaction-for-signing.mdx +0 -39
  110. package/docs/pages/signetjs/chain-adapters/derive-address-and-public-key.mdx +0 -28
  111. package/docs/pages/signetjs/chain-adapters/evm/finalize-message-signing.mdx +0 -33
  112. package/docs/pages/signetjs/chain-adapters/evm/finalize-transaction-signing.mdx +0 -44
  113. package/docs/pages/signetjs/chain-adapters/evm/finalize-typed-data-signing.mdx +0 -34
  114. package/docs/pages/signetjs/chain-adapters/evm/index.mdx +0 -84
  115. package/docs/pages/signetjs/chain-adapters/evm/prepare-message-for-signing.mdx +0 -26
  116. package/docs/pages/signetjs/chain-adapters/evm/prepare-transaction-for-signing.mdx +0 -30
  117. package/docs/pages/signetjs/chain-adapters/evm/prepare-typed-data-for-signing.mdx +0 -44
  118. package/docs/pages/signetjs/chain-adapters/get-balance.mdx +0 -26
  119. package/docs/pages/signetjs/contracts/evm/constructor.mdx +0 -38
  120. package/docs/pages/signetjs/contracts/evm/get-current-signature-deposit.mdx +0 -17
  121. package/docs/pages/signetjs/contracts/evm/get-derived-public-key.mdx +0 -28
  122. package/docs/pages/signetjs/contracts/evm/get-latest-key-version.mdx +0 -17
  123. package/docs/pages/signetjs/contracts/evm/get-public-key.mdx +0 -17
  124. package/docs/pages/signetjs/contracts/evm/sign.mdx +0 -36
  125. package/docs/pages/signetjs/contracts/near/constructor.mdx +0 -29
  126. package/docs/pages/signetjs/contracts/near/get-current-signature-deposit.mdx +0 -17
  127. package/docs/pages/signetjs/contracts/near/get-derived-public-key.mdx +0 -28
  128. package/docs/pages/signetjs/contracts/near/get-public-key.mdx +0 -17
  129. package/docs/pages/signetjs/contracts/near/sign.mdx +0 -32
  130. package/docs/public/signet-logo.png +0 -0
  131. package/docs/snippets/code/chains.ts +0 -42
  132. package/docs/snippets/code/contract.ts +0 -44
  133. package/docs/snippets/code/evm/contract.ts +0 -24
  134. package/docs/snippets/code/evm/env.ts +0 -16
  135. package/docs/snippets/code/near/env.ts +0 -13
  136. package/hardhat.config.mts +0 -19
  137. package/src/chain-adapters/Bitcoin/BTCRpcAdapter/BTCRpcAdapter.ts +0 -15
  138. package/src/chain-adapters/Bitcoin/BTCRpcAdapter/Mempool/Mempool.ts +0 -101
  139. package/src/chain-adapters/Bitcoin/BTCRpcAdapter/Mempool/index.ts +0 -1
  140. package/src/chain-adapters/Bitcoin/BTCRpcAdapter/Mempool/types.ts +0 -72
  141. package/src/chain-adapters/Bitcoin/BTCRpcAdapter/index.ts +0 -6
  142. package/src/chain-adapters/Bitcoin/Bitcoin.ts +0 -287
  143. package/src/chain-adapters/Bitcoin/index.ts +0 -13
  144. package/src/chain-adapters/Bitcoin/types.ts +0 -48
  145. package/src/chain-adapters/Bitcoin/utils.ts +0 -14
  146. package/src/chain-adapters/ChainAdapter.ts +0 -92
  147. package/src/chain-adapters/Cosmos/Cosmos.ts +0 -258
  148. package/src/chain-adapters/Cosmos/index.ts +0 -8
  149. package/src/chain-adapters/Cosmos/types.ts +0 -35
  150. package/src/chain-adapters/Cosmos/utils.ts +0 -45
  151. package/src/chain-adapters/EVM/EVM.test.ts +0 -238
  152. package/src/chain-adapters/EVM/EVM.ts +0 -337
  153. package/src/chain-adapters/EVM/index.ts +0 -11
  154. package/src/chain-adapters/EVM/types.ts +0 -53
  155. package/src/chain-adapters/EVM/utils.ts +0 -27
  156. package/src/chain-adapters/index.ts +0 -5
  157. package/src/constants.ts +0 -62
  158. package/src/contracts/ChainSignatureContract.ts +0 -65
  159. package/src/contracts/evm/ChainSignaturesContract.ts +0 -323
  160. package/src/contracts/evm/ChainSignaturesContractABI.ts +0 -359
  161. package/src/contracts/evm/errors.ts +0 -52
  162. package/src/contracts/evm/index.ts +0 -10
  163. package/src/contracts/evm/types.ts +0 -39
  164. package/src/contracts/evm/utils.ts +0 -41
  165. package/src/contracts/index.ts +0 -4
  166. package/src/contracts/near/ChainSignatureContract.ts +0 -196
  167. package/src/contracts/near/account.ts +0 -42
  168. package/src/contracts/near/constants.ts +0 -4
  169. package/src/contracts/near/index.ts +0 -10
  170. package/src/contracts/near/signAndSend/index.ts +0 -1
  171. package/src/contracts/near/signAndSend/keypair.ts +0 -178
  172. package/src/contracts/near/transaction.ts +0 -202
  173. package/src/contracts/near/types.ts +0 -71
  174. package/src/index.ts +0 -5
  175. package/src/types.ts +0 -46
  176. package/src/utils/cryptography.ts +0 -141
  177. package/src/utils/index.ts +0 -1
  178. package/src/utils/publicKey.ts +0 -17
  179. package/tsconfig.eslint.json +0 -8
  180. package/tsconfig.json +0 -126
  181. package/tsup.config.ts +0 -58
  182. package/vitest.config.ts +0 -19
  183. package/vocs.config.ts +0 -213
@@ -1,73 +0,0 @@
1
- ## Signing an Arbitrary Hash
2
-
3
- Below is a **working example** of how to **request** and **retrieve** a signature for an arbitrary 32-byte hash from the **ChainSignatures** contract **deployed on Sepolia**.
4
-
5
- > **Assumption**:
6
- >
7
- > - The ChainSignatures contract is deployed at `0x69C6b28Fdc74618817fa380De29a653060e14009` (example).
8
- > - You have a web3 provider (e.g., viem) pointing to Sepolia.
9
-
10
- ### Prepare Your Ethers Contract Instance
11
-
12
- ```ts twoslash filename="init-contract.ts"
13
- import { contracts, constants } from 'signet.js'
14
- // [!include ~/snippets/code/evm/env.ts]
15
-
16
- const evmChainSigContract = new contracts.evm.ChainSignatureContract({
17
- publicClient,
18
- walletClient,
19
- contractAddress: constants.CONTRACT_ADDRESSES.ETHEREUM
20
- .TESTNET_DEV as `0x${string}`,
21
- })
22
- ```
23
-
24
- ### Request a Signature on an Arbitrary Hash
25
-
26
- ```ts twoslash filename="request-signature.ts"
27
- // [!include init-contract.ts]
28
- // ---cut---
29
-
30
- // Suppose you have a 32-byte hash you'd like to have signed:
31
- const hashToSign = Array.from(new Uint8Array(32).fill(1)) // Must be exactly 32 bytes
32
-
33
- // Derive the path you want (could be any string)
34
- const path = 'myArbitraryPath'
35
-
36
- // Key version (check chainSignatures.latestKeyVersion() if needed)
37
- const keyVersion = 0
38
-
39
- const signature = await evmChainSigContract.sign({
40
- path,
41
- key_version: keyVersion,
42
- payload: hashToSign,
43
- })
44
- ```
45
-
46
- - At this point, the mpc network sees the `SignatureRequested` event, does the off-chain ECDSA signing, and calls `respond(...)`.
47
-
48
- ### Retrieve the Signature Once Responded
49
-
50
- The MPC network will call:
51
-
52
- ```solidity
53
- chainSignatures.respond(
54
- requestId,
55
- SignatureResponse({
56
- bigR: AffinePoint({ x: rPointX, y: rPointY }),
57
- s: sValue,
58
- recoveryId: vValue
59
- })
60
- );
61
- ```
62
-
63
- After that transaction is confirmed, a `SignatureResponded` event is emitted. The `sign` methods will handle the event polling internally and return the signature components to you:
64
-
65
- ```ts twoslash filename="retrieve-signature.ts"
66
- // [!include request-signature.ts]
67
- // ---cut---
68
- console.log('r:', signature.r)
69
- console.log('s:', signature.s)
70
- console.log('v:', signature.v)
71
- ```
72
-
73
- You now have the ECDSA components (`r`, `s`, `v`) to do whatever you need with them. The deposit is refunded automatically to `msg.sender` of the original `sign` call if there's any excess.
@@ -1 +0,0 @@
1
- ## TODO
@@ -1,36 +0,0 @@
1
- ## Introduction
2
-
3
- Managing multiple accounts across different blockchains is a headache. Every chain has its own wallets, private keys, and authentication systems, making cross-chain interactions complex and fragmented. But what if a single abstract account could seamlessly control multiple accounts across different chains—without compromising security? That's now possible through Chain Signatures.
4
-
5
- ### What Are Chain Signatures?
6
-
7
- Chain Signatures are programmable digital signatures that enable cross-chain control, allowing one account on one blockchain to securely manage accounts and assets on entirely different chains.
8
- The system:
9
-
10
- - **Derives keys** from a single base key.
11
- - Allows third parties (e.g., dApps, wallets, or protocols) to **request signatures** on-chain.
12
- - Introduces **flexible usage controls**, such as daily spending limits or rate limits, by combining these keys with custom on-chain logic.
13
-
14
- ### Benefits & Use Cases:
15
-
16
- - **One Identity, Many Chains**: Instead of juggling multiple wallets, a single signature from your Ethereum account could authorize actions on any other supported EVM or non-EVM chain, without needing to manage separate private keys.
17
- - **Seamless Cross-Chain Transactions**: Move assets or execute smart contract functions across different chains, without relying on third-party bridges or centralized custodians.
18
- - **Usage Controls**: rate or time-based restrictions can be enforced by the on-chain contract that manages key usage (e.g., "this key can only send up to 1 ETH per day").
19
- - **Recovery or Fallback Conditions**: Instead of storing private keys in a single hardware device, you can use a multi-party computation (MPC) setup that offers user-friendly ways to recover accounts.
20
- - **Signs the Arbitrary State of a Foreign Chain**: Gives your smart contract awareness of whether a transaction it signed went through so that it can perform actions accordingly. For example, it allows for a smart contract to keep track of local chain assets based on the foreign chain's state.
21
-
22
- ## How It Works?
23
-
24
- ### Contract Background
25
-
26
- The **ChainSignatures** contract:
27
-
28
- - Holds a base public key (`publicKey`), expressed in affine coordinates on the secp256k1 curve.
29
- - Derives new public keys for each `(user, path)` combination by computing an integer `epsilon` (based on a `path` string and user’s address) and performing an EC point addition:
30
-
31
- ```
32
- DerivedPubKey = BasePubKey + (epsilon × G)
33
- ```
34
-
35
- - Allows a user to request a signature on a 32-byte payload by calling `sign(...)`. A minimal deposit may be required to discourage spam; any unused deposit is refunded once the request is completed.
36
- - Awaits the **MPC network** to compute the actual ECDSA signature offline, then call `respond(...)` with that signature. The contract then emits an event with the signature, and refunds the deposit.
@@ -1,88 +0,0 @@
1
- # Quick Start
2
-
3
- ## Installation
4
-
5
- ```bash
6
- npm install signet.js
7
- # or
8
- yarn add signet.js
9
- # or
10
- pnpm add signet.js
11
- ```
12
-
13
- ## Signing a Transaction
14
-
15
- Here's a basic example using the EVM implementation:
16
-
17
- ```ts twoslash
18
- import { contracts, constants, chainAdapters } from 'signet.js'
19
- // [!include ~/snippets/code/evm/env.ts]
20
-
21
- const evmChainSigContract = new contracts.evm.ChainSignatureContract({
22
- publicClient,
23
- walletClient,
24
- contractAddress: constants.CONTRACT_ADDRESSES.ETHEREUM
25
- .TESTNET_DEV as `0x${string}`,
26
- })
27
-
28
- const evm = new chainAdapters.evm.EVM({
29
- rpcUrl: 'https://sepolia.infura.io/v3/YOUR-PROJECT-ID',
30
- contract: evmChainSigContract,
31
- })
32
-
33
- const path = 'eth'
34
- const predecessorId = walletClient.account.address
35
-
36
- const { address: from, publicKey } = await evm.deriveAddressAndPublicKey(
37
- predecessorId,
38
- path
39
- )
40
-
41
- const { balance, decimals } = await evm.getBalance(from)
42
-
43
- const { transaction, hashesToSign } = await evm.prepareTransactionForSigning({
44
- from: from as `0x${string}`,
45
- to: '0x4174678c78fEaFd778c1ff319D5D326701449b25',
46
- value: 1n, // Amount in wei (1 wei in this example)
47
- })
48
-
49
- const rsvSignature = await evmChainSigContract?.sign({
50
- payload: hashesToSign[0],
51
- path,
52
- key_version: 0, // The version of the key to use (usually 0)
53
- })
54
-
55
- const tx = evm.finalizeTransactionSigning({
56
- transaction,
57
- rsvSignatures: [rsvSignature],
58
- })
59
-
60
- const txHash = await evm.broadcastTx(tx)
61
- ```
62
-
63
- ## Supported Chains
64
-
65
- - [EVM Chains](/signetjs/chain-adapters/evm) - Ethereum and compatible networks
66
- - [Bitcoin](/signetjs/chain-adapters/bitcoin) - Bitcoin network
67
- - [Cosmos Chains](/signetjs/chain-adapters/cosmos) - Cosmos SDK-based networks
68
-
69
- ## Architecture
70
-
71
- The library is built around a core `ChainAdapter` interface that defines common functionality across all supported blockchain networks. Each specific chain implementation extends this interface with network-specific features while maintaining a consistent API.
72
-
73
- For more details check the [ChainAdapter](/primitives/chain-adapter-interface.mdx) page.
74
-
75
- ## Utility Functions
76
-
77
- Besides the ChainAdapter classes the library also provide utility functions to assist you on building transactions, requesting signature in wrapped methods.
78
-
79
- Currently we support:
80
-
81
- - Near
82
- - EVM
83
-
84
- ## Repositories
85
-
86
- - Signet.js: [https://github.com/sig-net/signet.js](https://github.com/sig-net/signet.js).
87
- - Examples: [https://github.com/sig-net/signet-examples](https://github.com/sig-net/signet-examples).
88
- - MPC: [https://github.com/sig-net/mpc](https://github.com/sig-net/mpc).
@@ -1,45 +0,0 @@
1
- # ChainAdapter
2
-
3
- ChainAdapter is the most basic interface of the signet.js library. It provides a standard set of methods that all chains must implement.
4
-
5
- With this interface you will be able to interact with Sig Network smart contracts in a standard way to:
6
-
7
- - getBalance
8
- - deriveAddressAndPublicKey
9
- - serializeTransaction
10
- - deserializeTransaction
11
- - prepareTransactionForSigning
12
- - finalizeTransactionSigning
13
- - broadcastTx
14
-
15
- If you wanna have a look this is the chain interface with a brief description of each method:
16
-
17
- ```ts twoslash
18
- // [!include ~/../src/chain-adapters/ChainAdapter.ts]
19
- ```
20
-
21
- # Implementing a New ChainAdapter
22
-
23
- This guide explains how to implement support for a new blockchain network in the signet.js library.
24
-
25
- ## Overview
26
-
27
- To add support for a new blockchain, you need to implement the `ChainAdapter` interface:
28
-
29
- ## Step-by-Step Guide
30
-
31
- ### 1. Create the ChainAdapter Types
32
-
33
- First, define the transaction types for your chain:
34
-
35
- ```ts twoslash
36
- // [!include ~/../src/types.ts]
37
- ```
38
-
39
- ### 2. Implement the ChainAdapter Interface
40
-
41
- Create a new class that implements the `ChainAdapter` interface:
42
-
43
- ```ts twoslash
44
- // [!include ~/../src/chain-adapters/EVM/EVM.ts]
45
- ```
@@ -1,52 +0,0 @@
1
- # Implementing a Custom Chain Signature Contract
2
-
3
- This guide explains how to implement a custom Chain Signature Contract to provide as argument when instantiating a Chain instance.
4
-
5
- ## Overview
6
-
7
- The `ChainSignatureContract` is an abstract class that defines the interface for interacting with the Sig Network infrastructure.
8
-
9
- - Key Derivation: Derive the child key from the root key using Sig Network key derivation function
10
- - Sign: Sigs the given payload using Sig Network MPC
11
- - Current Fee: Gets the current signature deposit that handles network congestion
12
- - Root Public Key: Gets the root public key of the Smart Contract on Sig Network MPC
13
-
14
- While the library includes a default implementation for the NEAR protocol, you have the flexibility to implement your own contract for other blockchain networks.
15
-
16
- ## Using the NEAR Implementation
17
-
18
- ```ts twoslash
19
- // [!include ~/snippets/code/near/env.ts]
20
- // ---cut---
21
- import { contracts, chainAdapters } from 'signet.js'
22
-
23
- const contract = new contracts.near.ChainSignatureContract({
24
- networkId: 'testnet',
25
- contractId: 'v1.signer-prod.testnet',
26
- accountId,
27
- keypair,
28
- })
29
-
30
- const evmChain = new chainAdapters.evm.EVM({
31
- rpcUrl: 'https://mainnet.infura.io/v3/YOUR-PROJECT-ID',
32
- contract,
33
- })
34
- ```
35
-
36
- ## Implementing a Custom Chain Signature Contract
37
-
38
- To create your own implementation to use on the [Chain Adapter](/primitives/chain-adapter-interface.mdx) Instance, your contract must implement the `BaseChainSignatureContract` interface.
39
-
40
- In case you need you want all Sig Network Smart Contract capabilities, you can implement the `ChainSignatureContract` interface.
41
-
42
- ```ts twoslash
43
- // [!include ~/../src/contracts/ChainSignatureContract.ts]
44
- ```
45
-
46
- ### Example: NEAR Implementation
47
-
48
- Below is the reference implementation for the NEAR, which you can use as a guide for implementing your own chain signature contract:
49
-
50
- ```ts twoslash
51
- // [!include ~/../src/contracts/near/ChainSignatureContract.ts]
52
- ```
@@ -1,27 +0,0 @@
1
- # Contract Addresses
2
-
3
- All the necessary constants to interact with the Sig Network are exported from the `constants.ts` file.
4
-
5
- ## Using the Constants in your code
6
-
7
- You can import and use them in your code as follows:
8
-
9
- ```ts twoslash
10
- import { constants } from 'signet.js'
11
-
12
- const evmTestnetAddress = constants.CONTRACT_ADDRESSES.ETHEREUM.TESTNET
13
-
14
- console.log(evmTestnetAddress) // '0x83458E8Bf8206131Fe5c05127007FA164c0948A2'
15
-
16
- const testnetPublicKey = constants.ROOT_PUBLIC_KEYS.TESTNET
17
-
18
- console.log(testnetPublicKey) // 'secp256k1:3Ww8iFjqTHufye5aRGUvrQqETegR4gVUcW8FX5xzscaN9ENhpkffojsxJwi6N1RbbHMTxYa9UyKeqK3fsMuwxjR5'
19
- ```
20
-
21
- ## Constants file
22
-
23
- For reference, here is the file with the full list of constants and their explanations:
24
-
25
- ```ts twoslash
26
- // [!include ~/../src/constants.ts]
27
- ```
@@ -1,26 +0,0 @@
1
- # Implementing a Bitcoin RPC Adapter
2
-
3
- This guide explains how to implement a custom RPC adapter for interacting with Bitcoin nodes or services.
4
-
5
- ## Overview
6
-
7
- The `BTCRpcAdapter` provides an abstraction layer for Bitcoin-specific operations like UTXO management, balance queries, and transaction broadcasting. You might want to implement a custom adapter when:
8
-
9
- - Using a different Bitcoin API provider
10
- - Implementing specialized UTXO selection strategies
11
-
12
- ## Base Class
13
-
14
- In order to implement a custom adapter, you need to implement the `BTCRpcAdapter` abstract class:
15
-
16
- ```ts twoslash
17
- // [!include ~/../src/chain-adapters/Bitcoin/BTCRpcAdapter/BTCRpcAdapter.ts]
18
- ```
19
-
20
- ### 2. Example
21
-
22
- There is an example implementation of the `BTCRpcAdapter` abstract class in the `Mempool` class:
23
-
24
- ```ts twoslash
25
- // [!include ~/../src/chain-adapters/Bitcoin/BTCRpcAdapter/Mempool/Mempool.ts]
26
- ```
@@ -1,47 +0,0 @@
1
- import './prepare-transaction-for-signing.mdx'
2
-
3
- # finalizeTransactionSigning
4
-
5
- The `finalizeTransactionSigning` method adds signatures to a Bitcoin PSBT and finalizes it for broadcasting to the network.
6
-
7
- ## Usage
8
-
9
- ```ts twoslash
10
- // [!include ~/snippets/code/chains.ts]
11
- // ---cut---
12
- const { transaction, hashesToSign } =
13
- await btcChain.prepareTransactionForSigning({
14
- from: 'bc1qxy2kgdygjrsqtzq2n0yrf2493p83kkfjhx0wlh',
15
- to: 'bc1qw508d6qejxtdg4y5r3zarvary0c5xw7kv8f3t4',
16
- value: '0.001', // 0.001 BTC
17
- publicKey: '0235a3...',
18
- })
19
- // ---cut---
20
- import { RSVSignature } from 'signet.js'
21
-
22
- const rsvSignatures: RSVSignature[] = [
23
- {
24
- r: '0x123...',
25
- s: '0x123...',
26
- v: 27,
27
- },
28
- ]
29
-
30
- const signedTx = btcChain.finalizeTransactionSigning({
31
- transaction,
32
- rsvSignatures,
33
- })
34
- ```
35
-
36
- ## Parameters
37
-
38
- | Parameter | Type | Description |
39
- | --------------- | ------------------------ | ---------------------------------------------------------- |
40
- | `transaction` | `BTCUnsignedTransaction` | The unsigned PSBT returned by prepareTransactionForSigning |
41
- | `rsvSignatures` | `RSVSignature[]` | Array of RSV signatures from the MPC network |
42
-
43
- ## Returns
44
-
45
- | Type | Description |
46
- | -------- | ----------------------------------------------------------------------- |
47
- | `string` | The serialized signed transaction in hex format, ready for broadcasting |
@@ -1,119 +0,0 @@
1
- # Bitcoin Chain
2
-
3
- The Bitcoin chain implementation in Signet.js provides support for both Bitcoin mainnet and testnet networks, with a focus on P2WPKH (Native SegWit) transactions.
4
-
5
- ## Overview
6
-
7
- The Bitcoin implementation allows you to:
8
-
9
- - Generate addresses and public keys
10
- - Check balances
11
- - Prepare, sign, and broadcast transactions
12
- - Work with UTXOs (Unspent Transaction Outputs)
13
-
14
- ## Complete Transaction Example
15
-
16
- Below is a complete example of sending a transaction on the Bitcoin network using Signet.js:
17
-
18
- ```ts twoslash
19
- import { chainAdapters } from 'signet.js'
20
- // [!include ~/snippets/code/evm/contract.ts]
21
-
22
- const btcRpcAdapter = new chainAdapters.btc.BTCRpcAdapters.Mempool(
23
- 'https://mempool.space/api'
24
- )
25
-
26
- const bitcoin = new chainAdapters.btc.Bitcoin({
27
- network: 'testnet',
28
- contract: evmChainSigContract,
29
- btcRpcAdapter,
30
- })
31
-
32
- const path = 'btc'
33
- const predecessorId = walletClient.account.address
34
-
35
- const { address: from, publicKey } = await bitcoin.deriveAddressAndPublicKey(
36
- predecessorId,
37
- path
38
- )
39
-
40
- const { balance, decimals } = await bitcoin.getBalance(from)
41
-
42
- const { transaction, hashesToSign } =
43
- await bitcoin.prepareTransactionForSigning({
44
- from,
45
- to: 'tb1qw508d6qejxtdg4y5r3zarvary0c5xw7kxpjzsx',
46
- value: '0.001', // 0.001 BTC
47
- publicKey,
48
- })
49
-
50
- const rsvSignature = await evmChainSigContract.sign({
51
- payload: hashesToSign[0],
52
- path,
53
- key_version: 0,
54
- })
55
-
56
- const tx = bitcoin.finalizeTransactionSigning({
57
- transaction,
58
- rsvSignatures: [rsvSignature],
59
- })
60
-
61
- const txHash = await bitcoin.broadcastTx(tx)
62
- ```
63
-
64
- ### Supported Networks
65
-
66
- You can use different Bitcoin networks by specifying the network parameter:
67
-
68
- ```ts twoslash
69
- // [!include ~/snippets/code/contract.ts]
70
- // ---cut---
71
- import { chainAdapters } from 'signet.js'
72
-
73
- const btcRpcAdapter = new chainAdapters.btc.BTCRpcAdapters.Mempool(
74
- 'https://mempool.space/api'
75
- )
76
-
77
- // Bitcoin Mainnet
78
- const mainnetBitcoin = new chainAdapters.btc.Bitcoin({
79
- network: 'mainnet',
80
- contract: evmChainSigContract,
81
- btcRpcAdapter,
82
- })
83
-
84
- // Bitcoin Testnet
85
- const testnetBitcoin = new chainAdapters.btc.Bitcoin({
86
- network: 'testnet',
87
- contract: evmChainSigContract,
88
- btcRpcAdapter,
89
- })
90
-
91
- // Bitcoin Regtest (for local development)
92
- const regtestBitcoin = new chainAdapters.btc.Bitcoin({
93
- network: 'regtest',
94
- contract: evmChainSigContract,
95
- btcRpcAdapter,
96
- })
97
- ```
98
-
99
- ## RPC Adapter
100
-
101
- The RPC adapter is a class that provides an interface for interacting with the Bitcoin network. It handles essential operations such as:
102
-
103
- - Fetching UTXOs (Unspent Transaction Outputs)
104
- - Retrieving transaction details
105
- - Getting current network fees
106
- - Broadcasting transactions
107
- - Querying address balances
108
-
109
- The adapter abstracts away the complexity of different Bitcoin API providers, allowing you to easily switch between services like Mempool.space, BlockCypher, or your own Bitcoin node.
110
-
111
- For detailed implementation and configuration options, see the [RPC Adapter](/signetjs/chain-adapters/bitcoin/btc-rpc-adapter) documentation.
112
-
113
- ## Types
114
-
115
- The following types are used on the Bitcoin chain:
116
-
117
- ```ts twoslash
118
- // [!include ~/../src/chain-adapters/Bitcoin/types.ts]
119
- ```
@@ -1,30 +0,0 @@
1
- # prepareTransactionForSigning
2
-
3
- The `prepareTransactionForSigning` method prepares a Bitcoin transaction for MPC signing by creating a PSBT (Partially Signed Bitcoin Transaction) and computing the hash that needs to be signed.
4
-
5
- ## Usage
6
-
7
- ```ts twoslash
8
- // [!include ~/snippets/code/chains.ts]
9
- // ---cut---
10
- const { transaction, hashesToSign } =
11
- await btcChain.prepareTransactionForSigning({
12
- from: 'bc1qxy2kgdygjrsqtzq2n0yrf2493p83kkfjhx0wlh',
13
- to: 'bc1qw508d6qejxtdg4y5r3zarvary0c5xw7kv8f3t4',
14
- value: '0.001', // 0.001 BTC
15
- publicKey: '0235a3...',
16
- })
17
- ```
18
-
19
- ## Parameters
20
-
21
- | Parameter | Type | Description |
22
- | -------------------- | ----------------------- | ---------------------------------------------------------------------------------------------------- |
23
- | `transactionRequest` | `BTCTransactionRequest` | The transaction request object containing from, to, value, publicKey, and optional feeRate and utxos |
24
-
25
- ## Returns
26
-
27
- | Property | Type | Description |
28
- | -------------- | ------------------------ | -------------------------------------- |
29
- | `transaction` | `BTCUnsignedTransaction` | Object containing the unsigned PSBT |
30
- | `hashesToSign` | `string[]` | Array of hashes that need to be signed |
@@ -1,23 +0,0 @@
1
- # broadcastTx
2
-
3
- The `broadcastTx` method broadcasts a signed transaction.
4
-
5
- ## Usage
6
-
7
- ```ts twoslash
8
- // [!include ~/snippets/code/chains.ts]
9
- // ---cut---
10
- const txHash = await evmChain.broadcastTx('0x02f8...')
11
- ```
12
-
13
- ## Parameters
14
-
15
- | Parameter | Type | Description |
16
- | -------------- | -------- | --------------------------------- |
17
- | `txSerialized` | `string` | The serialized signed transaction |
18
-
19
- ## Returns
20
-
21
- | Type | Description |
22
- | -------- | -------------------- |
23
- | `string` | The transaction hash |
@@ -1,53 +0,0 @@
1
- # finalizeTransactionSigning
2
-
3
- The `finalizeTransactionSigning` method adds signatures to a Cosmos transaction and finalizes it for broadcasting to the network.
4
-
5
- ## Usage
6
-
7
- ```ts twoslash
8
- // [!include ~/snippets/code/chains.ts]
9
- const { transaction, hashesToSign } =
10
- await cosmosChain.prepareTransactionForSigning({
11
- address: 'cosmos1...',
12
- publicKey: '0350e8...',
13
- messages: [
14
- {
15
- typeUrl: '/cosmos.bank.v1beta1.MsgSend',
16
- value: {
17
- fromAddress: 'cosmos1...',
18
- toAddress: 'cosmos1...',
19
- amount: [{ denom: 'uatom', amount: '1000000' }],
20
- },
21
- },
22
- ],
23
- memo: 'Token transfer',
24
- })
25
- // ---cut---
26
- import { RSVSignature } from 'signet.js'
27
-
28
- const rsvSignatures: RSVSignature[] = [
29
- {
30
- r: '0x123...',
31
- s: '0x123...',
32
- v: 27,
33
- },
34
- ]
35
-
36
- const signedTx = cosmosChain.finalizeTransactionSigning({
37
- transaction,
38
- rsvSignatures,
39
- })
40
- ```
41
-
42
- ## Parameters
43
-
44
- | Parameter | Type | Description |
45
- | --------------- | --------------------------- | ----------------------------------------------------------------- |
46
- | `transaction` | `CosmosUnsignedTransaction` | The unsigned transaction object from prepareTransactionForSigning |
47
- | `rsvSignatures` | `RSVSignature[]` | Array of RSV signatures from the MPC network |
48
-
49
- ## Returns
50
-
51
- | Type | Description |
52
- | -------- | ----------------------------------------------------------------------- |
53
- | `string` | The serialized signed transaction in hex format, ready for broadcasting |