Skip to content

Commit 0b34edd

Browse files
committed
wip: serializes transition more correctly
1 parent 205ea9f commit 0b34edd

File tree

1 file changed

+87
-71
lines changed

1 file changed

+87
-71
lines changed

demo-static.js

Lines changed: 87 additions & 71 deletions
Original file line numberDiff line numberDiff line change
@@ -199,11 +199,18 @@ async function main() {
199199
// txDraft.outputs.sort(DashTx.sortOutputs);
200200
let vout = txDraft.outputs.indexOf(burnOutput);
201201

202+
let txProof = DashTx.createRaw(txDraft);
203+
txProof.inputs[0].script =
204+
"76a91488d9931ea73d60eaf7e5671efc0552b912911f2a88ac";
205+
txProof.inputs[0].sequence = "00000000"; // Non-final DashTx.NON_FINAL = "00000000"
206+
//@ts-expect-error
207+
let txProofHex = await DashTx.serialize(txProof, null);
208+
console.log(`txProof:`, txProof);
209+
console.log(txProofHex);
202210
let txSigned = await dashTx.hashAndSignAll(txDraft);
203-
console.log();
204-
console.log(`txSigned:`);
205-
console.log(txSigned);
206-
process.exit(1);
211+
// console.log();
212+
// console.log(`txSigned:`);
213+
// console.log(txSigned);
207214

208215
// let txid = await DashTx.utils.rpc(
209216
// rpcAuthUrl,
@@ -214,26 +221,43 @@ async function main() {
214221
// const INSTANT_ALP = 0;
215222
// const CHAIN_ALP = 1;
216223

217-
let blockchaininfo = await DashTx.utils.rpc(rpcAuthUrl, "getblockchaininfo");
218-
let nextBlock = blockchaininfo.blocks + 1;
224+
// let blockchaininfo = await DashTx.utils.rpc(rpcAuthUrl, "getblockchaininfo");
225+
// let nextBlock = blockchaininfo.blocks + 1;
219226

220227
// TODO - AJ is here
228+
console.log(`DEBUG funding outpoint`);
221229
let outpoint = await getFundingOutPointHex(txSigned.transaction, vout);
230+
console.log(outpoint);
222231
let fundingOutPointHex = `${outpoint.txid}${outpoint.voutHex}`;
223-
let identityId = createIdentityId(fundingOutPointHex);
232+
console.log(fundingOutPointHex);
233+
let identityId = await createIdentityId(fundingOutPointHex);
234+
console.log(identityId);
224235

225236
/** @param {any} magicZmqEmitter */
226237
async function getAssetLockInstantProof(magicZmqEmitter) {
227238
let assetLockInstantProof = {
228239
// type: INSTANT_ALP,
229-
instant_lock: await magicZmqEmitter.once(
230-
"zmqpubrawtxlocksig",
231-
/** @param {any} instantLock */
232-
function (instantLock) {
233-
return instantLock.toBase64();
234-
},
235-
),
236-
transaction: txSigned.transaction,
240+
// ex: 01 v1
241+
// 01 1 input
242+
// 1dbbda5861b12d7523f20aa5e0d42f52de3dcd2d5c2fe919ba67b59f050d206e prev txid
243+
// 00000000 prev vout
244+
// 58c444dd0957767db2c0adea69fd861792bfa75c7e364d83fe85bebebc2a08b4 txid
245+
// 36a56617591a6a89237bada6af1f9b46eba47b5d89a8c4e49ff2d0236182307c cycle hash
246+
// 8967c46529a967b3822e1ba8a173066296d02593f0f59b3a LLMQ BLS Sig
247+
// 78a30a7eef9c8a120847729e62e4a32954339286b79fe759
248+
// 0221331cd28d576887a263f45b595d499272f656c3f51769
249+
// 87c976239cac16f972d796ad82931d532102a4f95eec7d80
250+
// instant_lock: await magicZmqEmitter.once(
251+
// "zmqpubrawtxlocksig",
252+
// /** @param {any} instantLock */
253+
// function (instantLock) {
254+
// return instantLock.toBase64();
255+
// },
256+
// ),
257+
// not sure what "previous outpoint" this refers to, as its not the one in the transaction
258+
instant_lock:
259+
"01011dbbda5861b12d7523f20aa5e0d42f52de3dcd2d5c2fe919ba67b59f050d206e0000000058c444dd0957767db2c0adea69fd861792bfa75c7e364d83fe85bebebc2a08b436a56617591a6a89237bada6af1f9b46eba47b5d89a8c4e49ff2d0236182307c8967c46529a967b3822e1ba8a173066296d02593f0f59b3a78a30a7eef9c8a120847729e62e4a32954339286b79fe7590221331cd28d576887a263f45b595d499272f656c3f5176987c976239cac16f972d796ad82931d532102a4f95eec7d80",
260+
transaction: txProofHex,
237261
output_index: vout,
238262
};
239263
return assetLockInstantProof;
@@ -253,15 +277,19 @@ async function main() {
253277
}
254278

255279
let assetLockProof;
256-
let weEvenKnowHowToGetIsdlock = false;
280+
let weEvenKnowHowToGetIsdlock = true;
257281
if (weEvenKnowHowToGetIsdlock) {
258282
assetLockProof = await getAssetLockInstantProof(null);
259283
} else {
260284
assetLockProof = await getAssetLockChainProof();
261285
}
262286

263-
let idIndex = 0; // increment to first unused
264-
let identityKeys = await getIdentityKeys(walletKey, idIndex);
287+
// let idIndex = 0; // increment to first unused
288+
// let identityKeys = await getIdentityKeys(walletKey, idIndex);
289+
let identityKeys = await getKnownIdentityKeys(
290+
{ privateKey: masterPrivateKey, publicKey: masterPublicKey },
291+
{ privateKey: otherPrivateKey, publicKey: otherPublicKey },
292+
);
265293
let stKeys = await getIdentityTransitionKeys(identityKeys);
266294

267295
// {
@@ -366,9 +394,7 @@ async function main() {
366394
console.log(DashTx.utils.bytesToHex(bc));
367395
console.log(bytesToBase64(bc));
368396

369-
/** @type {Uint8Array} */ //@ts-expect-error
370-
let privBytes = addressKey.privateKey;
371-
let sigBytes = await KeyUtils.sign(privBytes, bc);
397+
let sigBytes = await KeyUtils.sign(assetLockPrivateKey, bc);
372398
// let sigHex = DashTx.utils.bytesToHex(sigBytes);
373399
Object.assign(stateTransition, {
374400
identity_id: identityId,
@@ -436,74 +462,64 @@ function createIdentityId(fundingOutPointHex) {
436462
}
437463

438464
/**
439-
* @param {DashHd.HDKey} walletKey
440-
* @param {Uint53} idIndex
465+
* @param {Required<Pick<DashHd.HDXKey, "privateKey"|"publicKey">>} masterKey
466+
* @param {Required<Pick<DashHd.HDXKey, "privateKey"|"publicKey">>} otherKey
441467
* @returns {Promise<Array<EvoKey>>}
442468
*/
443-
async function getIdentityKeys(walletKey, idIndex) {
444-
let identityEcdsaKey = await DashHd.derivePath(walletKey, identityEcdsaPath);
445-
let identityKey = await DashHd.deriveChild(
446-
identityEcdsaKey,
447-
idIndex,
448-
DashHd.HARDENED,
449-
);
450-
469+
async function getKnownIdentityKeys(masterKey, otherKey) {
470+
if (!masterKey.privateKey) {
471+
throw new Error("linter fail");
472+
}
473+
if (!otherKey.privateKey) {
474+
throw new Error("linter fail");
475+
}
451476
let keyDescs = [
477+
// {"$version":"0","id":0,"purpose":0,"securityLevel":0,"contractBounds":null,"type":0,"readOnly":false,"data":[3,58,154,139,30,76,88,26,25,135,114,76,102,151,19,93,49,192,126,231,172,130,126,106,89,206,192,34,176,77,81,5,95],"disabledAt":null}
452478
{
453479
id: 0,
454480
type: KEY_TYPES.ECDSA_SECP256K1,
455481
purpose: KEY_PURPOSES.AUTHENTICATION,
456-
data: "",
457482
securityLevel: KEY_LEVELS.MASTER,
458-
// readOnly: false,
459-
},
460-
{
461-
id: 1,
462-
type: KEY_TYPES.ECDSA_SECP256K1,
463-
purpose: KEY_PURPOSES.AUTHENTICATION,
483+
readOnly: false,
484+
publicKey: masterKey.publicKey,
485+
privateKey: masterKey.privateKey,
464486
data: "",
465-
securityLevel: KEY_LEVELS.HIGH,
466-
// readOnly: false,
467487
},
488+
// {"$version":"0","id":1,"purpose":0,"securityLevel":1,"contractBounds":null,"type":0,"readOnly":false,"data":[2,1,70,3,1,141,196,55,100,45,218,22,244,199,252,80,228,130,221,35,226,70,128,188,179,165,150,108,59,52,56,72,226],"disabledAt":null}
468489
{
469-
id: 2,
490+
id: 1,
470491
type: KEY_TYPES.ECDSA_SECP256K1,
471492
purpose: KEY_PURPOSES.AUTHENTICATION,
472-
data: "",
473493
securityLevel: KEY_LEVELS.CRITICAL,
474-
// readOnly: false,
475-
},
476-
{
477-
id: 3,
478-
type: KEY_TYPES.ECDSA_SECP256K1,
479-
purpose: KEY_PURPOSES.TRANSFER,
494+
readOnly: false,
495+
privateKey: otherKey.privateKey,
496+
publicKey: otherKey.publicKey,
480497
data: "",
481-
securityLevel: KEY_LEVELS.CRITICAL,
482-
// readOnly: false,
483498
},
484499
];
500+
return keyDescs;
501+
502+
// let privKeyDescs = [];
503+
// for (let keyDesc of keyDescs) {
504+
// let key = await DashHd.deriveChild(
505+
// identityKey,
506+
// keyDesc.id,
507+
// DashHd.HARDENED,
508+
// );
509+
// let privKeyDesc = Object.assign(keyDesc, key);
510+
// privKeyDescs.push(privKeyDesc); // for type info
511+
512+
// let dppKey = new WasmDpp.IdentityPublicKey(L2_VERSION_PLATFORM);
513+
// dppKey.setId(keyDesc.id);
514+
// dppKey.setData(key.publicKey);
515+
// if (keyDesc.purpose) {
516+
// dppKey.setPurpose(keyDesc.purpose);
517+
// }
518+
// dppKey.setSecurityLevel(keyDesc.securityLevel);
519+
// dppKeys.push(dppKey);
520+
// }
485521

486-
let privKeyDescs = [];
487-
for (let keyDesc of keyDescs) {
488-
let key = await DashHd.deriveChild(
489-
identityKey,
490-
keyDesc.id,
491-
DashHd.HARDENED,
492-
);
493-
let privKeyDesc = Object.assign(keyDesc, key);
494-
privKeyDescs.push(privKeyDesc); // for type info
495-
496-
// let dppKey = new WasmDpp.IdentityPublicKey(L2_VERSION_PLATFORM);
497-
// dppKey.setId(keyDesc.id);
498-
// dppKey.setData(key.publicKey);
499-
// if (keyDesc.purpose) {
500-
// dppKey.setPurpose(keyDesc.purpose);
501-
// }
502-
// dppKey.setSecurityLevel(keyDesc.securityLevel);
503-
// dppKeys.push(dppKey);
504-
}
505-
506-
return privKeyDescs;
522+
// return privKeyDescs;
507523
}
508524

509525
/**

0 commit comments

Comments
 (0)