diff options
author | Florian Dold <florian@dold.me> | 2022-11-02 17:42:14 +0100 |
---|---|---|
committer | Florian Dold <florian@dold.me> | 2022-11-02 18:23:17 +0100 |
commit | d50294f76e0aa357d690a933bb6d696a2f6aef1b (patch) | |
tree | abe961337c5df1614b5095bce6c5b09e761cda2c /packages/taler-wallet-core/src/crypto/cryptoImplementation.ts | |
parent | 6c3ef31d9a7ba44829e779afed0af9be3ab23723 (diff) | |
download | wallet-core-d50294f76e0aa357d690a933bb6d696a2f6aef1b.tar.xz |
wallet-core: DB FIXMEs (amount format)
Diffstat (limited to 'packages/taler-wallet-core/src/crypto/cryptoImplementation.ts')
-rw-r--r-- | packages/taler-wallet-core/src/crypto/cryptoImplementation.ts | 16 |
1 files changed, 9 insertions, 7 deletions
diff --git a/packages/taler-wallet-core/src/crypto/cryptoImplementation.ts b/packages/taler-wallet-core/src/crypto/cryptoImplementation.ts index 8ba7d9298..d239270c8 100644 --- a/packages/taler-wallet-core/src/crypto/cryptoImplementation.ts +++ b/packages/taler-wallet-core/src/crypto/cryptoImplementation.ts @@ -28,6 +28,7 @@ import { AgeCommitmentProof, AgeRestriction, AmountJson, + AmountLike, Amounts, AmountString, BlindedDenominationSignature, @@ -1155,8 +1156,8 @@ export const nativeCryptoR: TalerCryptoInterfaceR = { sessionSecretSeed: refreshSessionSecretSeed, } = req; - const currency = newCoinDenoms[0].value.currency; - let valueWithFee = Amounts.getZero(currency); + const currency = Amounts.currencyOf(newCoinDenoms[0].value); + let valueWithFee = Amounts.zeroOfCurrency(currency); for (const ncd of newCoinDenoms) { const t = Amounts.add(ncd.value, ncd.feeWithdraw).amount; @@ -1627,21 +1628,22 @@ export const nativeCryptoR: TalerCryptoInterfaceR = { }, }; -function amountToBuffer(amount: AmountJson): Uint8Array { +function amountToBuffer(amount: AmountLike): Uint8Array { + const amountJ = Amounts.jsonifyAmount(amount); const buffer = new ArrayBuffer(8 + 4 + 12); const dvbuf = new DataView(buffer); const u8buf = new Uint8Array(buffer); - const curr = stringToBytes(amount.currency); + const curr = stringToBytes(amountJ.currency); if (typeof dvbuf.setBigUint64 !== "undefined") { - dvbuf.setBigUint64(0, BigInt(amount.value)); + dvbuf.setBigUint64(0, BigInt(amountJ.value)); } else { - const arr = bigint(amount.value).toArray(2 ** 8).value; + const arr = bigint(amountJ.value).toArray(2 ** 8).value; let offset = 8 - arr.length; for (let i = 0; i < arr.length; i++) { dvbuf.setUint8(offset++, arr[i]); } } - dvbuf.setUint32(8, amount.fraction); + dvbuf.setUint32(8, amountJ.fraction); u8buf.set(curr, 8 + 4); return u8buf; |