signet.js 0.0.12 → 0.3.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 CHANGED
@@ -25,46 +25,33 @@ yarn add signet.js
25
25
  pnpm add signet.js
26
26
  ```
27
27
 
28
- ## Quick Example
28
+ ## Quick Example (EVM)
29
29
 
30
30
  ```ts twoslash
31
31
  import { chainAdapters, contracts } from 'signet.js'
32
- import { KeyPair, type KeyPairString } from '@near-js/crypto'
33
- import { createPublicClient, http } from 'viem';
34
- import { mainnet } from "viem/chains";
35
-
36
- // Initialize NEAR connection with credentials from environment
37
- const accountId = process.env.NEAR_ACCOUNT_ID
38
- const privateKey = process.env.NEAR_PRIVATE_KEY as KeyPairString
39
-
40
- if (!accountId || !privateKey) {
41
- throw new Error(
42
- 'NEAR_ACCOUNT_ID and NEAR_PRIVATE_KEY must be set in environment'
43
- )
44
- }
45
-
46
- const keypair = KeyPair.fromString(privateKey)
47
-
48
- const contract = new contracts.near.ChainSignatureContract({
49
- networkId: 'testnet',
50
- contractId: 'v1.signer-prod.testnet',
51
- accountId,
52
- keypair,
53
- })
32
+ import { createPublicClient, http } from 'viem'
33
+ import { mainnet } from 'viem/chains'
54
34
 
55
35
  const publicClient = createPublicClient({
56
- chain: mainnet,
57
- transport: http(),
58
- });
36
+ chain: mainnet,
37
+ transport: http(),
38
+ })
39
+
40
+ // Assume you already instantiated your ChainSignatures EVM contract wrapper
41
+ const contract = new contracts.evm.ChainSignaturesContract({
42
+ contractAddress: '0xYourContractAddress' as `0x${string}`,
43
+ walletClient: /* your WalletClient */ undefined as any,
44
+ })
59
45
 
60
46
  const evmChain = new chainAdapters.evm.EVM({
61
47
  publicClient,
62
48
  contract,
63
49
  })
64
50
 
65
- // Derive address and public key
51
+ // Derive address and public key for a predecessor identifier
52
+ const predecessorId = '0xYourEOAOrContract'
66
53
  const { address, publicKey } = await evmChain.deriveAddressAndPublicKey(
67
- accountId,
54
+ predecessorId,
68
55
  'any_string'
69
56
  )
70
57
 
@@ -74,25 +61,24 @@ const { balance, decimals } = await evmChain.getBalance(address)
74
61
  // Create and sign transaction
75
62
  const { transaction, hashesToSign } =
76
63
  await evmChain.prepareTransactionForSigning({
77
- from: '0x...',
64
+ from: address,
78
65
  to: '0x...',
79
66
  value: 1n,
80
67
  })
81
68
 
82
- // Sign with MPC
83
- const signature = await contract.sign({
84
- payload: hashesToSign[0].payload,
69
+ // Request MPC signature
70
+ const rsvSignature = await contract.sign({
71
+ payload: hashesToSign[0],
85
72
  path: 'any_string',
86
73
  key_version: 0,
87
74
  })
88
75
 
89
- // Add signature
76
+ // Finalize and broadcast
90
77
  const signedTx = evmChain.finalizeTransactionSigning({
91
78
  transaction,
92
- rsvSignatures: [signature],
79
+ rsvSignatures: [rsvSignature],
93
80
  })
94
81
 
95
- // Broadcast transaction
96
82
  const txHash = await evmChain.broadcastTx(signedTx)
97
83
  ```
98
84
 
@@ -0,0 +1,18 @@
1
+ //#region rolldown:runtime
2
+ var __defProp = Object.defineProperty;
3
+ var __export = (all, symbols) => {
4
+ let target = {};
5
+ for (var name in all) {
6
+ __defProp(target, name, {
7
+ get: all[name],
8
+ enumerable: true
9
+ });
10
+ }
11
+ if (symbols) {
12
+ __defProp(target, Symbol.toStringTag, { value: "Module" });
13
+ }
14
+ return target;
15
+ };
16
+
17
+ //#endregion
18
+ export { __export as t };