Skip to content

Commit 94206a9

Browse files
committed
Playing with Vite + gRPC
1 parent 7ff4c1d commit 94206a9

File tree

105 files changed

+70639
-2583
lines changed

Some content is hidden

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

105 files changed

+70639
-2583
lines changed

1-create-asset-lock.js

Lines changed: 19 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,18 @@
11
import Fs from "node:fs/promises";
22

33
import DashHd from "dashhd";
4-
import * as DashHdUtils from "./dashhd-utils.js";
4+
import * as DashHdUtils from "./src/dashhd-utils.js";
55
import DashKeys from "dashkeys";
6-
import * as DashTx from "dashtx/dashtx.js";
7-
import * as DashPlatform from "./dashplatform.js";
8-
import * as QRCode from "./_qr.js";
9-
import * as KeyUtils from "./key-utils.js";
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";
1010

1111
import { createIdentityFromAssetLock } from "./2-create-identity-transition.js";
1212

13-
import { loadWallet } from "./cli.js"
14-
import { deriveAllCreateIdentityKeys } from "./asset_lock.js"
15-
import { createPlatformAssetLock } from "./asset_lock.js"
13+
import { loadWallet } from "./src/cli.js"
14+
import { deriveAllCreateIdentityKeys } from "./src/asset_lock.js"
15+
import { createPlatformAssetLock } from "./src/asset_lock.js"
1616
// let DapiGrpc = require("@dashevo/dapi-grpc");
1717
// let WasmDpp = require("@dashevo/wasm-dpp");
1818
// let Dpp = WasmDpp.DashPlatformProtocol;
@@ -50,39 +50,32 @@ async function main() {
5050

5151
console.log("Asset WIF", assetWif, "(would be ephemeral, non-hd)");
5252

53+
console.log('regFundKey', await DashHd.toAddr(regFundKey.publicKey, {version: 'testnet'}));
54+
console.log('topupKey', await DashHd.toAddr(topupKey.publicKey, {version: 'testnet'}));
55+
console.log('assetKey', await DashHd.toAddr(assetKey.publicKey, {version: 'testnet'}));
56+
console.log('masterKey', await DashHd.toAddr(masterKey.publicKey, {version: 'testnet'}));
57+
console.log('otherKey', await DashHd.toAddr(otherKey.publicKey, {version: 'testnet'}));
58+
console.log();
59+
5360
let { identityIdHex, txidHex, assetProof } = await createPlatformAssetLock(
5461
hdOpts,
5562
regFundKey,
5663
topupKey, // TODO next change key from wallet
5764
assetInfo,
5865
);
5966

60-
let txlocksigHex;
61-
let txCore;
62-
if (assetProof.data.raw) {
63-
txlocksigHex = assetProof.data.raw;
64-
} else if (assetProof.data.vin) {
65-
txCore = assetProof.data;
66-
} else {
67-
console.log(`DEBUG assetProof`);
68-
console.log(assetProof);
69-
throw new Error("internal error: no acceptable asset proof");
70-
}
71-
7267
console.log();
7368
console.log(`txidHex: `, txidHex);
7469
console.log(`identityIdHex:`, identityIdHex);
75-
console.log(`txlocksigHex:`, txlocksigHex);
76-
console.log(`txCore:`, txCore);
70+
console.log(`assetProof:`, assetProof);
7771

78-
await Fs.writeFile('ready-to-thingy-dostuff.json', JSON.stringify({
72+
await Fs.writeFile('ready-to-create-identity.json', JSON.stringify({
7973
assetKey,
8074
masterKey,
8175
otherKey,
8276
identityIdHex,
8377
txidHex,
84-
txlocksigHex,
85-
txCore,
78+
assetProof,
8679
}, (key, val) => {
8780
if (val instanceof Uint8Array || val instanceof ArrayBuffer) {
8881
return {'@Uint8Array hex': DashTx.utils.bytesToHex(new Uint8Array(val))}
@@ -96,8 +89,7 @@ async function main() {
9689
otherKey,
9790
identityIdHex,
9891
txidHex,
99-
txlocksigHex,
100-
txCore,
92+
assetProof,
10193
);
10294
// walletKey, coinType, identityIndex
10395
}

1.8.1/generated_bincode.d.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import { BinCode, BinCodeable, VARIANTS } from "../bincode.ts";
2-
import { Option, FixedBytes, Hash, SocketAddr, Transaction } from "../bincode_types.ts";
1+
import { BinCode, BinCodeable, VARIANTS } from "../src/bincode.ts";
2+
import { Option, FixedBytes, Hash, SocketAddr, Transaction } from "../src/bincode_types.ts";
33
declare module "./generated_bincode.js" {
44

55
/**

1.8.1/generated_bincode.js

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

1010
/** @type {*} */

2-create-identity-transition.js

Lines changed: 5 additions & 81 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,15 @@
11

22
// import DashKeys from "dashkeys";
3-
import * as DashTx from "dashtx/dashtx.js";
3+
import * as DashTx from "dashtx";
44

5-
import * as Bincode from "./bincode.ts";
5+
import * as Bincode from "./src/bincode.ts";
66
import * as DashBincode from "./1.8.1/generated_bincode.js";
7-
import * as KeyUtils from "./key-utils.js";
7+
import * as KeyUtils from "./src/key-utils.js";
88
import baseX from "base-x";
99

1010
const BASE58 = `123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz`;
1111
let base58 = baseX(BASE58);
1212

13-
let Thingy = {};
14-
1513
/**
1614
* @typedef AssetLockChainProof
1715
* @prop {Number} core_chain_locked_height
@@ -26,29 +24,19 @@ let Thingy = {};
2624
* @param {import('dashhd').HDWallet} otherKey
2725
* @param {String} identityIdHex
2826
* @param {String} txidHex
29-
* @param {String} [txlocksigHex]
30-
* @param {import('dashtx').TxInfo} [txCore]
27+
* @param {DashBincode.AssetLockProof} [assetProof]
3128
*/
3229
export async function createIdentityFromAssetLock(
3330
assetKey,
3431
masterKey,
3532
otherKey,
3633
identityIdHex,
3734
txidHex,
38-
txlocksigHex,
39-
txCore,
35+
assetLockProof,
4036
) {
4137
// const INSTANT_ALP = 0;
4238
// const CHAIN_ALP = 1;
4339

44-
/** @type {DashBincode.AssetLockProof} */
45-
let assetLockProof;
46-
if (txlocksigHex) {
47-
assetLockProof = await makeAssetLockInstantProof(txlocksigHex);
48-
} else {
49-
assetLockProof = await makeAssetLockChainProof(txidHex, txCore);
50-
}
51-
5240
if (!masterKey.privateKey) {
5341
throw new Error("'masterKey' is missing 'privateKey'");
5442
}
@@ -171,70 +159,6 @@ export async function createIdentityFromAssetLock(
171159
);
172160
};
173161

174-
/** @param {HexString} txlocksigHex */
175-
async function makeAssetLockInstantProof(txlocksigHex) {
176-
{
177-
let len = txlocksigHex.length / 2;
178-
console.log();
179-
console.log(`Tx Lock Sig Hex (${len}):`);
180-
console.log(txlocksigHex);
181-
}
182-
183-
let vout = -1;
184-
let instantLockTxHex = "";
185-
let instantLockSigHex = "";
186-
{
187-
let txlocksig = DashTx.parseUnknown(txlocksigHex);
188-
vout = 0;
189-
//vout = txlocksig.extraPayload.outputs.findIndex(function (output) {
190-
// //@ts-expect-error
191-
// return output.script === "6a00";
192-
//});
193-
// console.log(txlocksig.extraPayload.outputs);
194-
//@ts-expect-error
195-
instantLockSigHex = txlocksig.sigHashTypeHex;
196-
let isLen = instantLockSigHex.length / 2;
197-
let len = txlocksigHex.length / 2;
198-
len -= isLen;
199-
instantLockTxHex = txlocksigHex.slice(0, len * 2);
200-
console.log();
201-
console.log(`Tx Hex (${len})`);
202-
console.log(instantLockTxHex);
203-
console.log();
204-
console.log(`Tx Lock Sig Instant Lock Hex (${isLen})`);
205-
//@ts-expect-error
206-
console.log(txlocksig.sigHashTypeHex);
207-
}
208-
209-
let assetLockInstantProof = DashBincode.RawInstantLockProof({
210-
instant_lock: DashBincode.BinaryData(DashTx.utils.hexToBytes(instantLockSigHex)),
211-
transaction: DashBincode.BinaryData(DashTx.utils.hexToBytes(instantLockTxHex)), // TODO this may need the proof, not the signed tx
212-
output_index: vout,
213-
});
214-
return DashBincode.AssetLockProof.Instant(assetLockInstantProof);
215-
}
216-
217-
/**
218-
* @param {HexString} txidHex
219-
* @param {any} txInfo - TODO CoreTx
220-
*/
221-
async function makeAssetLockChainProof(txidHex, txInfo) {
222-
//@ts-expect-error
223-
let vout = txInfo.vout.findIndex(voutInfo =>
224-
voutInfo.scriptPubKey?.hex === "6a00" // TODO match the burn
225-
);
226-
227-
let assetLockChainProof = DashBincode.ChainAssetLockProof({
228-
core_chain_locked_height: txInfo.height,
229-
out_point: {
230-
txid: DashBincode.Txid(DashTx.utils.hexToBytes(txidHex)),
231-
vout: vout,
232-
},
233-
});
234-
235-
return DashBincode.AssetLockProof.Chain(assetLockChainProof);
236-
}
237-
238162
/**
239163
* @param {Required<Pick<import('dashhd').HDXKey, "privateKey"|"publicKey">>} masterKey
240164
* @param {Required<Pick<import('dashhd').HDXKey, "privateKey"|"publicKey">>} otherKey

2.0.0/generated_bincode.d.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import { BinCode, BinCodeable, VARIANTS } from "../bincode.ts";
2-
import { Option, FixedBytes, Hash, SocketAddr, Transaction } from "../bincode_types.ts";
1+
import { BinCode, BinCodeable, VARIANTS } from "../src/bincode.ts";
2+
import { Option, FixedBytes, Hash, SocketAddr, Transaction } from "../src/bincode_types.ts";
33
declare module "./generated_bincode.js" {
44

55
/**

0 commit comments

Comments
 (0)