signet.js 0.0.12-beta1 → 0.2.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 +21 -35
- package/dist/chunk-BAz01cYq.js +18 -0
- package/dist/index.cjs +3080 -0
- package/dist/index.d.cts +2026 -0
- package/dist/index.d.ts +2024 -0
- package/dist/index.js +3014 -0
- package/package.json +28 -36
- package/browser/index.browser.cjs +0 -3
- package/browser/index.browser.cjs.map +0 -1
- package/browser/index.browser.js +0 -3
- package/browser/index.browser.js.map +0 -1
- package/node/index.node.cjs +0 -3
- package/node/index.node.cjs.map +0 -1
- package/node/index.node.js +0 -3
- package/node/index.node.js.map +0 -1
- package/types/index.d.cts +0 -1372
- package/types/index.d.ts +0 -1372
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 {
|
|
33
|
-
import {
|
|
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
|
-
|
|
57
|
-
|
|
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
|
-
|
|
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:
|
|
64
|
+
from: address,
|
|
78
65
|
to: '0x...',
|
|
79
66
|
value: 1n,
|
|
80
67
|
})
|
|
81
68
|
|
|
82
|
-
//
|
|
83
|
-
const
|
|
84
|
-
payload: hashesToSign[0]
|
|
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
|
-
//
|
|
76
|
+
// Finalize and broadcast
|
|
90
77
|
const signedTx = evmChain.finalizeTransactionSigning({
|
|
91
78
|
transaction,
|
|
92
|
-
rsvSignatures: [
|
|
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 };
|