From 6fd3cc2eb02f376beef1729a7e213133e6ed6280 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=B6ren?= Date: Thu, 14 Nov 2024 12:02:13 -0600 Subject: [PATCH] WIP --- client/PublicPaymentOptions.ts | 2 +- client/PublicRequestTypes.ts | 16 +- client/dist/src/PublicPaymentOptions.d.ts | 2 +- client/dist/src/PublicRequestTypes.d.ts | 14 +- docs/api-methods/10_checkout.md | 6 +- docs/api-methods/40_sign-transaction.md | 6 +- package.json | 2 +- src/CashlinkApp.vue | 6 +- src/components/CheckoutCardNimiq.vue | 8 +- src/components/Network.vue | 250 ++++++------------ src/config/config.local.ts | 2 +- src/config/config.mainnet.ts | 2 +- src/config/config.testnet.ts | 2 +- src/export.ts | 3 - src/i18n/en.po | 171 ++++++------ src/lib/AccountInfo.ts | 2 +- src/lib/BufferUtils.ts | 15 -- src/lib/Cashlink.ts | 139 ++++------ src/lib/ContractInfo.ts | 68 ++--- src/lib/CookieDecoder.ts | 12 +- src/lib/CookieJar.ts | 14 +- src/lib/Helpers.ts | 30 --- src/lib/LedgerSwapProxy.ts | 82 +++--- src/lib/NetworkClient.ts | 95 +++++-- src/lib/NimiqUtils.ts | 7 + src/lib/PermissionStore.ts | 4 +- src/lib/RequestParser.ts | 16 +- src/lib/RequestTypes.ts | 6 +- src/lib/Uid.ts | 3 - src/lib/WalletInfo.ts | 6 +- src/lib/WalletInfoCollector.ts | 5 +- src/lib/WalletStore.ts | 1 - src/lib/bitcoin/BitcoinLedgerUtils.ts | 4 +- src/lib/bitcoin/BitcoinUtils.ts | 9 + src/lib/paymentOptions/NimiqPaymentOptions.ts | 14 +- src/main.ts | 12 + src/views/AddVestingContract.vue | 40 ++- src/views/CashlinkCreate.vue | 32 +-- src/views/CashlinkManage.vue | 4 +- src/views/CashlinkReceive.vue | 15 +- src/views/CheckoutTransmission.vue | 16 +- src/views/Migrate.vue | 3 +- src/views/RefundSwap.vue | 2 +- src/views/RefundSwapLedger.vue | 29 +- src/views/RefundSwapSuccess.vue | 8 +- src/views/SetupSwap.vue | 4 +- src/views/SetupSwapLedger.vue | 28 +- src/views/SetupSwapSuccess.vue | 41 +-- src/views/SignBtcTransaction.vue | 7 +- src/views/SignBtcTransactionLedger.vue | 3 +- src/views/SignStaking.vue | 3 +- src/views/SignStakingSuccess.vue | 13 +- src/views/SignTransaction.vue | 10 +- src/views/SignTransactionLedger.vue | 24 +- src/views/SignTransactionSuccess.vue | 17 +- tests/unit/CookieJar.spec.ts | 32 +-- tests/unit/WalletStore.spec.ts | 4 +- types/Nimiq.d.ts | 10 +- yarn.lock | 5 +- 59 files changed, 644 insertions(+), 742 deletions(-) delete mode 100644 src/lib/BufferUtils.ts create mode 100644 src/lib/NimiqUtils.ts diff --git a/client/PublicPaymentOptions.ts b/client/PublicPaymentOptions.ts index d9b7bae2f..85b08e0b3 100644 --- a/client/PublicPaymentOptions.ts +++ b/client/PublicPaymentOptions.ts @@ -9,7 +9,7 @@ export interface NimiqSpecifics { sender?: string; forceSender?: boolean; recipient?: string; - recipientType?: Nimiq.Account.Type; + recipientType?: Nimiq.AccountType; } export type NimiqDirectPaymentOptions = PaymentOptions; diff --git a/client/PublicRequestTypes.ts b/client/PublicRequestTypes.ts index 2adc7d3c3..2648e0bfa 100644 --- a/client/PublicRequestTypes.ts +++ b/client/PublicRequestTypes.ts @@ -92,7 +92,7 @@ export interface ChooseAddressResult extends Address { export interface SignTransactionRequest extends BasicRequest { sender: string; recipient: string; - recipientType?: Nimiq.Account.Type | 3; + recipientType?: Nimiq.AccountType; recipientLabel?: string; value: number; fee?: number; @@ -113,7 +113,7 @@ export interface NimiqCheckoutRequest extends BasicRequest { sender?: string; forceSender?: boolean; recipient: string; - recipientType?: Nimiq.Account.Type; + recipientType?: Nimiq.AccountType; value: number; fee?: number; extraData?: Bytes; @@ -236,9 +236,9 @@ export interface SignedTransaction { signature: Uint8Array; sender: string; // Userfriendly address - senderType: Nimiq.Account.Type | 3; + senderType: Nimiq.AccountType; recipient: string; // Userfriendly address - recipientType: Nimiq.Account.Type | 3; + recipientType: Nimiq.AccountType; value: number; // Luna fee: number; // Luna validityStartHeight: number; @@ -460,19 +460,19 @@ export interface Address { } export interface VestingContract { - type: Nimiq.Account.Type.VESTING; + type: Nimiq.AccountType.Vesting; address: string; // Userfriendly address label: string; owner: string; // Userfriendly address - start: number; + startTime: number; stepAmount: number; - stepBlocks: number; + timeStep: number; totalAmount: number; } export interface HashedTimeLockedContract { - type: Nimiq.Account.Type.HTLC; + type: Nimiq.AccountType.HTLC; address: string; // Userfriendly address label: string; diff --git a/client/dist/src/PublicPaymentOptions.d.ts b/client/dist/src/PublicPaymentOptions.d.ts index ac0204eea..40a121481 100644 --- a/client/dist/src/PublicPaymentOptions.d.ts +++ b/client/dist/src/PublicPaymentOptions.d.ts @@ -8,7 +8,7 @@ export interface NimiqSpecifics { sender?: string; forceSender?: boolean; recipient?: string; - recipientType?: Nimiq.Account.Type; + recipientType?: Nimiq.AccountType; } export declare type NimiqDirectPaymentOptions = PaymentOptions; export interface BitcoinSpecifics { diff --git a/client/dist/src/PublicRequestTypes.d.ts b/client/dist/src/PublicRequestTypes.d.ts index dd9bf3884..b3146ea00 100644 --- a/client/dist/src/PublicRequestTypes.d.ts +++ b/client/dist/src/PublicRequestTypes.d.ts @@ -34,7 +34,7 @@ export declare enum AccountType { BIP39 = 2, LEDGER = 3 } -export { +export { /** @deprecated Use AccountType instead */ AccountType as WalletType, }; export interface BasicRequest { @@ -72,7 +72,7 @@ export interface ChooseAddressResult extends Address { export interface SignTransactionRequest extends BasicRequest { sender: string; recipient: string; - recipientType?: Nimiq.Account.Type | 3; + recipientType?: Nimiq.AccountType | 3; recipientLabel?: string; value: number; fee?: number; @@ -91,7 +91,7 @@ export interface NimiqCheckoutRequest extends BasicRequest { sender?: string; forceSender?: boolean; recipient: string; - recipientType?: Nimiq.Account.Type; + recipientType?: Nimiq.AccountType; value: number; fee?: number; extraData?: Bytes; @@ -190,9 +190,9 @@ export interface SignedTransaction { signerPublicKey: Uint8Array; signature: Uint8Array; sender: string; - senderType: Nimiq.Account.Type | 3; + senderType: Nimiq.AccountType | 3; recipient: string; - recipientType: Nimiq.Account.Type | 3; + recipientType: Nimiq.AccountType | 3; value: number; fee: number; validityStartHeight: number; @@ -375,7 +375,7 @@ export interface Address { label: string; } export interface VestingContract { - type: Nimiq.Account.Type.VESTING; + type: Nimiq.AccountType.VESTING; address: string; label: string; owner: string; @@ -385,7 +385,7 @@ export interface VestingContract { totalAmount: number; } export interface HashedTimeLockedContract { - type: Nimiq.Account.Type.HTLC; + type: Nimiq.AccountType.HTLC; address: string; label: string; sender: string; diff --git a/docs/api-methods/10_checkout.md b/docs/api-methods/10_checkout.md index 153e20ed0..edd70d378 100644 --- a/docs/api-methods/10_checkout.md +++ b/docs/api-methods/10_checkout.md @@ -77,7 +77,7 @@ const signedTransaction = await hubApi.checkout(options); | `forceSender` | boolean | no | Whether to force the submitted sender address. If this option is `true`, an exception is thrown when either the sender address does not exist or does not have sufficient balance. When `false` (default), the user will be shown the address selector instead. (Only relevant in connection with the `sender` option.) | | `validityDuration` | number | no | The duration (in number of blocks) that the signed transaction should be valid for. The maximum and default is 120. | | `flags` | number | no | A [`Nimiq.Transaction.Flag`](https://nimiq-network.github.io/developer-reference/chapters/transactions.html#extended-transaction), only required if the transaction should create a contract. | -| `recipientType` | number | no | The [`Nimiq.Account.Type`](https://nimiq-network.github.io/developer-reference/chapters/accounts-and-contracts.html#contracts) of the recipient. Only required if the transaction should create a contract. | +| `recipientType` | number | no | The [`Nimiq.AccountType`](https://nimiq-network.github.io/developer-reference/chapters/accounts-and-contracts.html#contracts) of the recipient. Only required if the transaction should create a contract. | ## Result @@ -93,10 +93,10 @@ interface SignedTransaction { signature: Uint8Array; // Serialized signature of the signer sender: string; // Human-readable address of sender - senderType: Nimiq.Account.Type; // 0, 1, 2 - see recipientType above + senderType: Nimiq.AccountType; // 0, 1, 2, 3 - see recipientType above recipient: string; // Human-readable address of recipient - recipientType: Nimiq.Account.Type; // 0, 1, 2 - see above + recipientType: Nimiq.AccountType; // 0, 1, 2, 3 - see above value: number; fee: number; diff --git a/docs/api-methods/40_sign-transaction.md b/docs/api-methods/40_sign-transaction.md index a586b68ff..fe93a589f 100644 --- a/docs/api-methods/40_sign-transaction.md +++ b/docs/api-methods/40_sign-transaction.md @@ -102,7 +102,7 @@ const signedTransaction = await hubApi.signTransaction(options); | `fee` | number | no | Transaction fee in luna. Default: 0 | | `extraData` | string or Uint8Array | no | Extra data that should be sent with the transaction. | | `flags` | number | no | A [`Nimiq.Transaction.Flag`](https://nimiq-network.github.io/developer-reference/chapters/transactions.html#extended-transaction), only required if the transaction should create a contract. | -| `recipientType` | number | no | The [`Nimiq.Account.Type`](https://nimiq-network.github.io/developer-reference/chapters/accounts-and-contracts.html#contracts) of the recipient. Only required if the transaction should create a contract. | +| `recipientType` | number | no | The [`Nimiq.AccountType`](https://nimiq-network.github.io/developer-reference/chapters/accounts-and-contracts.html#contracts) of the recipient. Only required if the transaction should create a contract. | ## Result @@ -118,10 +118,10 @@ interface SignedTransaction { signature: Uint8Array; // Serialized signature of the signer sender: string; // Human-readable address of sender - senderType: Nimiq.Account.Type; // 0, 1, 2 - see recipientType above + senderType: Nimiq.AccountType; // 0, 1, 2, 3 - see recipientType above recipient: string; // Human-readable address of recipient - recipientType: Nimiq.Account.Type; // 0, 1, 2 - see above + recipientType: Nimiq.AccountType; // 0, 1, 2, 3 - see above value: number; fee: number; diff --git a/package.json b/package.json index d695c394e..7ac100ee9 100644 --- a/package.json +++ b/package.json @@ -26,7 +26,7 @@ "@nimiq/fastspot-api": "^1.8.0", "@nimiq/iqons": "^1.5.2", "@nimiq/keyguard-client": "https://gitpkg.vercel.app/nimiq/keyguard?scripts.postinstall=cd%20client%20%26%26%20.%2Fbuild-gitpkg.sh&239c43cc712da603ce744eeede76f3b9d56d16b2", - "@nimiq/ledger-api": "^3.0.0", + "@nimiq/ledger-api": "github:nimiq/ledger-api#a7179c2d207c1deaeb2ab777ce6ad994e59f9c5f", "@nimiq/network-client": "^0.6.2", "@nimiq/oasis-api": "^1.1.1", "@nimiq/rpc": "^0.4.1", diff --git a/src/CashlinkApp.vue b/src/CashlinkApp.vue index 8f145f662..89bd7736e 100644 --- a/src/CashlinkApp.vue +++ b/src/CashlinkApp.vue @@ -21,7 +21,6 @@ import { Component, Vue } from 'vue-property-decorator'; import { LoadingSpinner } from '@nimiq/vue-components'; import CashlinkReceive from './views/CashlinkReceive.vue'; import { CashlinkTheme } from '../client/PublicRequestTypes'; -import { loadNimiq } from './lib/Helpers'; import '@nimiq/style/nimiq-style.min.css'; import '@nimiq/vue-components/dist/NimiqVueComponents.css'; @@ -32,10 +31,7 @@ export default class CashlinkApp extends Vue { private isDarkTheme = false; public async created() { - await Promise.all([ - this.$store.dispatch('initWallets'), - loadNimiq(), - ]); + await this.$store.dispatch('initWallets'); this.loading = false; } diff --git a/src/components/CheckoutCardNimiq.vue b/src/components/CheckoutCardNimiq.vue index cb3374d72..b34cc5c5a 100644 --- a/src/components/CheckoutCardNimiq.vue +++ b/src/components/CheckoutCardNimiq.vue @@ -247,10 +247,10 @@ class CheckoutCardNimiq const balance = balances.get(accountOrContract.userFriendlyAddress); if (balance === undefined) continue; - if ('type' in accountOrContract && accountOrContract.type === Nimiq.Account.Type.VESTING) { + if ('type' in accountOrContract && accountOrContract.type === Nimiq.AccountType.Vesting) { // Calculate available amount for vesting contract accountOrContract.balance = (accountOrContract as VestingContractInfo) - .calculateAvailableAmount(this.height, balance); + .calculateAvailableAmount(balance); } else { accountOrContract.balance = balance; } @@ -392,10 +392,10 @@ class CheckoutCardNimiq keyLabel: senderAccount.labelForKeyguard, sender: (senderContract || signer).address.serialize(), - senderType: senderContract ? senderContract.type : Nimiq.Account.Type.BASIC, + senderType: senderContract ? senderContract.type : Nimiq.AccountType.Basic, senderLabel: (senderContract || signer).label, recipient: this.paymentOptions.protocolSpecific.recipient!.serialize(), - recipientType: this.paymentOptions.protocolSpecific.recipientType, + recipientType: this.paymentOptions.protocolSpecific.recipientType as any, // TODO: Remove when Keyguard Client is updated // recipientLabel: '', // Checkout is using the shopOrigin instead value: this.paymentOptions.amount, fee: this.paymentOptions.fee, diff --git a/src/components/Network.vue b/src/components/Network.vue index a12bcad09..ca054534c 100644 --- a/src/components/Network.vue +++ b/src/components/Network.vue @@ -3,36 +3,36 @@