1
- import Fs from "node:fs/promises" ;
2
1
3
2
// import DashKeys from "dashkeys";
4
3
import * as DashTx from "dashtx/dashtx.js" ;
@@ -8,40 +7,6 @@ import * as DashBincode from "./1.8.1/generated_bincode.js";
8
7
import * as KeyUtils from "./key-utils.js" ;
9
8
import baseX from "base-x" ;
10
9
11
- const ST_CREATE_IDENTITY = 2 ;
12
- const L2_VERSION_PLATFORM = 1 ; // actually constant "0" ??
13
-
14
- let KEY_LEVELS = {
15
- 0 : "MASTER" ,
16
- 1 : "CRITICAL" ,
17
- 2 : "HIGH" ,
18
- 3 : "MEDIUM" ,
19
- MASTER : 0 ,
20
- CRITICAL : 1 ,
21
- HIGH : 2 ,
22
- MEDIUM : 3 ,
23
- } ;
24
-
25
- let KEY_PURPOSES = {
26
- 0 : "AUTHENTICATION" ,
27
- 1 : "ENCRYPTION" ,
28
- 2 : "DECRYPTION" ,
29
- 3 : "TRANSFER" ,
30
- 4 : "SYSTEM" ,
31
- 5 : "VOTING" ,
32
- AUTHENTICATION : 0 ,
33
- ENCRYPTION : 1 ,
34
- DECRYPTION : 2 ,
35
- TRANSFER : 3 ,
36
- SYSTEM : 4 ,
37
- VOTING : 5 ,
38
- } ;
39
-
40
- let KEY_TYPES = {
41
- 0 : "ECDSA_SECP256K1" ,
42
- ECDSA_SECP256K1 : 0 ,
43
- } ;
44
-
45
10
const BASE58 = `123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz` ;
46
11
let base58 = baseX ( BASE58 ) ;
47
12
@@ -64,7 +29,7 @@ let Thingy = {};
64
29
* @param {String } [txlocksigHex]
65
30
* @param {import('dashtx').TxInfo } [txCore]
66
31
*/
67
- Thingy . doStuff = async function (
32
+ export async function createIdentityFromAssetLock (
68
33
assetKey ,
69
34
masterKey ,
70
35
otherKey ,
@@ -79,9 +44,9 @@ Thingy.doStuff = async function (
79
44
/** @type {DashBincode.AssetLockProof } */
80
45
let assetLockProof ;
81
46
if ( txlocksigHex ) {
82
- assetLockProof = await getAssetLockInstantProof ( txlocksigHex ) ;
47
+ assetLockProof = await makeAssetLockInstantProof ( txlocksigHex ) ;
83
48
} else {
84
- assetLockProof = await getAssetLockChainProof ( txidHex , txCore ) ;
49
+ assetLockProof = await makeAssetLockChainProof ( txidHex , txCore ) ;
85
50
}
86
51
87
52
if ( ! masterKey . privateKey ) {
@@ -206,10 +171,8 @@ Thingy.doStuff = async function (
206
171
) ;
207
172
} ;
208
173
209
- export default Thingy ;
210
-
211
174
/** @param {HexString } txlocksigHex */
212
- async function getAssetLockInstantProof ( txlocksigHex ) {
175
+ async function makeAssetLockInstantProof ( txlocksigHex ) {
213
176
{
214
177
let len = txlocksigHex . length / 2 ;
215
178
console . log ( ) ;
@@ -255,7 +218,7 @@ async function getAssetLockInstantProof(txlocksigHex) {
255
218
* @param {HexString } txidHex
256
219
* @param {any } txInfo - TODO CoreTx
257
220
*/
258
- async function getAssetLockChainProof ( txidHex , txInfo ) {
221
+ async function makeAssetLockChainProof ( txidHex , txInfo ) {
259
222
//@ts -expect-error
260
223
let vout = txInfo . vout . findIndex ( voutInfo =>
261
224
voutInfo . scriptPubKey ?. hex === "6a00" // TODO match the burn
@@ -339,16 +302,18 @@ async function getKnownIdentityKeys(masterKey, otherKey) {
339
302
function getIdentityTransitionKeys ( identityKeys ) {
340
303
let stKeys = [ ] ;
341
304
for ( let key of identityKeys ) {
342
- let stKey = DashBincode . IdentityPublicKeyInCreation . V0 ( DashBincode . IdentityPublicKeyInCreationV0 ( {
343
- id : key . id ,
344
- key_type : key . type ,
345
- purpose : key . purpose ,
346
- security_level : key . securityLevel ,
347
- contract_bounds : undefined ,
348
- read_only : key . readOnly || false ,
349
- data : DashBincode . BinaryData ( key . publicKey ) ,
350
- signature : DashBincode . BinaryData ( new Uint8Array ) ,
351
- } ) ) ;
305
+ let stKey = DashBincode . IdentityPublicKeyInCreation . V0 (
306
+ DashBincode . IdentityPublicKeyInCreationV0 ( {
307
+ id : key . id ,
308
+ key_type : key . type ,
309
+ purpose : key . purpose ,
310
+ security_level : key . securityLevel ,
311
+ contract_bounds : undefined ,
312
+ read_only : key . readOnly || false ,
313
+ data : DashBincode . BinaryData ( key . publicKey ) ,
314
+ signature : DashBincode . BinaryData ( new Uint8Array ) ,
315
+ } )
316
+ ) ;
352
317
stKeys . push ( stKey ) ;
353
318
}
354
319
return stKeys ;
@@ -362,34 +327,6 @@ function bytesToBase64(bytes) {
362
327
return btoa ( String . fromCharCode . apply ( null , bytes ) ) ;
363
328
}
364
329
365
- /**
366
- * Reads a hex file as text, stripping comments (anything including and after a non-hex character), removing whitespace, and joining as a single string
367
- * @param {String } path
368
- */
369
- async function readHex ( path ) {
370
- let text = await Fs . readFile ( path , "utf8" ) ;
371
- let lines = text . split ( "\n" ) ;
372
- let hexes = [ ] ;
373
- for ( let line of lines ) {
374
- line = line . replace ( / \s / g, "" ) ;
375
- line = line . replace ( / [ ^ 0 - 9 a - f ] .* / i, "" ) ;
376
- hexes . push ( line ) ;
377
- }
378
-
379
- let hex = hexes . join ( "" ) ;
380
- return hex ;
381
- }
382
-
383
- /**
384
- * @param {String } path
385
- */
386
- async function readWif ( path ) {
387
- let wif = await Fs . readFile ( path , "utf8" ) ;
388
- wif = wif . trim ( ) ;
389
-
390
- return wif ;
391
- }
392
-
393
330
/** @typedef {String } Base58 */
394
331
/** @typedef {String } Base64 */
395
332
/** @typedef {String } HexString */
0 commit comments