@@ -64,39 +64,9 @@ async function main() {
64
64
let otherInfo = await wifToInfo ( otherWif , "testnet" ) ;
65
65
66
66
let identityIdHex = await readHex ( "./identity-id.hex" ) ;
67
+ let txidHex = await readHex ( "./txid.hex" ) ;
67
68
68
69
let txlocksigHex = await readHex ( "./rawtxlocksig.hex" ) ;
69
- {
70
- let len = txlocksigHex . length / 2 ;
71
- console . log ( ) ;
72
- console . log ( `Tx Lock Sig Hex (${ len } ):` ) ;
73
- console . log ( txlocksigHex ) ;
74
- }
75
-
76
- let vout = - 1 ;
77
- let instantLockTxHex = "" ;
78
- let instantLockSigHex = "" ;
79
- {
80
- let txlocksig = DashTx . parseUnknown ( txlocksigHex ) ;
81
- vout = txlocksig . outputs . findIndex ( function ( output ) {
82
- //@ts -expect-error
83
- return output . script === "6a00" ; // TODO match the burn
84
- } ) ;
85
- console . log ( txlocksig . outputs ) ;
86
- //@ts -expect-error
87
- instantLockSigHex = txlocksig . sigHashTypeHex ;
88
- let isLen = instantLockSigHex . length / 2 ;
89
- let len = txlocksigHex . length / 2 ;
90
- len -= isLen ;
91
- instantLockTxHex = txlocksigHex . slice ( 0 , len * 2 ) ;
92
- console . log ( ) ;
93
- console . log ( `Tx Hex (${ len } )` ) ;
94
- console . log ( instantLockTxHex ) ;
95
- console . log ( ) ;
96
- console . log ( `Tx Lock Sig Instant Lock Hex (${ isLen } )` ) ;
97
- //@ts -expect-error
98
- console . log ( txlocksig . sigHashTypeHex ) ;
99
- }
100
70
101
71
// let txid = await DashTx.utils.rpc(
102
72
// rpcAuthUrl,
@@ -110,39 +80,12 @@ async function main() {
110
80
// let blockchaininfo = await DashTx.utils.rpc(rpcAuthUrl, "getblockchaininfo");
111
81
// let nextBlock = blockchaininfo.blocks + 1;
112
82
113
- // TODO - AJ is here
114
-
115
- /** @param {any } magicZmqEmitter */
116
- async function getAssetLockInstantProof ( magicZmqEmitter ) {
117
- let assetLockInstantProof = {
118
- // type: INSTANT_ALP,
119
- instant_lock : DashTx . utils . hexToBytes ( instantLockSigHex ) ,
120
- transaction : DashTx . utils . hexToBytes ( instantLockTxHex ) , // TODO this may need the proof, not the signed tx
121
- // output_index: DashTx.utils.hexToBytes(vout),
122
- output_index : vout ,
123
- } ;
124
- return assetLockInstantProof ;
125
- }
126
-
127
- async function getAssetLockChainProof ( ) {
128
- let assetLockChainProof = {
129
- // type: CHAIN_ALP,
130
- core_chain_locked_height : nextBlock ,
131
- // out_point: fundingOutPointHex,
132
- out_point : {
133
- txid : outpoint . txid ,
134
- vout : vout ,
135
- } ,
136
- } ;
137
- return assetLockChainProof ;
138
- }
139
-
140
83
let assetLockProof ;
141
84
let weEvenKnowHowToGetIsdlock = true ;
142
85
if ( weEvenKnowHowToGetIsdlock ) {
143
- assetLockProof = await getAssetLockInstantProof ( null ) ;
86
+ assetLockProof = await getAssetLockInstantProof ( txlocksigHex ) ;
144
87
} else {
145
- assetLockProof = await getAssetLockChainProof ( ) ;
88
+ assetLockProof = await getAssetLockChainProof ( txidHex ) ;
146
89
}
147
90
148
91
let identityKeys = await getKnownIdentityKeys (
@@ -175,56 +118,144 @@ async function main() {
175
118
console . log ( `stKeys:` ) ;
176
119
console . log ( stKeys ) ;
177
120
178
- let bcAb = Bincode . encode ( Bincode . StateTransition , stateTransition , {
179
- signable : true ,
180
- } ) ;
181
- console . log ( `bc (ready-to-sign) AB:` , bcAb ) ;
182
- let bc = new Uint8Array ( bcAb ) ;
183
- console . log ( `bc (ready-to-sign):` ) ;
184
- console . log ( DashTx . utils . bytesToHex ( bc ) ) ;
185
- console . log ( bytesToBase64 ( bc ) ) ;
186
-
187
- let ethBytes = await KeyUtils . signEth ( assetInfo . privateKey , bc ) ;
188
- // let sigHex = DashTx.utils.bytesToHex(sigBytes);
189
- Object . assign ( stateTransition , {
190
- identity_id : DashTx . utils . hexToBytes ( identityIdHex ) ,
191
- // signature: sigHex,
192
- signature : ethBytes ,
193
- } ) ;
121
+ let nullSigTransitionAb = Bincode . encode (
122
+ Bincode . StateTransition ,
123
+ stateTransition ,
124
+ {
125
+ signable : true ,
126
+ } ,
127
+ ) ;
128
+ let nullSigTransition = new Uint8Array ( nullSigTransitionAb ) ;
129
+ console . log ( ) ;
130
+ console . log ( `nullSigTransition (ready-to-sign by identity keys):` ) ;
131
+ console . log ( DashTx . utils . bytesToHex ( nullSigTransition ) ) ;
132
+ console . log ( bytesToBase64 ( nullSigTransition ) ) ;
133
+
134
+ let nullSigMagicHash = await KeyUtils . doubleSha256 ( nullSigTransition ) ;
135
+
136
+ {
137
+ let magicSigBytes = await KeyUtils . magicSign ( {
138
+ privKeyBytes : assetInfo . privateKey ,
139
+ doubleSha256Bytes : nullSigMagicHash ,
140
+ } ) ;
141
+
142
+ Object . assign ( stateTransition , {
143
+ identity_id : DashTx . utils . hexToBytes ( identityIdHex ) ,
144
+ signature : magicSigBytes ,
145
+ } ) ;
146
+ }
147
+
194
148
for ( let i = 0 ; i < identityKeys . length ; i += 1 ) {
195
149
let key = identityKeys [ i ] ;
196
150
let stPub = stateTransition . public_keys [ i ] ;
197
- let ethBytes = await KeyUtils . signEth ( key . privateKey , bc ) ;
198
- // let sigHex = DashTx.utils.bytesToHex(sigBytes);
151
+ let magicSigBytes = await KeyUtils . magicSign ( {
152
+ privKeyBytes : key . privateKey ,
153
+ doubleSha256Bytes : nullSigMagicHash ,
154
+ } ) ;
155
+
199
156
Object . assign ( stPub , {
200
- // signature: sigHex,
201
- signature : ethBytes ,
157
+ signature : magicSigBytes ,
202
158
} ) ;
203
159
}
204
160
161
+ console . log ( ) ;
205
162
console . log ( JSON . stringify ( stateTransition , null , 2 ) ) ;
206
163
164
+ let grpcTransition = "" ;
207
165
{
208
- let bcAb = Bincode . encode ( Bincode . StateTransition , stateTransition , {
209
- signable : false ,
210
- } ) ;
211
- let bc = new Uint8Array ( bcAb ) ;
212
- console . log ( `bc (signed):` ) ;
213
- console . log ( DashTx . utils . bytesToHex ( bc ) ) ;
214
- console . log ( bytesToBase64 ( bc ) ) ;
166
+ let fullSigTransitionAb = Bincode . encode (
167
+ Bincode . StateTransition ,
168
+ stateTransition ,
169
+ {
170
+ signable : false ,
171
+ } ,
172
+ ) ;
173
+ let fullSigTransition = new Uint8Array ( fullSigTransitionAb ) ;
174
+ console . log ( ) ;
175
+ console . log ( `transition (fully signed):` ) ;
176
+ console . log ( DashTx . utils . bytesToHex ( fullSigTransition ) ) ;
177
+ grpcTransition = bytesToBase64 ( fullSigTransition ) ;
215
178
}
216
179
217
- // let identityId = assetLockProof.createIdentifier();
218
- // let identity = Dpp.identity.create(identityId, dppKeys);
219
- // let signedTransition = signTransition(
220
- // identity,
221
- // assetLockProof,
222
- // assetLockPrivateKeyBuffer,
223
- // );
224
-
225
180
console . log ( "" ) ;
226
- console . log ( "TODO" ) ;
227
- console . log ( ` - how to serialize and broadcast transition via grpc?` ) ;
181
+ console . log ( `grpcurl -plaintext -d '{
182
+ "stateTransition": "${ grpcTransition } "
183
+ }' seed-1.testnet.networks.dash.org:1443 org.dash.platform.dapi.v0.Platform.broadcastStateTransition` ) ;
184
+ }
185
+
186
+ /** @param {HexString } txlocksigHex */
187
+ async function getAssetLockInstantProof ( txlocksigHex ) {
188
+ {
189
+ let len = txlocksigHex . length / 2 ;
190
+ console . log ( ) ;
191
+ console . log ( `Tx Lock Sig Hex (${ len } ):` ) ;
192
+ console . log ( txlocksigHex ) ;
193
+ }
194
+
195
+ let vout = - 1 ;
196
+ let instantLockTxHex = "" ;
197
+ let instantLockSigHex = "" ;
198
+ {
199
+ let txlocksig = DashTx . parseUnknown ( txlocksigHex ) ;
200
+ vout = 0 ;
201
+ //vout = txlocksig.extraPayload.outputs.findIndex(function (output) {
202
+ // //@ts -expect-error
203
+ // return output.script === "6a00";
204
+ //});
205
+ // console.log(txlocksig.extraPayload.outputs);
206
+ //@ts -expect-error
207
+ instantLockSigHex = txlocksig . sigHashTypeHex ;
208
+ let isLen = instantLockSigHex . length / 2 ;
209
+ let len = txlocksigHex . length / 2 ;
210
+ len -= isLen ;
211
+ instantLockTxHex = txlocksigHex . slice ( 0 , len * 2 ) ;
212
+ console . log ( ) ;
213
+ console . log ( `Tx Hex (${ len } )` ) ;
214
+ console . log ( instantLockTxHex ) ;
215
+ console . log ( ) ;
216
+ console . log ( `Tx Lock Sig Instant Lock Hex (${ isLen } )` ) ;
217
+ //@ts -expect-error
218
+ console . log ( txlocksig . sigHashTypeHex ) ;
219
+ }
220
+
221
+ let assetLockInstantProof = {
222
+ // type: INSTANT_ALP,
223
+ instant_lock : DashTx . utils . hexToBytes ( instantLockSigHex ) ,
224
+ transaction : DashTx . utils . hexToBytes ( instantLockTxHex ) , // TODO this may need the proof, not the signed tx
225
+ // output_index: DashTx.utils.hexToBytes(vout),
226
+ output_index : vout ,
227
+ } ;
228
+ return assetLockInstantProof ;
229
+ }
230
+
231
+ /**
232
+ * @param {HexString } txidHex
233
+ */
234
+ async function getAssetLockChainProof ( txidHex ) {
235
+ let rpcAuthUrl = "https://api:[email protected] " ;
236
+ let getJson = true ;
237
+
238
+ let txInfo = await DashTx . utils . rpc (
239
+ rpcAuthUrl ,
240
+ "getrawtransaction" ,
241
+ txidHex ,
242
+ getJson ,
243
+ ) ;
244
+ //@ts -expect-error
245
+ let vout = txInfo . vout . findIndex ( function ( voutInfo ) {
246
+ return voutInfo . scriptPubKey ?. hex === "6a00" ; // TODO match the burn
247
+ } ) ;
248
+
249
+ let assetLockChainProof = {
250
+ // type: CHAIN_ALP,
251
+ core_chain_locked_height : txInfo . height ,
252
+ // out_point: fundingOutPointHex,
253
+ out_point : {
254
+ txid : DashTx . utils . hexToBytes ( txidHex ) ,
255
+ vout : vout ,
256
+ } ,
257
+ } ;
258
+ return assetLockChainProof ;
228
259
}
229
260
230
261
/**
@@ -387,7 +418,7 @@ main();
387
418
388
419
/** @typedef {String } Base58 */
389
420
/** @typedef {String } Base64 */
390
- /** @typedef {String } Hex */
421
+ /** @typedef {String } HexString */
391
422
/** @typedef {Number } Uint53 */
392
423
/** @typedef {Number } Uint32 */
393
424
/** @typedef {Number } Uint8 */
0 commit comments