Skip to content

Commit

Permalink
Update SignMultisigTransaction flow to Albatross PoS SDK
Browse files Browse the repository at this point in the history
  • Loading branch information
sisou committed Jan 15, 2025
1 parent 96a73b1 commit 98d7997
Show file tree
Hide file tree
Showing 24 changed files with 177 additions and 782 deletions.
14 changes: 6 additions & 8 deletions client/src/PublicRequest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -198,16 +198,14 @@ export type EncryptionKeyParams = {

export type MultisigConfig = {
publicKeys: Uint8Array[],
numberOfSigners: number,
signerPublicKeys: Uint8Array[],
secret: {
aggregatedSecret: Uint8Array,
} | {
encryptedSecrets: Uint8Array[],
bScalar: Uint8Array,
signers: Array<{
publicKey: Uint8Array,
commitments: Uint8Array[],
}>,
secrets: Uint8Array[] | {
encrypted: Uint8Array[],
keyParams: EncryptionKeyParams,
},
aggregatedCommitment: Uint8Array,
userName?: string,
};

Expand Down
4 changes: 2 additions & 2 deletions demos/RSAKeys.html
Original file line number Diff line number Diff line change
Expand Up @@ -109,9 +109,9 @@ <h1>RSA Keys</h1>

// Extend 32-byte entropy into 1024-byte seed
const entropyBuffer = Nimiq.BufferUtils.fromHex($entropy.value);
const seed = Nimiq.BufferUtils.toAscii(Nimiq.CryptoUtils.computePBKDF2sha512(
const seed = Nimiq.BufferUtils.toUtf8(Nimiq.CryptoUtils.computePBKDF2sha512(
entropyBuffer,
Nimiq.PublicKey.derive(Nimiq.PrivateKey.unserialize(entropyBuffer)).toAddress().serialize(),
Nimiq.PublicKey.derive(Nimiq.PrivateKey.deserialize(entropyBuffer)).toAddress().serialize(),
1024, // Iterations
1024, // Output size
));
Expand Down
3 changes: 1 addition & 2 deletions demos/SignMultisigTransaction.html
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
<script src="../src/lib/Key.js"></script>
<script src="../src/lib/KeyStore.js"></script>
<script src="../src/lib/multisig/MerkleTreePatch.js"></script>
<script src="../src/lib/multisig/MultisigUtils.js"></script>
<script src="../node_modules/@nimiq/rpc/dist/rpc.umd.js"></script>

<style>
Expand Down Expand Up @@ -175,7 +174,7 @@
keyLabel: 'Demo Account',

// Transaction information
sender: MultisigUtils.calculateAddress(publicKeys, numberOfSigners).serialize(),
sender: Nimiq.Address.fromPublicKeys(publicKeys, numberOfSigners).serialize(),
senderLabel: 'Our Multisig Wallet',
recipient: Nimiq.Address.fromUserFriendlyAddress('NQ82 HP54 C9D4 2FAG 69QD 6Q71 LURR 5187 0V3X').serialize(),
recipientLabel: 'Best Friend',
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
},
"homepage": "https://github.com/nimiq/keyguard#readme",
"devDependencies": {
"@nimiq/albatross-wasm": "npm:@nimiq/core@^2.0.5",
"@nimiq/albatross-wasm": "https://gitpkg.now.sh/nimiq/core-rs-albatross/web-client/dist?06999e1626b3312a906a0a490339d7feb781811b",
"@nimiq/core-web": "1.6.3",
"@nimiq/rpc": "^0.3.0",
"@nimiq/style": "^0.8.3",
Expand Down
27 changes: 17 additions & 10 deletions src/lib/Key.js
Original file line number Diff line number Diff line change
Expand Up @@ -94,21 +94,28 @@ class Key {
*
* @param {string} path
* @param {Uint8Array} data
* @param {Nimiq.PublicKey[]} signerPublicKeys
* @param {Nimiq.RandomSecret} secret
* @param {Nimiq.Commitment} aggregatedCommitment
* @param {Nimiq.CommitmentPair[]} ownCommitmentPairs
* @param {{publicKey: Nimiq.PublicKey, commitments: Nimiq.Commitment[]}[]} otherSigners
* @returns {Nimiq.PartialSignature}
*/
signPartially(path, data, signerPublicKeys, secret, aggregatedCommitment) {
signPartially(path, data, ownCommitmentPairs, otherSigners) {
const privateKey = this.derivePrivateKey(path);
const publicKey = Nimiq.PublicKey.derive(privateKey);
signerPublicKeys.sort((a, b) => a.compare(b));
const [otherPublicKeys, otherCommitments] = otherSigners.reduce((acc, signer) => {
acc[0].push(signer.publicKey);
acc[1].push(signer.commitments);
return acc;
}, [
/** @type {Nimiq.PublicKey[]} */ ([]),
/** @type {Nimiq.Commitment[][]} */ ([]),
]);

return Nimiq.PartialSignature.create(
privateKey,
publicKey,
signerPublicKeys,
secret,
aggregatedCommitment,
ownCommitmentPairs,
otherPublicKeys,
otherCommitments,
data,
);
}
Expand Down Expand Up @@ -215,7 +222,7 @@ class Key {
}

// Extend 32-byte secret into 1024-byte seed as bytestring
/** @type {Nimiq.SerialBuffer} */
/** @type {Uint8Array} */
let seed;
switch (keyParams.kdf) {
case 'PBKDF2-SHA512':
Expand All @@ -233,7 +240,7 @@ class Key {
// Send computation command to iframe
iframe.contentWindow.postMessage({
command: 'generateKey',
seed: Nimiq.BufferUtils.toAscii(seed), // seed is a bytestring
seed: Nimiq.BufferUtils.toUtf8(seed), // seed is a bytestring
keySize: keyParams.keySize,
}, '*');

Expand Down
79 changes: 0 additions & 79 deletions src/lib/multisig/MerkleTreePatch.js

This file was deleted.

57 changes: 0 additions & 57 deletions src/lib/multisig/MultisigUtils.js

This file was deleted.

1 change: 0 additions & 1 deletion src/lib/multisig/wasm/.gitignore

This file was deleted.

Loading

0 comments on commit 98d7997

Please sign in to comment.