- From: Marcos Cáceres <notifications@github.com>
- Date: Mon, 30 Jan 2017 19:24:17 -0800
- To: w3c/webpayments-payment-apps-api <webpayments-payment-apps-api@noreply.github.com>
- Cc: Subscribed <subscribed@noreply.github.com>
- Message-ID: <w3c/webpayments-payment-apps-api/issues/99/276264871@github.com>
Ok, here is a very rough sketch. I need @hhalpin to help me a little here... or at least to sanity check.
```JS
async function encryptData(url, data) {
// Note: with foreign fetch, this is an immediate response, as it would be cached.
const bobPublicKey = await fetch(url).then(r => r.text());
// I don't know what AlgorithmIdentifier to use 🤷♀️, Harry! HELP!!! ❤️
const cryptoKey = await crypto.subtle
.importKey("spki", bobPublicKey, algoIdentifier, false, ["encrypt"]);
const encoder = new TextEncoder('utf-8');
const clearData = encoder.encode(JSON.stringify(bobPayData));
// I have no idea if the below is correct... I stole it from the Web Crypto spec.
const aesAlgorithmEncrypt = {
name: "AES-CBC",
iv: crypto.getRandomValues(new Uint8Array(16))
};
return await crypto.subtle.encrypt(aesAlgorithmEncrypt, cryptoKey, [clearData]))
}
async function requestPayment() {
const bobPayData = {
supportedMethods: ["bobpay.com"],
data: {
merchantIdentifier: "XXXX",
bobPaySpecificField: true
},
};
const bobKeyURL = "https://bobpay.com/public.key";
const methodData = [{
supportedMethods: ["basic-card"],
data: {
supportedNetworks: ['aFamousBrand', 'aDebitNetwork'],
supportedTypes: ['debit']
}
}, {
supportedMethods: ["bobpay.com"],
data: await encrypt(bobKeyURL, bobPayData),
}];
const request = new PaymentRequest(methodData, details, options);
if (await request.canMakePayment() === false) {
return; // Too bad... do something else
}
request.show();
}
```
--
You are receiving this because you are subscribed to this thread.
Reply to this email directly or view it on GitHub:
https://github.com/w3c/webpayments-payment-apps-api/issues/99#issuecomment-276264871
Received on Tuesday, 31 January 2017 03:24:50 UTC