aboutsummaryrefslogtreecommitdiff
path: root/packages/taler-wallet-core/src/crypto
diff options
context:
space:
mode:
authorSebastian <sebasjm@gmail.com>2023-07-21 15:50:03 -0300
committerSebastian <sebasjm@gmail.com>2023-07-21 15:50:03 -0300
commite90f1b4206e8843b85655ebe47485c70dbdab3f6 (patch)
treeaa623535e7dd6eca7ddafb383e59c0d195212346 /packages/taler-wallet-core/src/crypto
parent43f5572779f54cee0a73854f0c4fe7bbec35cc2c (diff)
downloadwallet-core-e90f1b4206e8843b85655ebe47485c70dbdab3f6.tar.xz
move amount and time function to util
Diffstat (limited to 'packages/taler-wallet-core/src/crypto')
-rw-r--r--packages/taler-wallet-core/src/crypto/cryptoImplementation.ts61
1 files changed, 3 insertions, 58 deletions
diff --git a/packages/taler-wallet-core/src/crypto/cryptoImplementation.ts b/packages/taler-wallet-core/src/crypto/cryptoImplementation.ts
index 1dd70304a..76c13bcb4 100644
--- a/packages/taler-wallet-core/src/crypto/cryptoImplementation.ts
+++ b/packages/taler-wallet-core/src/crypto/cryptoImplementation.ts
@@ -31,6 +31,7 @@ import {
AmountLike,
Amounts,
AmountString,
+ amountToBuffer,
BlindedDenominationSignature,
bufferForUint32,
bufferForUint64,
@@ -44,6 +45,7 @@ import {
decryptContractForMerge,
DenomKeyType,
DepositInfo,
+ durationRoundedToBuffer,
ecdhGetPublic,
eddsaGetPublic,
EddsaPublicKeyString,
@@ -82,6 +84,7 @@ import {
TalerProtocolDuration,
TalerProtocolTimestamp,
TalerSignaturePurpose,
+ timestampRoundedToBuffer,
UnblindedSignature,
validateIban,
WireFee,
@@ -1698,64 +1701,6 @@ export const nativeCryptoR: TalerCryptoInterfaceR = {
},
};
-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(amountJ.currency);
- if (typeof dvbuf.setBigUint64 !== "undefined") {
- dvbuf.setBigUint64(0, BigInt(amountJ.value));
- } else {
- 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, amountJ.fraction);
- u8buf.set(curr, 8 + 4);
-
- return u8buf;
-}
-
-function timestampRoundedToBuffer(ts: TalerProtocolTimestamp): Uint8Array {
- const b = new ArrayBuffer(8);
- const v = new DataView(b);
- // The buffer we sign over represents the timestamp in microseconds.
- if (typeof v.setBigUint64 !== "undefined") {
- const s = BigInt(ts.t_s) * BigInt(1000 * 1000);
- v.setBigUint64(0, s);
- } else {
- const s =
- ts.t_s === "never" ? bigint.zero : bigint(ts.t_s).multiply(1000 * 1000);
- const arr = s.toArray(2 ** 8).value;
- let offset = 8 - arr.length;
- for (let i = 0; i < arr.length; i++) {
- v.setUint8(offset++, arr[i]);
- }
- }
- return new Uint8Array(b);
-}
-
-function durationRoundedToBuffer(ts: TalerProtocolDuration): Uint8Array {
- const b = new ArrayBuffer(8);
- const v = new DataView(b);
- // The buffer we sign over represents the timestamp in microseconds.
- if (typeof v.setBigUint64 !== "undefined") {
- const s = BigInt(ts.d_us);
- v.setBigUint64(0, s);
- } else {
- const s = ts.d_us === "forever" ? bigint.zero : bigint(ts.d_us);
- const arr = s.toArray(2 ** 8).value;
- let offset = 8 - arr.length;
- for (let i = 0; i < arr.length; i++) {
- v.setUint8(offset++, arr[i]);
- }
- }
- return new Uint8Array(b);
-}
-
export interface EddsaSignRequest {
msg: string;
priv: string;