1
- import Fs from "node:fs/promises" ;
2
1
3
- // import DashHd from "dashhd";
4
- // import * as DashHdUtils from "./dashhd-utils.ts";
5
2
import DashKeys from "dashkeys" ;
6
- // import * as DashTx from "dashtx";
7
- // import * as DashPlatform from "./dashplatform.js";
8
3
import * as Bincode from "./src/bincode.ts" ;
9
4
import * as DashBincode from "./2.0.0/generated_bincode.js" ;
10
- import * as QRCode from "./src/_qr.js" ;
11
5
import * as KeyUtils from "./src/key-utils.js" ;
12
6
import { connectToNode } from "./src/rpc.ts"
13
7
import { NODE_ADDRESS } from "./src/constants.ts"
@@ -18,36 +12,13 @@ import { deriveAllCreateIdentityKeys } from "./src/asset_lock.ts"
18
12
import { toHex } from "./src/hex.js"
19
13
import { base58 } from "./src/util/base58.ts"
20
14
21
- const nodeRpc = connectToNode ( NODE_ADDRESS ) ;
15
+ export async function step3CreateDocument ( walletPhrase : string , walletSalt : string , identityIndex : number , dataContractId : string , message : string ) {
22
16
23
- const walletKey = await loadWallet ( ) ;
17
+ const nodeRpc = connectToNode ( NODE_ADDRESS ) ;
24
18
25
- function printUsage ( ) {
26
- console . error ( "" ) ;
27
- console . error ( "USAGE" ) ;
28
- console . error ( ` ${ process . argv [ 0 ] } ${ process . argv [ 1 ] } <identity-index> <data-contract-id> [<message>]` ) ;
29
- console . error ( "" ) ;
30
- console . error ( "EXAMPLE" ) ;
31
- console . error ( ` ${ process . argv [ 0 ] } ${ process . argv [ 1 ] } 0 JEJjgpGiLqeH8yaUeAwbCzuhTeL3xBMUAvyRCiGBXkEn "It's working!"` ) ;
32
- console . error ( "" ) ;
33
- }
19
+ const walletKey = await loadWallet ( walletPhrase , walletSalt ) ;
34
20
35
- const identityIndex = parseInt ( process . argv [ 2 ] , 10 ) ;
36
- if ( isNaN ( identityIndex ) ) {
37
- printUsage ( ) ;
38
- process . exit ( 1 ) ;
39
- }
40
-
41
- const dataContractId = process . argv [ 3 ] ; // "JEJjgpGiLqeH8yaUeAwbCzuhTeL3xBMUAvyRCiGBXkEn"
42
- console . log ( 'dataContractId' , dataContractId , dataContractId . length ) ;
43
21
const dataContractIdBytes = base58 . decode ( dataContractId ) ;
44
- if ( dataContractIdBytes . length != 32 ) {
45
- printUsage ( ) ;
46
- process . exit ( 1 ) ;
47
- }
48
-
49
- const message = process . argv [ 4 ] ?? "It's working!" ;
50
-
51
22
52
23
const hdOpts = { version : "testnet" } as const ; // TODO
53
24
@@ -199,3 +170,41 @@ try {
199
170
console . log ( "Document ID:" + base58 . encode ( document_id ) )
200
171
console . log ( "https://testnet.platform-explorer.com/document/" + base58 . encode ( document_id ) )
201
172
console . log ( `https://testnet.platform-explorer.com/transaction/${ toHex ( transitionHash ) } ` ) ;
173
+ }
174
+
175
+ if ( typeof process === 'object' && process . argv [ 1 ] === import . meta. filename ) {
176
+
177
+ import ( "dotenv" ) . then ( dotenv => {
178
+ dotenv . default . config ( { path : ".env" } ) ;
179
+
180
+ let walletPhrase = process . env . DASH_WALLET_PHRASE ! ;
181
+ let walletSalt = process . env . DASH_WALLET_SALT ?? "" ;
182
+
183
+ function printUsage ( ) {
184
+ console . error ( "" ) ;
185
+ console . error ( "USAGE" ) ;
186
+ console . error ( ` ${ process . argv [ 0 ] } ${ process . argv [ 1 ] } <identity-index> <data-contract-id> [<message>]` ) ;
187
+ console . error ( "" ) ;
188
+ console . error ( "EXAMPLE" ) ;
189
+ console . error ( ` ${ process . argv [ 0 ] } ${ process . argv [ 1 ] } 0 JEJjgpGiLqeH8yaUeAwbCzuhTeL3xBMUAvyRCiGBXkEn "It's working!"` ) ;
190
+ console . error ( "" ) ;
191
+ }
192
+
193
+ const identityIndex = parseInt ( process . argv [ 2 ] , 10 ) ;
194
+ if ( isNaN ( identityIndex ) ) {
195
+ printUsage ( ) ;
196
+ process . exit ( 1 ) ;
197
+ }
198
+
199
+ const dataContractId = process . argv [ 3 ] ; // "JEJjgpGiLqeH8yaUeAwbCzuhTeL3xBMUAvyRCiGBXkEn"
200
+ console . log ( 'dataContractId' , dataContractId , dataContractId . length ) ;
201
+ const dataContractIdBytes = base58 . decode ( dataContractId ) ;
202
+ if ( dataContractIdBytes . length != 32 ) {
203
+ printUsage ( ) ;
204
+ process . exit ( 1 ) ;
205
+ }
206
+
207
+ const message = process . argv [ 4 ] ?? "It's working!" ;
208
+ step3CreateDocument ( walletPhrase , walletSalt , identityIndex , dataContractId , message ) ;
209
+ } ) ;
210
+ }
0 commit comments