signet.js 0.0.1-beta.5 → 0.0.1-beta.7

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 (121) hide show
  1. package/.eslintrc.json +55 -0
  2. package/.prettierrc +1 -0
  3. package/LICENSE +19 -0
  4. package/README.md +42 -14
  5. package/babel.config.js +6 -0
  6. package/docs/pages/chain-signatures-contract.mdx +56 -0
  7. package/docs/pages/chain.mdx +45 -0
  8. package/docs/pages/chains/bitcoin/bitcoin.mdx +191 -0
  9. package/docs/pages/chains/bitcoin/btc-rpc-adapter.mdx +307 -0
  10. package/docs/pages/chains/cosmos.mdx +181 -0
  11. package/docs/pages/chains/evm.mdx +189 -0
  12. package/docs/pages/index.mdx +99 -0
  13. package/docs/snippets/contract.ts +21 -0
  14. package/docs/snippets/env.ts +13 -0
  15. package/jest.config.ts +199 -0
  16. package/package.json +21 -11
  17. package/src/chains/Bitcoin/BTCRpcAdapter/BTCRpcAdapter.ts +11 -0
  18. package/src/chains/Bitcoin/BTCRpcAdapter/Mempool/Mempool.ts +96 -0
  19. package/src/chains/Bitcoin/BTCRpcAdapter/Mempool/index.ts +1 -0
  20. package/src/chains/Bitcoin/BTCRpcAdapter/Mempool/types.ts +72 -0
  21. package/src/chains/Bitcoin/BTCRpcAdapter/index.ts +6 -0
  22. package/src/chains/Bitcoin/Bitcoin.ts +301 -0
  23. package/src/chains/Bitcoin/types.ts +45 -0
  24. package/src/chains/Bitcoin/utils.ts +14 -0
  25. package/src/chains/Chain.ts +96 -0
  26. package/src/chains/ChainSignatureContract.ts +48 -0
  27. package/src/chains/Cosmos/Cosmos.ts +279 -0
  28. package/src/chains/Cosmos/types.ts +35 -0
  29. package/src/chains/Cosmos/utils.ts +45 -0
  30. package/src/chains/EVM/EVM.ts +180 -0
  31. package/src/chains/EVM/types.ts +7 -0
  32. package/src/chains/EVM/utils.ts +26 -0
  33. package/src/chains/index.ts +34 -0
  34. package/src/chains/types.ts +35 -0
  35. package/src/chains/utils.ts +40 -0
  36. package/src/index.ts +2 -0
  37. package/src/utils/chains/index.ts +1 -0
  38. package/src/utils/chains/near/ChainSignatureContract.ts +195 -0
  39. package/src/utils/chains/near/account.ts +42 -0
  40. package/src/utils/chains/near/constants.ts +4 -0
  41. package/src/utils/chains/near/index.ts +3 -0
  42. package/src/utils/chains/near/relayer/index.ts +1 -0
  43. package/src/utils/chains/near/relayer/relayer.ts +39 -0
  44. package/src/utils/chains/near/relayer/types.ts +24 -0
  45. package/src/utils/chains/near/signAndSend/index.ts +1 -0
  46. package/src/utils/chains/near/signAndSend/keypair.ts +180 -0
  47. package/src/utils/chains/near/transactionBuilder.ts +138 -0
  48. package/src/utils/chains/near/types.ts +67 -0
  49. package/src/utils/index.ts +1 -0
  50. package/tsconfig.eslint.json +8 -0
  51. package/tsconfig.json +116 -0
  52. package/vite.config.ts +47 -0
  53. package/vocs.config.ts +60 -0
  54. package/src/chains/Bitcoin/BTCRpcAdapter/BTCRpcAdapter.d.ts +0 -10
  55. package/src/chains/Bitcoin/BTCRpcAdapter/BTCRpcAdapter.js +0 -2
  56. package/src/chains/Bitcoin/BTCRpcAdapter/Mempool/Mempool.d.ts +0 -15
  57. package/src/chains/Bitcoin/BTCRpcAdapter/Mempool/Mempool.js +0 -69
  58. package/src/chains/Bitcoin/BTCRpcAdapter/Mempool/index.d.ts +0 -1
  59. package/src/chains/Bitcoin/BTCRpcAdapter/Mempool/index.js +0 -1
  60. package/src/chains/Bitcoin/BTCRpcAdapter/Mempool/types.d.ts +0 -69
  61. package/src/chains/Bitcoin/BTCRpcAdapter/Mempool/types.js +0 -1
  62. package/src/chains/Bitcoin/BTCRpcAdapter/index.d.ts +0 -5
  63. package/src/chains/Bitcoin/BTCRpcAdapter/index.js +0 -5
  64. package/src/chains/Bitcoin/Bitcoin.d.ts +0 -69
  65. package/src/chains/Bitcoin/Bitcoin.js +0 -198
  66. package/src/chains/Bitcoin/types.d.ts +0 -42
  67. package/src/chains/Bitcoin/types.js +0 -1
  68. package/src/chains/Bitcoin/utils.d.ts +0 -2
  69. package/src/chains/Bitcoin/utils.js +0 -13
  70. package/src/chains/Chain.d.ts +0 -89
  71. package/src/chains/Chain.js +0 -9
  72. package/src/chains/ChainSignatureContract.d.ts +0 -62
  73. package/src/chains/ChainSignatureContract.js +0 -7
  74. package/src/chains/Cosmos/Cosmos.d.ts +0 -51
  75. package/src/chains/Cosmos/Cosmos.js +0 -157
  76. package/src/chains/Cosmos/types.d.ts +0 -30
  77. package/src/chains/Cosmos/types.js +0 -1
  78. package/src/chains/Cosmos/utils.d.ts +0 -2
  79. package/src/chains/Cosmos/utils.js +0 -27
  80. package/src/chains/EVM/EVM.d.ts +0 -42
  81. package/src/chains/EVM/EVM.js +0 -109
  82. package/src/chains/EVM/types.d.ts +0 -5
  83. package/src/chains/EVM/types.js +0 -1
  84. package/src/chains/EVM/utils.d.ts +0 -7
  85. package/src/chains/EVM/utils.js +0 -14
  86. package/src/chains/index.d.ts +0 -12
  87. package/src/chains/index.js +0 -12
  88. package/src/chains/types.d.ts +0 -31
  89. package/src/chains/types.js +0 -1
  90. package/src/chains/utils.d.ts +0 -12
  91. package/src/chains/utils.js +0 -27
  92. package/src/index.d.ts +0 -2
  93. package/src/index.js +0 -2
  94. package/src/utils/chains/index.d.ts +0 -1
  95. package/src/utils/chains/index.js +0 -1
  96. package/src/utils/chains/near/account.d.ts +0 -13
  97. package/src/utils/chains/near/account.js +0 -22
  98. package/src/utils/chains/near/constants.d.ts +0 -3
  99. package/src/utils/chains/near/constants.js +0 -3
  100. package/src/utils/chains/near/contract.d.ts +0 -40
  101. package/src/utils/chains/near/contract.js +0 -102
  102. package/src/utils/chains/near/index.d.ts +0 -3
  103. package/src/utils/chains/near/index.js +0 -3
  104. package/src/utils/chains/near/relayer/index.d.ts +0 -1
  105. package/src/utils/chains/near/relayer/index.js +0 -1
  106. package/src/utils/chains/near/relayer/relayer.d.ts +0 -8
  107. package/src/utils/chains/near/relayer/relayer.js +0 -33
  108. package/src/utils/chains/near/relayer/types.d.ts +0 -22
  109. package/src/utils/chains/near/relayer/types.js +0 -1
  110. package/src/utils/chains/near/signAndSend/index.d.ts +0 -1
  111. package/src/utils/chains/near/signAndSend/index.js +0 -1
  112. package/src/utils/chains/near/signAndSend/keypair.d.ts +0 -6
  113. package/src/utils/chains/near/signAndSend/keypair.js +0 -127
  114. package/src/utils/chains/near/transactionBuilder.d.ts +0 -26
  115. package/src/utils/chains/near/transactionBuilder.js +0 -72
  116. package/src/utils/chains/near/types.d.ts +0 -50
  117. package/src/utils/chains/near/types.js +0 -1
  118. package/src/utils/index.d.ts +0 -1
  119. package/src/utils/index.js +0 -1
  120. package/vocs.config.d.ts +0 -3
  121. package/vocs.config.js +0 -71
@@ -1,127 +0,0 @@
1
- import { Bitcoin, Cosmos, EVM } from '../../../../chains/index.js';
2
- import { BTCRpcAdapters } from '../../../../chains/Bitcoin/BTCRpcAdapter';
3
- import { getNearAccount } from '../../../chains/near/account';
4
- import { NearChainSignatureContract } from '../../../chains/near/contract';
5
- export const EVMTransaction = async (req, keyPair) => {
6
- try {
7
- const account = await getNearAccount({
8
- networkId: req.nearAuthentication.networkId,
9
- accountId: req.nearAuthentication.accountId,
10
- keypair: keyPair,
11
- });
12
- const contract = new NearChainSignatureContract({
13
- networkId: req.nearAuthentication.networkId,
14
- contractId: req.chainConfig.contract,
15
- accountId: account.accountId,
16
- keypair: keyPair,
17
- });
18
- const evm = new EVM({
19
- rpcUrl: req.chainConfig.providerUrl,
20
- contract,
21
- });
22
- const { transaction, mpcPayloads } = await evm.getMPCPayloadAndTransaction(req.transaction);
23
- const signature = await contract.sign({
24
- payload: mpcPayloads[0].payload,
25
- path: req.derivationPath,
26
- key_version: 0,
27
- });
28
- const txSerialized = evm.addSignature({
29
- transaction,
30
- mpcSignatures: [signature],
31
- });
32
- const txHash = await evm.broadcastTx(txSerialized);
33
- return {
34
- transactionHash: txHash,
35
- success: true,
36
- };
37
- }
38
- catch (e) {
39
- console.error(e);
40
- return {
41
- success: false,
42
- errorMessage: e instanceof Error ? e.message : String(e),
43
- };
44
- }
45
- };
46
- export const BTCTransaction = async (req, keyPair) => {
47
- try {
48
- const account = await getNearAccount({
49
- networkId: req.nearAuthentication.networkId,
50
- accountId: req.nearAuthentication.accountId,
51
- keypair: keyPair,
52
- });
53
- const contract = new NearChainSignatureContract({
54
- networkId: req.nearAuthentication.networkId,
55
- contractId: req.chainConfig.contract,
56
- accountId: account.accountId,
57
- keypair: keyPair,
58
- });
59
- const btc = new Bitcoin({
60
- btcRpcAdapter: new BTCRpcAdapters.Mempool(req.chainConfig.providerUrl),
61
- contract,
62
- network: req.chainConfig.network,
63
- });
64
- const { transaction, mpcPayloads } = await btc.getMPCPayloadAndTransaction(req.transaction);
65
- const signatures = await Promise.all(mpcPayloads.map(async ({ payload }) => await contract.sign({
66
- payload,
67
- path: req.derivationPath,
68
- key_version: 0,
69
- })));
70
- const txSerialized = btc.addSignature({
71
- transaction,
72
- mpcSignatures: signatures,
73
- });
74
- const txHash = await btc.broadcastTx(txSerialized);
75
- return {
76
- transactionHash: txHash,
77
- success: true,
78
- };
79
- }
80
- catch (e) {
81
- return {
82
- success: false,
83
- errorMessage: e instanceof Error ? e.message : String(e),
84
- };
85
- }
86
- };
87
- export const CosmosTransaction = async (req, keyPair) => {
88
- try {
89
- const account = await getNearAccount({
90
- networkId: req.nearAuthentication.networkId,
91
- accountId: req.nearAuthentication.accountId,
92
- keypair: keyPair,
93
- });
94
- const contract = new NearChainSignatureContract({
95
- networkId: req.nearAuthentication.networkId,
96
- contractId: req.chainConfig.contract,
97
- accountId: account.accountId,
98
- keypair: keyPair,
99
- });
100
- const cosmos = new Cosmos({
101
- contract,
102
- chainId: req.chainConfig.chainId,
103
- });
104
- const { transaction, mpcPayloads } = await cosmos.getMPCPayloadAndTransaction(req.transaction);
105
- const signatures = await Promise.all(mpcPayloads.map(async ({ payload }) => await contract.sign({
106
- payload,
107
- path: req.derivationPath,
108
- key_version: 0,
109
- })));
110
- const txSerialized = cosmos.addSignature({
111
- transaction,
112
- mpcSignatures: signatures,
113
- });
114
- const txHash = await cosmos.broadcastTx(txSerialized);
115
- return {
116
- transactionHash: txHash,
117
- success: true,
118
- };
119
- }
120
- catch (e) {
121
- console.error(e);
122
- return {
123
- success: false,
124
- errorMessage: e instanceof Error ? e.message : String(e),
125
- };
126
- }
127
- };
@@ -1,26 +0,0 @@
1
- import type { Action, FinalExecutionOutcome, NetworkId } from '@near-wallet-selector/core';
2
- import { type RSVSignature, type KeyDerivationPath, type MPCPayloads } from '../../../chains/types';
3
- import { type NFTKeysContracts, type ChainSignatureContractIds } from '../../chains/near/types';
4
- export declare const mpcPayloadsToChainSigTransaction: ({ networkId, contractId, mpcPayloads, path, }: {
5
- networkId: NetworkId;
6
- contractId: ChainSignatureContractIds;
7
- mpcPayloads: MPCPayloads;
8
- path: KeyDerivationPath;
9
- }) => Promise<{
10
- receiverId: string;
11
- actions: Action[];
12
- }>;
13
- export declare const mpcPayloadsToNFTKeysTransaction: ({ networkId, chainSigContract, nftKeysContract, mpcPayloads, path, tokenId, }: {
14
- networkId: NetworkId;
15
- chainSigContract: ChainSignatureContractIds;
16
- nftKeysContract: NFTKeysContracts;
17
- mpcPayloads: MPCPayloads;
18
- path: KeyDerivationPath;
19
- tokenId: string;
20
- }) => Promise<{
21
- receiverId: string;
22
- actions: Action[];
23
- }>;
24
- export declare const responseToMpcSignature: ({ response, }: {
25
- response: FinalExecutionOutcome;
26
- }) => RSVSignature | undefined;
@@ -1,72 +0,0 @@
1
- import BN from 'bn.js';
2
- import { utils } from '../../../chains/index.js';
3
- import { NEAR_MAX_GAS } from '../../chains/near/constants';
4
- import { NearChainSignatureContract } from '../../chains/near/contract';
5
- export const mpcPayloadsToChainSigTransaction = async ({ networkId, contractId, mpcPayloads, path, }) => {
6
- const contract = new NearChainSignatureContract({
7
- networkId,
8
- contractId,
9
- });
10
- const currentContractFee = await contract.getCurrentSignatureDeposit();
11
- return {
12
- receiverId: contractId,
13
- actions: mpcPayloads.map(({ payload }) => ({
14
- type: 'FunctionCall',
15
- params: {
16
- methodName: 'sign',
17
- args: {
18
- request: {
19
- payload: Array.from(payload),
20
- path,
21
- key_version: 0,
22
- },
23
- },
24
- gas: NEAR_MAX_GAS.div(new BN(mpcPayloads.length)).toString(),
25
- deposit: currentContractFee?.toString() || '1',
26
- },
27
- })),
28
- };
29
- };
30
- export const mpcPayloadsToNFTKeysTransaction = async ({ networkId, chainSigContract, nftKeysContract, mpcPayloads, path, tokenId, }) => {
31
- const contract = new NearChainSignatureContract({
32
- networkId,
33
- contractId: chainSigContract,
34
- });
35
- const currentContractFee = await contract.getCurrentSignatureDeposit();
36
- return {
37
- receiverId: nftKeysContract,
38
- actions: mpcPayloads.map(({ payload }) => ({
39
- type: 'FunctionCall',
40
- params: {
41
- methodName: 'ckt_sign_hash',
42
- args: {
43
- token_id: tokenId,
44
- path,
45
- payload: Array.from(payload),
46
- },
47
- gas: NEAR_MAX_GAS.div(new BN(mpcPayloads.length)).toString(),
48
- deposit: currentContractFee?.toString() || '1',
49
- },
50
- })),
51
- };
52
- };
53
- export const responseToMpcSignature = ({ response, }) => {
54
- const signature = response.receipts_outcome.reduce((acc, curr) => {
55
- if (acc) {
56
- return acc;
57
- }
58
- const { status } = curr.outcome;
59
- return ((typeof status === 'object' &&
60
- status.SuccessValue &&
61
- status.SuccessValue !== '' &&
62
- Buffer.from(status.SuccessValue, 'base64').toString('utf-8')) ||
63
- '');
64
- }, '');
65
- if (signature) {
66
- const parsedJSONSignature = JSON.parse(signature);
67
- return utils.toRSV(parsedJSONSignature.Ok);
68
- }
69
- else {
70
- return undefined;
71
- }
72
- };
@@ -1,50 +0,0 @@
1
- import type { KeyDerivationPath } from '../../../chains/types';
2
- import type { BTCTransactionRequest, BTCNetworkIds } from '../../../chains/Bitcoin/types';
3
- import type { CosmosNetworkIds, CosmosTransactionRequest } from '../../../chains/Cosmos/types';
4
- import { type EVMTransactionRequest } from '../../../chains/EVM/types';
5
- /**
6
- Available ChainSignature contracts:
7
- - Mainnet: v1.signer
8
- - Testnet: v1.signer-prod.testnet
9
- - Development (unstable): v1.signer-dev.testnet
10
- */
11
- export type ChainSignatureContractIds = string;
12
- export type NFTKeysContracts = string;
13
- export type NearNetworkIds = 'mainnet' | 'testnet';
14
- export interface ChainProvider {
15
- providerUrl: string;
16
- contract: ChainSignatureContractIds;
17
- }
18
- export interface NearAuthentication {
19
- networkId: NearNetworkIds;
20
- accountId: string;
21
- }
22
- export type EVMChainConfigWithProviders = ChainProvider;
23
- export interface EVMRequest {
24
- transaction: EVMTransactionRequest;
25
- chainConfig: EVMChainConfigWithProviders;
26
- nearAuthentication: NearAuthentication;
27
- fastAuthRelayerUrl?: string;
28
- derivationPath: KeyDerivationPath;
29
- }
30
- export type BTCChainConfigWithProviders = ChainProvider & {
31
- network: BTCNetworkIds;
32
- };
33
- export interface BitcoinRequest {
34
- transaction: BTCTransactionRequest;
35
- chainConfig: BTCChainConfigWithProviders;
36
- nearAuthentication: NearAuthentication;
37
- fastAuthRelayerUrl?: string;
38
- derivationPath: KeyDerivationPath;
39
- }
40
- export interface CosmosChainConfig {
41
- contract: ChainSignatureContractIds;
42
- chainId: CosmosNetworkIds;
43
- }
44
- export interface CosmosRequest {
45
- chainConfig: CosmosChainConfig;
46
- transaction: CosmosTransactionRequest;
47
- nearAuthentication: NearAuthentication;
48
- derivationPath: KeyDerivationPath;
49
- fastAuthRelayerUrl?: string;
50
- }
@@ -1 +0,0 @@
1
- export {};
@@ -1 +0,0 @@
1
- export * as chains from './chains';
@@ -1 +0,0 @@
1
- export * as chains from './chains';
package/vocs.config.d.ts DELETED
@@ -1,3 +0,0 @@
1
- import { type Config } from 'vocs';
2
- declare const _default: Config;
3
- export default _default;
package/vocs.config.js DELETED
@@ -1,71 +0,0 @@
1
- import { defineConfig } from 'vocs';
2
- export default defineConfig({
3
- title: 'Signet.js',
4
- description: 'A TypeScript library for handling multi-chain transactions and signatures using MPC',
5
- twoslash: {
6
- compilerOptions: {
7
- strict: true,
8
- paths: {
9
- 'signet.js': ['./src'],
10
- '@chains': ['./src/chains'],
11
- '@utils': ['./src/utils'],
12
- '@chains/*': ['./src/chains/*'],
13
- '@utils/*': ['./src/utils/*'],
14
- },
15
- },
16
- },
17
- sidebar: [
18
- {
19
- text: 'Getting Started',
20
- items: [
21
- { text: 'Overview', link: '/' },
22
- { text: 'Sig Network', link: '/sig-net' },
23
- ],
24
- },
25
- {
26
- text: 'Supported Chains',
27
- items: [
28
- { text: 'EVM Chains', link: '/chains/evm' },
29
- { text: 'Bitcoin', link: '/chains/bitcoin' },
30
- { text: 'Cosmos', link: '/chains/cosmos' },
31
- ],
32
- },
33
- {
34
- text: 'Core Concepts',
35
- items: [
36
- { text: 'Chain Interface', link: '/guides/implementing-new-chain' },
37
- { text: 'MPC Overview', link: '/guides/mpc-overview' },
38
- ],
39
- },
40
- {
41
- text: 'Implementation Guides',
42
- collapsed: true,
43
- items: [
44
- {
45
- text: 'Creating a New Chain',
46
- link: '/guides/implementing-new-chain',
47
- },
48
- {
49
- text: 'Bitcoin RPC Adapter',
50
- link: '/guides/implementing-btc-adapter',
51
- },
52
- {
53
- text: 'Chain Signature Contract',
54
- link: '/guides/implementing-signature-contract',
55
- },
56
- ],
57
- },
58
- ],
59
- socials: [
60
- {
61
- icon: 'github',
62
- link: 'https://github.com/near/signet.js',
63
- },
64
- ],
65
- theme: {
66
- accentColor: {
67
- light: '#00C08B',
68
- dark: '#00E6A6',
69
- },
70
- },
71
- });