Skip to content

Commit 3f28912

Browse files
committed
Data Contract Create is working
1 parent 94206a9 commit 3f28912

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

44 files changed

+9088
-2262
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,5 +129,6 @@ dist
129129
.yarn/install-state.gz
130130
.pnp.*
131131

132+
.DS_Store
132133
tools/bincode_generator/target
133134
rust_print_encoded/target

1-create-asset-lock.js

Lines changed: 0 additions & 97 deletions
This file was deleted.

1-create-asset-lock.ts

Lines changed: 138 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,138 @@
1+
import Fs from "node:fs/promises";
2+
3+
import DashHd from "dashhd";
4+
import * as DashHdUtils from "./src/dashhd-utils.ts";
5+
import DashKeys from "dashkeys";
6+
import * as DashTx from "dashtx";
7+
import * as DashPlatform from "./src/dashplatform.js";
8+
import * as QRCode from "./src/_qr.js";
9+
import * as KeyUtils from "./src/key-utils.js";
10+
11+
import {
12+
createIdentityFromAssetLock,
13+
} from "./2-create-identity-transition.ts";
14+
15+
import { loadWallet } from "./src/cli.ts";
16+
import { deriveAllCreateIdentityKeys } from "./src/asset_lock.ts";
17+
import { createPlatformAssetLock } from "./src/asset_lock.ts";
18+
import { connectToNode, TRPC } from "./src/rpc.ts"
19+
import { NODE_ADDRESS, RPC_AUTH_URL } from "./src/constants.ts"
20+
import { fromHex, toHex } from "./src/hex.js"
21+
import * as BinCode from "./src/bincode.ts"
22+
import * as DashBincode from "./2.0.0/generated_bincode.js"
23+
import { base58 } from "./src/util/base58.ts"
24+
import { findExistingIdentity } from "./src/identity.ts"
25+
26+
async function main(): Promise<void> {
27+
const rpc = new TRPC(RPC_AUTH_URL);
28+
const nodeRpc = connectToNode(NODE_ADDRESS)
29+
30+
const walletKey = await loadWallet();
31+
32+
const identityIndex = parseInt(process.argv[2], 10);
33+
if (isNaN(identityIndex)) {
34+
console.error("");
35+
console.error("USAGE");
36+
console.error(` ${process.argv[0]} ${process.argv[1]} <identity-index>`);
37+
console.error("");
38+
console.error("EXAMPLE");
39+
console.error(` ${process.argv[0]} ${process.argv[1]} 0`);
40+
console.error("");
41+
process.exit(1);
42+
}
43+
44+
const hdOpts = { version: "testnet" as const }; // TODO
45+
46+
const {
47+
regFundKey,
48+
changeKey,
49+
assetKey,
50+
masterKey,
51+
otherKey,
52+
} = await deriveAllCreateIdentityKeys(
53+
hdOpts,
54+
walletKey,
55+
identityIndex,
56+
);
57+
58+
// console.log("Asset WIF", assetWif, "(would be ephemeral, non-hd)");
59+
60+
console.log(
61+
"regFundKey",
62+
await DashHd.toAddr(regFundKey.publicKey, { version: "testnet" }),
63+
);
64+
console.log(
65+
"changeKey",
66+
await DashHd.toAddr(changeKey.publicKey, { version: "testnet" }),
67+
);
68+
console.log(
69+
"assetKey",
70+
await DashHd.toAddr(assetKey.publicKey, { version: "testnet" }),
71+
);
72+
console.log(
73+
"masterKey",
74+
await DashHd.toAddr(masterKey.publicKey, { version: "testnet" }),
75+
);
76+
console.log(
77+
"masterKey priv wif",
78+
await DashHd.toWif(masterKey.privateKey!, { version: "testnet" }),
79+
);
80+
console.log(
81+
"otherKey",
82+
await DashHd.toAddr(otherKey.publicKey, { version: "testnet" }),
83+
);
84+
console.log();
85+
86+
const pkh = await DashKeys.pubkeyToPkh(masterKey.publicKey)
87+
console.log('masterKey pkh', toHex(pkh))
88+
89+
const existingIdentityId = await findExistingIdentity(nodeRpc, pkh)
90+
if (existingIdentityId) {
91+
console.log('Identity Already Created!', base58.encode(existingIdentityId))
92+
process.exit(1);
93+
}
94+
95+
const {
96+
identityId,
97+
txidHex,
98+
assetProof,
99+
} = await createPlatformAssetLock(hdOpts, regFundKey, changeKey, assetKey, rpc);
100+
101+
console.log();
102+
console.log(`txidHex: `, txidHex);
103+
console.log(`identityId:`, base58.encode(identityId));
104+
console.log(`assetProof:`, assetProof);
105+
106+
await Fs.writeFile(
107+
"ready-to-create-identity.json",
108+
JSON.stringify(
109+
{
110+
assetKey,
111+
masterKey,
112+
otherKey,
113+
identityId: toHex(identityId),
114+
txidHex,
115+
assetProof,
116+
},
117+
(key, val) => {
118+
if (val instanceof Uint8Array || val instanceof ArrayBuffer) {
119+
return {
120+
"@Uint8Array hex": DashTx.utils.bytesToHex(new Uint8Array(val)),
121+
};
122+
}
123+
return val;
124+
},
125+
2,
126+
),
127+
);
128+
129+
await createIdentityFromAssetLock(
130+
assetKey,
131+
masterKey,
132+
otherKey,
133+
identityId,
134+
assetProof,
135+
);
136+
}
137+
138+
main();

1.8.1/generated_bincode.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import {
33
Int128, Int16, Int32, Int64, Int8, Uint128, Uint16, Uint32, Uint64, Uint8, Float64,
44
VarInt, VarUint, Vec, Tuple, Map, Option, String, Nothing, Range, NotSignable,
55
SocketAddr, DISCRIMINANT, VARIANT, ENUM,
6-
} from "../src/bincode.js"
6+
} from "../src/bincode.ts"
77
import { Transaction } from "../src/bincode_types.ts";
88
export const Hash = Bytes; //FixedBytes(32)
99

0 commit comments

Comments
 (0)