diff options
author | Florian Dold <florian.dold@gmail.com> | 2019-12-05 23:07:46 +0100 |
---|---|---|
committer | Florian Dold <florian.dold@gmail.com> | 2019-12-05 23:07:46 +0100 |
commit | 7b54439fd62bd2a5e15b3068a8fbaffeb0a57468 (patch) | |
tree | 09b32371728d4a0e40f1fb24b415b6dc1f488962 /src/crypto | |
parent | 8115ac660cd9d12ef69ca80fc2e4cf8eec6b1ba1 (diff) |
validate wire fees and acct info
Diffstat (limited to 'src/crypto')
-rw-r--r-- | src/crypto/workers/cryptoApi.ts | 4 | ||||
-rw-r--r-- | src/crypto/workers/cryptoImplementation.ts | 26 |
2 files changed, 26 insertions, 4 deletions
diff --git a/src/crypto/workers/cryptoApi.ts b/src/crypto/workers/cryptoApi.ts index 5537bb39f..aa1ff2c42 100644 --- a/src/crypto/workers/cryptoApi.ts +++ b/src/crypto/workers/cryptoApi.ts @@ -409,6 +409,10 @@ export class CryptoApi { return this.doRpc<boolean>("rsaVerify", 4, hm, sig, pk); } + isValidWireAccount(paytoUri: string, sig: string, masterPub: string): Promise<boolean> { + return this.doRpc<boolean>("isValidWireAccount", 4, paytoUri, sig, masterPub); + } + createPaybackRequest(coin: CoinRecord): Promise<PaybackRequest> { return this.doRpc<PaybackRequest>("createPaybackRequest", 1, coin); } diff --git a/src/crypto/workers/cryptoImplementation.ts b/src/crypto/workers/cryptoImplementation.ts index 00d81ce27..fa5a30d68 100644 --- a/src/crypto/workers/cryptoImplementation.ts +++ b/src/crypto/workers/cryptoImplementation.ts @@ -68,15 +68,17 @@ import { rsaVerify, } from "../talerCrypto"; import { randomBytes } from "../primitives/nacl-fast"; +import { kdf } from "../primitives/kdf"; enum SignaturePurpose { RESERVE_WITHDRAW = 1200, WALLET_COIN_DEPOSIT = 1201, MASTER_DENOMINATION_KEY_VALIDITY = 1025, + MASTER_WIRE_FEES = 1028, + MASTER_WIRE_DETAILS = 1030, WALLET_COIN_MELT = 1202, TEST = 4242, MERCHANT_PAYMENT_OK = 1104, - MASTER_WIRE_FEES = 1028, WALLET_COIN_PAYBACK = 1203, WALLET_COIN_LINK = 1204, } @@ -157,9 +159,7 @@ export class CryptoImplementation { * Create a pre-coin of the given denomination to be withdrawn from then given * reserve. */ - createPlanchet( - req: PlanchetCreationRequest, - ): PlanchetCreationResult { + createPlanchet(req: PlanchetCreationRequest): PlanchetCreationResult { const reservePub = decodeCrock(req.reservePub); const reservePriv = decodeCrock(req.reservePriv); const denomPub = decodeCrock(req.denomPub); @@ -264,6 +264,7 @@ export class CryptoImplementation { .put(timestampToBuffer(wf.startStamp)) .put(timestampToBuffer(wf.endStamp)) .put(amountToBuffer(wf.wireFee)) + .put(amountToBuffer(wf.closingFee)) .build(); const sig = decodeCrock(wf.sig); const pub = decodeCrock(masterPub); @@ -292,6 +293,23 @@ export class CryptoImplementation { return eddsaVerify(p, sig, pub); } + isValidWireAccount( + paytoUri: string, + sig: string, + masterPub: string, + ): boolean { + const h = kdf( + 64, + stringToBytes("exchange-wire-signature"), + stringToBytes(paytoUri + "\0"), + new Uint8Array(0), + ); + const p = buildSigPS(SignaturePurpose.MASTER_WIRE_DETAILS) + .put(h) + .build(); + return eddsaVerify(p, decodeCrock(sig), decodeCrock(masterPub)); + } + /** * Create a new EdDSA key pair. */ |