Skip to content

Commit 1104dc0

Browse files
committed
wip: serialized with signature
1 parent 5056d7b commit 1104dc0

File tree

2 files changed

+30
-11
lines changed

2 files changed

+30
-11
lines changed

bincode.js

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ export function Struct(name, inner) {
137137
name,
138138
encode(bc, val) {
139139
for (const innerKey in inner) {
140-
console.log(`DEBUG`, name);
140+
console.log(`DEBUG Struct ${name}:`, innerKey);
141141
// const startIdx = bc.idx;
142142
inner[innerKey].encode(bc, val[innerKey]);
143143
// console.log('DEBUG:', 'encode', name + '.' + innerKey, '=', val[innerKey], 'at', startIdx, toHex(bc.dataview.buffer.slice(startIdx, bc.idx)));
@@ -524,7 +524,7 @@ export function FixedBytes(length) {
524524
encode(bc, val) {
525525
let idx = bc._idxThenAddExtend(length);
526526
let bytes = new Uint8Array(bc.dataview.buffer);
527-
console.log(`DEBUG val, idx`, val, idx);
527+
console.log(`DEBUG val, idx`, val, idx);
528528
bytes.set(val, idx);
529529
},
530530
decode(bc) {
@@ -543,10 +543,15 @@ export function NotSignable(inner) {
543543
return {
544544
name: "NotSignable<" + inner.name + ">",
545545
encode(bc, value) {
546-
if (!bc.options.signable) inner.encode(bc, value);
546+
console.log(`DEBUG NotSignable<${inner.name}>`, bc, value);
547+
if (!bc.options.signable) {
548+
inner.encode(bc, value);
549+
}
547550
},
548551
decode(bc) {
549-
if (!bc.options.signable) return inner.decode(bc);
552+
if (!bc.options.signable) {
553+
return inner.decode(bc);
554+
}
550555
},
551556
};
552557
}

demo.js

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -335,29 +335,42 @@ async function main() {
335335
signable: true,
336336
});
337337
let bc = new Uint8Array(bcAb);
338-
console.log(`bc:`);
338+
console.log(`bc (ready-to-sign):`);
339339
console.log(DashTx.utils.bytesToHex(bc));
340340
console.log(bytesToBase64(bc));
341341

342342
/** @type {Uint8Array} */ //@ts-expect-error
343343
let privBytes = addressKey.privateKey;
344344
let sigBytes = await KeyUtils.sign(privBytes, bc);
345-
let sigHex = DashTx.utils.bytesToHex(sigBytes);
345+
// let sigHex = DashTx.utils.bytesToHex(sigBytes);
346346
Object.assign(stateTransition, {
347-
signature: sigHex,
347+
identity_id: identityId,
348+
// signature: sigHex,
349+
signature: sigBytes,
348350
});
349351
for (let i = 0; i < identityKeys.length; i += 1) {
350352
let key = identityKeys[i];
351353
let stPub = stateTransition.public_keys[i];
352354
let sigBytes = await KeyUtils.sign(key.privateKey, bc);
353-
let sigHex = DashTx.utils.bytesToHex(sigBytes);
355+
// let sigHex = DashTx.utils.bytesToHex(sigBytes);
354356
Object.assign(stPub, {
355-
signature: sigHex,
357+
// signature: sigHex,
358+
signature: sigBytes,
356359
});
357360
}
358361

359362
console.log(JSON.stringify(stateTransition, null, 2));
360363

364+
{
365+
let bcAb = Bincode.encode(Bincode.StateTransition, stateTransition, {
366+
signable: false,
367+
});
368+
let bc = new Uint8Array(bcAb);
369+
console.log(`bc (signed):`);
370+
console.log(DashTx.utils.bytesToHex(bc));
371+
console.log(bytesToBase64(bc));
372+
}
373+
361374
// let identityId = assetLockProof.createIdentifier();
362375
// let identity = Dpp.identity.create(identityId, dppKeys);
363376
// let signedTransition = signTransition(
@@ -390,8 +403,9 @@ async function getFundingOutPointHex(txSignedHex, outputIndex) {
390403
function createIdentityId(fundingOutPointHex) {
391404
let fundingOutPointBytes = DashTx.utils.hexToBytes(fundingOutPointHex);
392405
let identityHashBytes = DashTx.doubleSha256(fundingOutPointBytes);
393-
let identityId = b58.encode(identityHashBytes);
394-
return identityId;
406+
// let identityId = b58.encode(identityHashBytes);
407+
// return identityId;
408+
return identityHashBytes;
395409
}
396410

397411
/**

0 commit comments

Comments
 (0)