-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.ts
More file actions
59 lines (47 loc) · 1.83 KB
/
script.ts
File metadata and controls
59 lines (47 loc) · 1.83 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
import {
WalletSDKImpl,
localNetAuthDefault,
localNetLedgerDefault,
localNetTopologyDefault,
localNetTokenStandardDefault,
createKeyPair,
signTransactionHash,
TopologyController,
localValidatorDefault
} from '@canton-network/wallet-sdk'
// Node cannot resolve subdomain.localhost, therefore add the following mapping to your /etc/hosts
// 127.0.0.1 scan.localhost
// 127.0.0.1 wallet.localhost
export const LOCALNET_SCAN_API_URL = new URL(
'http://scan.localhost:4000/api/scan'
)
export const LOCALNET_REGISTRY_API_URL = new URL('http://scan.localhost:4000')
import { v4 } from 'uuid'
// it is important to configure the SDK correctly else you might run into connectivity or authentication issues
const sdk = new WalletSDKImpl().configure({
logger: console,
authFactory: localNetAuthDefault,
ledgerFactory: localNetLedgerDefault,
topologyFactory: localNetTopologyDefault,
tokenStandardFactory: localNetTokenStandardDefault,
validatorFactory: localValidatorDefault,
})
await sdk.connect()
await sdk.connectTopology(LOCALNET_SCAN_API_URL)
const { publicKey, privateKey } = TopologyController.createNewKeyPair()
const fingerPrint = TopologyController.createFingerprintFromPublicKey(publicKey)
console.log("publicKey is " + publicKey)
console.log("fingerPrint is " + fingerPrint)
console.log(`[${new Date().toISOString()}] privateKey is ${privateKey}`)
const partyHint = 'my-wallet-1'
const allocatedParty = await sdk.topology?.prepareSignAndSubmitExternalParty(
privateKey,
partyHint
)
console.log(`[${new Date().toISOString()}] partyId is ${allocatedParty.partyId}`)
sdk.validator?.setPartyId(allocatedParty.partyId)
try {
await sdk.validator?.externalPartyPreApprovalSetup(privateKey)
} catch (error) {
console.error("Error during external party pre-approval setup:", error)
}