Skip to content

Commit

Permalink
Resolving rebase conflict and simplifying the signature construction
Browse files Browse the repository at this point in the history
  • Loading branch information
xbtmatt committed Aug 12, 2023
1 parent 957ee15 commit 1474ae4
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -92,10 +92,8 @@ const main = async () => {
// Initialize a MultiEd25519 account with the created accounts as owners and a signature threshold K as NUM_SIGNATURES_REQUIRED
await initializeMultiEd25519(faucetClient, accounts, NUM_SIGNATURES_REQUIRED);

const multiSigPublicKey = new TxnBuilderTypes.MultiEd25519PublicKey(
accounts.map((acc) => new TxnBuilderTypes.Ed25519PublicKey(acc.signingKey.publicKey)),
NUM_SIGNATURES_REQUIRED,
);
const publicKeys = accounts.map((acc) => new TxnBuilderTypes.Ed25519PublicKey(acc.signingKey.publicKey));
const multiSigPublicKey = new TxnBuilderTypes.MultiEd25519PublicKey(publicKeys, NUM_SIGNATURES_REQUIRED);
const authKey = TxnBuilderTypes.AuthenticationKey.fromMultiEd25519PublicKey(multiSigPublicKey);
const multiSigAddress = TxnBuilderTypes.AccountAddress.fromHex(authKey.derivedAddress());

Expand All @@ -121,14 +119,11 @@ const main = async () => {
const structSig3 = account3.signBuffer(bcsSerializedStruct);
const structSignatures = [structSig1, structSig2, structSig3].map((sig) => sig.toUint8Array());

// This is the bitmap indicating which original owners are present as signers. It takes a diff of the original owners and the signing owners and creates the bitmap based on that.
const bitmap = createBitmapFromDiff(accountAddresses, signingAddresses);

// Step 5.
// Assemble a MultiEd25519 signed proof struct with the gathered signatures.
// This represents the multisig signed struct by all owners. This is used as proof of authentication by the overall MultiEd25519 account, since there's no signer
// checked in the entry function we're using.
const multiSigStruct = createMultiSigStructFromSignedStructs(structSignatures, bitmap);
const multiSigStruct = createMultiSigStructFromSignedStructs(accountAddresses, signingAddresses, structSignatures);

// Create test metadata for the multisig account post-creation
const metadataKeys = ["key 123", "key 456", "key 789"];
Expand Down Expand Up @@ -250,13 +245,20 @@ const createWithExistingAccountAndRevokeAuthKeyPayload = (

// We create the multisig struct by concatenating the individually signed structs together
// Then we append the bitmap at the end.
const createMultiSigStructFromSignedStructs = (signatures: Array<Uint8Array>, bitmap: Uint8Array): Uint8Array => {
const createMultiSigStructFromSignedStructs = (
accountAddresses: Array<TxnBuilderTypes.AccountAddress>,
signingAddresses: Array<TxnBuilderTypes.AccountAddress>,
signatures: Array<Uint8Array>,
): Uint8Array => {
// Flatten the signatures into a single byte array
let flattenedSignatures = new Uint8Array();
signatures.forEach((sig) => {
flattenedSignatures = new Uint8Array([...flattenedSignatures, ...sig]);
});

// This is the bitmap indicating which original owners are present as signers. It takes a diff of the original owners and the signing owners and creates the bitmap based on that.
const bitmap = createBitmapFromDiff(accountAddresses, signingAddresses);

// Add the bitmap to the end of the byte array
return new Uint8Array([...flattenedSignatures, ...bitmap]);
};
Expand Down
4 changes: 0 additions & 4 deletions ecosystem/typescript/sdk/examples/typescript-esm/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,9 @@
"scripts": {
"build": "rm -rf dist/* && tsc -p .",
"test": "pnpm build && node ./dist/index.js",
<<<<<<< HEAD
"offer_capabilities": "ts-node --esm offer_capabilities.ts",
"rotate_key": "ts-node --esm rotate_key.ts"
=======
"rotate_key": "ts-node --esm rotate_key.ts",
"multi_ed25519_to_multisig": "ts-node --esm multi_ed25519_to_multisig.ts"
>>>>>>> 1aafc62c48 (An example of converting a MultiEd25519 account to a MultiSig account)
},
"keywords": [],
"author": "",
Expand Down

0 comments on commit 1474ae4

Please sign in to comment.