Skip to content

Commit

Permalink
Secure payment request, #19
Browse files Browse the repository at this point in the history
  • Loading branch information
fabiancook committed Jun 25, 2023
1 parent 1df5f81 commit 2ecc45d
Show file tree
Hide file tree
Showing 14 changed files with 813 additions and 98 deletions.
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,8 @@
"react-dom": "node_modules/react-dom/index.js",
"react-dom/client": "node_modules/react-dom/client.js",
"@simplewebauthn/browser": "node_modules/@simplewebauthn/browser/dist/bundle/index.js",
"@authsignal/browser": "node_modules/@authsignal/browser/dist/index.js"
"@authsignal/browser": "node_modules/@authsignal/browser/dist/index.js",
"@hexagon/base64": "node_modules/@hexagon/base64/dist/base64.min.mjs"
}
},
"staticReferences": [
Expand Down
5 changes: 1 addition & 4 deletions src/data/user-credential/set-user-credential.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,14 @@ import {v4} from "uuid";
import {createHash} from "crypto";
import {getExpiresAt} from "../expiring-kv";

function getUserCredentialId(data: SetUserCredential): string {
function getUserCredentialId(data: Pick<SetUserCredential, "credentialId" | "userId">): string {
const hash = createHash("sha256");
hash.update(data.userId);
if (data.credentialId) {
hash.update(data.credentialId);
} else {
hash.update(v4());
}
if (data.deviceId) {
hash.update(data.deviceId);
}
return hash.digest().toString("hex");
}

Expand Down
76 changes: 76 additions & 0 deletions src/listen/auth/types.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
import {
PublicKeyCredentialRequestOptionsJSON,
AuthenticationResponseJSON,
Base64URLString, PublicKeyCredentialDescriptorJSON, PublicKeyCredentialJSON
} from "@simplewebauthn/typescript-types";
import {
AuthenticationExtensionsClientInputs,
UserVerificationRequirement
} from "@simplewebauthn/typescript-types/dist/dom";

export interface PaymentRequestInstrument {
displayName: string;
icon: string;
iconMustBeShown?: boolean;
}

export interface PaymentRequestDataJSON {
challenge: Base64URLString;
timeout?: number;
rpId?: string;
allowCredentials?: PublicKeyCredentialDescriptorJSON[];
instrument: PaymentRequestInstrument;
payeeOrigin: string;
}

export interface PartialPaymentRequestDataJSON extends Partial<Omit<PaymentRequestDataJSON, "instrument">> {
instrument?: Partial<PaymentRequestInstrument>;
}

export interface PaymentRequestOptionsJSON {
data: PaymentRequestDataJSON;
details: PaymentDetailsInit;
}

export interface PartialPaymentRequestOptionsJSON {
data?: PartialPaymentRequestDataJSON;
details?: Partial<PaymentDetailsInit>;
}

export interface PaymentResponseJSON {
details: AuthenticationResponseJSON
methodName: string;
payerEmail?: string;
payerName?: string;
payerPhone?: string;
requestId: string;
shippingAddress?: unknown;
shippingOption?: unknown;
}

/*
{
// The RP ID
rpId: location.hostname,
// List of credential IDs obtained from the RP server.
credentialIds: credentialIds.flatMap(value => value.split("_")).map(base64ToArrayBuffer),
// The challenge is also obtained from the RP server.
challenge: base64ToArrayBuffer(challenge),
// A display name and an icon that represent the payment instrument.
instrument: {
displayName: paymentMethodName,
// Transparent-black pixel.
icon: "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVR42mNk+P+/HgAFhAJ/wlseKgAAAABJRU5ErkJggg==",
iconMustBeShown: false
},
// The origin of the payee (merchant)
payeeOrigin: payeeOrigin || location.origin,
// The number of milliseconds to timeout.
timeout: 360000, // 6 minutes
}
*/
Loading

0 comments on commit 2ecc45d

Please sign in to comment.