Skip to content

Commit

Permalink
Update SignMultisigTransaction flow to Albatross PoS SDK
Browse files Browse the repository at this point in the history
And latest multisig Keyguard client.
  • Loading branch information
sisou committed Jan 15, 2025
1 parent 670110c commit ed539a7
Show file tree
Hide file tree
Showing 8 changed files with 41 additions and 45 deletions.
18 changes: 8 additions & 10 deletions client/PublicRequestTypes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -260,27 +260,25 @@ export interface EncryptionKeyParams {

export interface MultisigInfo {
publicKeys: Bytes[];
numberOfSigners: number;
signerPublicKeys?: Bytes[]; // Can be omitted when all publicKeys need to sign
secret: {
aggregatedSecret: Bytes;
} | {
encryptedSecrets: Bytes[];
bScalar: Bytes;
signers: Array<{
publicKey: Bytes;
commitments: Bytes[];
}>;
secrets: Bytes[] | {
encrypted: Bytes[];
keyParams: EncryptionKeyParams;
};
aggregatedCommitment: Bytes;
userName?: string;
}

export interface SignMultisigTransactionRequest extends BasicRequest {
signer: string; // Address

sender: string;
senderType?: Nimiq.Account.Type;
senderType?: Nimiq.AccountType;
senderLabel: string;
recipient: string;
recipientType?: Nimiq.Account.Type;
recipientType?: Nimiq.AccountType;
recipientLabel?: string;
value: number;
fee?: number;
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
"@nimiq/electrum-client": "https://github.com/nimiq/electrum-client#build",
"@nimiq/fastspot-api": "^1.10.2",
"@nimiq/iqons": "^1.5.2",
"@nimiq/keyguard-client": "https://gitpkg.now.sh/nimiq/keyguard?scripts.postinstall=cd%20client%20%26%26%20.%2Fbuild-gitpkg.sh&a62aa9f557e2ac4c0d7306828e423230f423a0f1",
"@nimiq/keyguard-client": "https://gitpkg.now.sh/nimiq/keyguard?scripts.postinstall=cd%20client%20%26%26%20.%2Fbuild-gitpkg.sh&fbbcf067a5043d9d56bd24c5a2ac79f63355fac1",
"@nimiq/ledger-api": "^3.1.1",
"@nimiq/oasis-api": "^1.1.1",
"@nimiq/rpc": "^0.4.1",
Expand Down
9 changes: 9 additions & 0 deletions src/i18n/en.po
Original file line number Diff line number Diff line change
Expand Up @@ -291,6 +291,10 @@ msgstr ""
msgid "Choose an Account"
msgstr ""

#: src/views/ConnectAccount.vue:5
msgid "Choose an Account to log in"
msgstr ""

#: src/views/CashlinkReceive.vue:64
#: src/views/ChooseAddress.vue:18
#: src/views/ChooseAddress.vue:5
Expand Down Expand Up @@ -697,7 +701,12 @@ msgstr ""
msgid "Login File saved!"
msgstr ""

#: src/views/ConnectAccountSuccess.vue:4
msgid "Login successful"
msgstr ""

#: src/views/ChooseAddress.vue:67
#: src/views/ConnectAccount.vue:40
msgid "Login to another account"
msgstr ""

Expand Down
28 changes: 12 additions & 16 deletions src/lib/RequestParser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -795,35 +795,31 @@ export class RequestParser {
signer: Nimiq.Address.fromAny(signMultisigTxRequest.signer),

sender: Nimiq.Address.fromString(signMultisigTxRequest.sender),
senderType: signMultisigTxRequest.senderType || Nimiq.Account.Type.BASIC,
senderType: signMultisigTxRequest.senderType || Nimiq.AccountType.Basic,
senderLabel: signMultisigTxRequest.senderLabel,
recipient: Nimiq.Address.fromString(signMultisigTxRequest.recipient),
recipientType: signMultisigTxRequest.recipientType || Nimiq.Account.Type.BASIC,
recipientType: signMultisigTxRequest.recipientType || Nimiq.AccountType.Basic,
recipientLabel: signMultisigTxRequest.recipientLabel,
value: signMultisigTxRequest.value,
fee: signMultisigTxRequest.fee || 0,
data: parseMessage(signMultisigTxRequest.extraData) || new Uint8Array(0),
flags: signMultisigTxRequest.flags || Nimiq.Transaction.Flag.NONE,
flags: signMultisigTxRequest.flags || Nimiq.TransactionFlag.None,
validityStartHeight: signMultisigTxRequest.validityStartHeight,

multisigConfig: {
publicKeys: signMultisigTxRequest.multisigConfig.publicKeys.map((bytes) => parseBytes(bytes)),
numberOfSigners: signMultisigTxRequest.multisigConfig.numberOfSigners,
signerPublicKeys: signMultisigTxRequest.multisigConfig.signerPublicKeys
? signMultisigTxRequest.multisigConfig.signerPublicKeys.map((bytes) => parseBytes(bytes))
: signMultisigTxRequest.multisigConfig.publicKeys.map((bytes) => parseBytes(bytes)),
secret: 'aggregatedSecret' in signMultisigTxRequest.multisigConfig.secret
? {aggregatedSecret: parseBytes(
signMultisigTxRequest.multisigConfig.secret.aggregatedSecret,
) }
signers: signMultisigTxRequest.multisigConfig.signers.map((signer) => ({
publicKey: parseBytes(signer.publicKey),
commitments: signer.commitments.map((bytes) => parseBytes(bytes)),
})),
secrets: Array.isArray(signMultisigTxRequest.multisigConfig.secrets)
? signMultisigTxRequest.multisigConfig.secrets.map((bytes) => parseBytes(bytes))
: {
encryptedSecrets: signMultisigTxRequest.multisigConfig.secret.encryptedSecrets.map(
encrypted: signMultisigTxRequest.multisigConfig.secrets.encrypted.map(
(bytes) => parseBytes(bytes),
),
bScalar: parseBytes(signMultisigTxRequest.multisigConfig.secret.bScalar),
keyParams: signMultisigTxRequest.multisigConfig.secret.keyParams,
keyParams: signMultisigTxRequest.multisigConfig.secrets.keyParams,
},
aggregatedCommitment: parseBytes(signMultisigTxRequest.multisigConfig.aggregatedCommitment),
userName: signMultisigTxRequest.multisigConfig.userName,
},
};
Expand All @@ -836,7 +832,7 @@ export class RequestParser {
}

if (connectAccountRequest.appLogoUrl) {
let origin;
let origin: string;
try {
origin = new URL(connectAccountRequest.appLogoUrl).origin;
} catch (err) {
Expand Down
18 changes: 8 additions & 10 deletions src/lib/RequestTypes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,31 +56,29 @@ export interface ParsedSignTransactionRequest extends ParsedBasicRequest {

export interface ParsedMultisigInfo {
publicKeys: Uint8Array[];
numberOfSigners: number;
signerPublicKeys: Uint8Array[]; // Can be omitted when all publicKeys need to sign
secret: {
aggregatedSecret: Uint8Array;
} | {
encryptedSecrets: Uint8Array[];
bScalar: Uint8Array;
signers: Array<{
publicKey: Uint8Array;
commitments: Uint8Array[];
}>;
secrets: Uint8Array[] | {
encrypted: Uint8Array[];
keyParams: {
kdf: string;
iterations: number;
keySize: number;
};
};
aggregatedCommitment: Uint8Array;
userName?: string;
}

export interface ParsedSignMultisigTransactionRequest extends ParsedBasicRequest {
signer: Nimiq.Address;

sender: Nimiq.Address;
senderType: Nimiq.Account.Type;
senderType: Nimiq.AccountType;
senderLabel: string;
recipient: Nimiq.Address;
recipientType: Nimiq.Account.Type;
recipientType: Nimiq.AccountType;
recipientLabel?: string;
value: number;
fee?: number;
Expand Down
5 changes: 0 additions & 5 deletions src/views/ConnectAccountSuccess.vue
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ import StatusScreen from '../components/StatusScreen.vue';
import { SmallPage, CheckmarkIcon } from '@nimiq/vue-components';
import { WalletInfo } from '../lib/WalletInfo';
import { WalletType } from '../lib/Constants';
import { loadNimiq } from '../lib/Helpers';
import { ParsedConnectAccountRequest } from '../lib/RequestTypes';
import { WalletStore } from '../lib/WalletStore';
Expand All @@ -32,8 +31,6 @@ export default class ConnectAccountSuccess extends Vue {
private async mounted() {
const startTime = Date.now();
const nimiqPromise = loadNimiq(); // Required for deriving address from public key
const wallet = this.findWalletByKeyId(this.keyguardRequest.keyId)!;
const walletTypeName: Record<WalletType, string> = {
Expand All @@ -48,8 +45,6 @@ export default class ConnectAccountSuccess extends Vue {
wallet.permissions[this.rpcState.origin] = walletPermissions;
await WalletStore.Instance.put(wallet);
await nimiqPromise;
const result: ConnectedAccount = {
signatures: this.keyguardResult.signatures.map(({signature, publicKey}) => ({
signer: new Nimiq.PublicKey(publicKey).toAddress().toUserFriendlyAddress(),
Expand Down
2 changes: 1 addition & 1 deletion src/views/SignMultisigTransaction.vue
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ export default class SignMultisigTransaction extends Vue {
value: this.request.value,
fee: this.request.fee || 0,
validityStartHeight: this.request.validityStartHeight,
data: this.request.data,
recipientData: this.request.data,
flags: this.request.flags,
multisigConfig: this.request.multisigConfig,
Expand Down
4 changes: 2 additions & 2 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1843,9 +1843,9 @@
dependencies:
dom-parser "^0.1.5"

"@nimiq/keyguard-client@https://gitpkg.now.sh/nimiq/keyguard?scripts.postinstall=cd%20client%20%26%26%20.%2Fbuild-gitpkg.sh&a62aa9f557e2ac4c0d7306828e423230f423a0f1":
"@nimiq/keyguard-client@https://gitpkg.now.sh/nimiq/keyguard?scripts.postinstall=cd%20client%20%26%26%20.%2Fbuild-gitpkg.sh&fbbcf067a5043d9d56bd24c5a2ac79f63355fac1":
version "1.0.0"
resolved "https://gitpkg.now.sh/nimiq/keyguard?scripts.postinstall=cd%20client%20%26%26%20.%2Fbuild-gitpkg.sh&a62aa9f557e2ac4c0d7306828e423230f423a0f1#b821554c4e4751e93cd9e287cd3617812e2a3ea2"
resolved "https://gitpkg.now.sh/nimiq/keyguard?scripts.postinstall=cd%20client%20%26%26%20.%2Fbuild-gitpkg.sh&fbbcf067a5043d9d56bd24c5a2ac79f63355fac1#69723c531cb46fd97466bf35d6cfadd612836ff6"

"@nimiq/ledger-api@^3.1.1":
version "3.1.1"
Expand Down

0 comments on commit ed539a7

Please sign in to comment.