@@ -5,6 +5,8 @@ import * as KeyUtils from "./src/key-utils.js";
5
5
import base64 from "base64-js" ;
6
6
import { base58 } from "./src/util/base58.ts" ;
7
7
import type { HDKey } from "dashhd"
8
+ import { connectToNode } from "./src/rpc.ts"
9
+ import { NODE_ADDRESS } from "./src/constants.ts"
8
10
9
11
export interface AssetLockChainProof {
10
12
core_chain_locked_height : number ;
@@ -41,7 +43,7 @@ export interface STKey {
41
43
readOnly : boolean ;
42
44
}
43
45
44
- // --- Main Function ---
46
+ const nodeRpc = connectToNode ( NODE_ADDRESS ) ;
45
47
46
48
/**
47
49
*
@@ -87,25 +89,18 @@ export async function createIdentityFromAssetLock(
87
89
console . log ( `stKeys:` ) ;
88
90
console . log ( stKeys ) ;
89
91
90
- const nullSigTransition = new Uint8Array (
92
+ const signableTransition = new Uint8Array (
91
93
Bincode . encode ( DashBincode . StateTransition , stateTransition , {
92
94
signable : true ,
93
95
} ) ,
94
96
) ;
95
- console . log ( ) ;
96
- console . log ( `nullSigTransition (ready-to-sign by identity keys):` ) ;
97
- console . log ( "(hex)" , DashTx . utils . bytesToHex ( nullSigTransition ) ) ;
98
- console . log ( "(base64)" , base64 . fromByteArray ( nullSigTransition ) ) ;
99
97
100
- const nullSigMagicHash = await KeyUtils . doubleSha256 ( nullSigTransition ) ;
98
+ const signableTransitionHash = await KeyUtils . doubleSha256 ( signableTransition ) ;
101
99
102
- if ( ! assetKey . privateKey ) {
103
- throw new Error ( "'assetKey' is missing 'privateKey'" ) ;
104
- }
105
100
{
106
101
const magicSigBytes = await KeyUtils . magicSign ( {
107
- privKeyBytes : assetKey . privateKey ,
108
- doubleSha256Bytes : nullSigMagicHash ,
102
+ privKeyBytes : assetKey . privateKey ! ,
103
+ doubleSha256Bytes : signableTransitionHash ,
109
104
} ) ;
110
105
111
106
identityCreate . signature [ 0 ] = magicSigBytes ;
@@ -116,7 +111,7 @@ export async function createIdentityFromAssetLock(
116
111
const stPub = identityCreate . public_keys [ i ] ;
117
112
const magicSigBytes = await KeyUtils . magicSign ( {
118
113
privKeyBytes : key . privateKey ,
119
- doubleSha256Bytes : nullSigMagicHash ,
114
+ doubleSha256Bytes : signableTransitionHash ,
120
115
} ) ;
121
116
122
117
Bincode . match ( stPub , {
@@ -144,25 +139,31 @@ export async function createIdentityFromAssetLock(
144
139
145
140
let grpcTransition = "" ;
146
141
let transitionHashHex = "" ;
147
- {
148
- const fullSigTransition = new Uint8Array (
149
- Bincode . encode ( DashBincode . StateTransition , stateTransition , {
150
- signable : false ,
151
- } ) ,
152
- ) ;
153
- console . log ( ) ;
154
- console . log ( `transition (fully signed):` ) ;
155
- console . log ( DashTx . utils . bytesToHex ( fullSigTransition ) ) ;
156
- const transitionHash = await KeyUtils . sha256 ( fullSigTransition ) ;
157
- transitionHashHex = DashTx . utils . bytesToHex ( transitionHash ) ;
158
- grpcTransition = base64 . fromByteArray ( fullSigTransition ) ;
142
+
143
+ const fullSigTransition = new Uint8Array (
144
+ Bincode . encode ( DashBincode . StateTransition , stateTransition , {
145
+ signable : false ,
146
+ } ) ,
147
+ ) ;
148
+ console . log ( ) ;
149
+ console . log ( `transition (fully signed):` ) ;
150
+ console . log ( DashTx . utils . bytesToHex ( fullSigTransition ) ) ;
151
+ const transitionHash = await KeyUtils . sha256 ( fullSigTransition ) ;
152
+ transitionHashHex = DashTx . utils . bytesToHex ( transitionHash ) ;
153
+ grpcTransition = base64 . fromByteArray ( fullSigTransition ) ;
154
+
155
+
156
+
157
+ console . log ( "Broadcasting Identity Create Transition..." )
158
+ try {
159
+ const response = await nodeRpc . platform . broadcastStateTransition ( {
160
+ stateTransition : fullSigTransition ,
161
+ } )
162
+ console . log ( 'response' , response ) ;
163
+ } catch ( e ) {
164
+ console . error ( "Error: " , decodeURIComponent ( ( e as any ) . message ) )
159
165
}
160
166
161
- console . log ( ) ;
162
- console . log ( ) ;
163
- console . log ( `grpcurl -plaintext -d '{
164
- "stateTransition": "${ grpcTransition } "
165
- }' seed-2.testnet.networks.dash.org:1443 org.dash.platform.dapi.v0.Platform.broadcastStateTransition` ) ;
166
167
console . log ( ) ;
167
168
const identity = base58 . encode ( identityId ) ;
168
169
console . log ( `https://testnet.platform-explorer.com/identity/${ identity } ` ) ;
0 commit comments