@andco/protocol 0.0.1 → 0.0.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +1 -1
- package/README.md +33 -3
- package/dist/api-errors.d.ts +109 -0
- package/dist/api-errors.d.ts.map +1 -0
- package/dist/api-errors.js +111 -0
- package/dist/authorization-preparation.d.ts +52 -543
- package/dist/authorization-preparation.d.ts.map +1 -1
- package/dist/authorization-preparation.js +19 -42
- package/dist/authorization.d.ts +64 -22
- package/dist/authorization.d.ts.map +1 -1
- package/dist/authorization.js +136 -55
- package/dist/consent.d.ts +5 -8
- package/dist/consent.d.ts.map +1 -1
- package/dist/consent.js +5 -62
- package/dist/constants.d.ts +19 -3
- package/dist/constants.d.ts.map +1 -1
- package/dist/constants.js +19 -3
- package/dist/errors.d.ts +156 -58
- package/dist/errors.d.ts.map +1 -1
- package/dist/errors.js +176 -57
- package/dist/index.d.ts +5 -5
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +5 -5
- package/dist/intent-input.d.ts +1010 -279
- package/dist/intent-input.d.ts.map +1 -1
- package/dist/intent-input.js +268 -40
- package/dist/messages/error.d.ts +1 -2
- package/dist/messages/error.d.ts.map +1 -1
- package/dist/messages/error.js +5 -2
- package/dist/messages/index.d.ts +3 -3
- package/dist/messages/index.js +2 -2
- package/dist/messages/presentation-response.d.ts +20 -0
- package/dist/messages/presentation-response.d.ts.map +1 -0
- package/dist/messages/presentation-response.js +17 -0
- package/dist/native-copy.d.ts +23 -2
- package/dist/native-copy.d.ts.map +1 -1
- package/dist/native-copy.js +42 -98
- package/dist/native-intent.d.ts +126 -75
- package/dist/native-intent.d.ts.map +1 -1
- package/dist/native-intent.js +140 -48
- package/dist/rar/account-matchers.d.ts +579 -0
- package/dist/rar/account-matchers.d.ts.map +1 -0
- package/dist/rar/account-matchers.js +480 -0
- package/dist/rar/bank.d.ts +1549 -0
- package/dist/rar/bank.d.ts.map +1 -0
- package/dist/rar/bank.js +379 -0
- package/dist/rar/catalog.d.ts +1155 -0
- package/dist/rar/catalog.d.ts.map +1 -0
- package/dist/rar/catalog.js +175 -0
- package/dist/rar/detail.d.ts +39 -0
- package/dist/rar/detail.d.ts.map +1 -0
- package/dist/rar/detail.js +44 -0
- package/dist/rar/index.d.ts +9 -0
- package/dist/rar/index.d.ts.map +1 -0
- package/dist/rar/index.js +8 -0
- package/dist/rar/money.d.ts +58 -0
- package/dist/rar/money.d.ts.map +1 -0
- package/dist/rar/money.js +61 -0
- package/dist/rar/project-users.d.ts +43 -0
- package/dist/rar/project-users.d.ts.map +1 -0
- package/dist/rar/project-users.js +63 -0
- package/dist/rar/subject-data.d.ts +170 -0
- package/dist/rar/subject-data.d.ts.map +1 -0
- package/dist/rar/subject-data.js +127 -0
- package/dist/rar/subject.d.ts +166 -0
- package/dist/rar/subject.d.ts.map +1 -0
- package/dist/rar/subject.js +119 -0
- package/dist/scopes.d.ts +5 -30
- package/dist/scopes.d.ts.map +1 -1
- package/dist/scopes.js +0 -13
- package/dist/service-grants.d.ts +44 -0
- package/dist/service-grants.d.ts.map +1 -0
- package/dist/service-grants.js +45 -0
- package/dist/signing.d.ts +56 -0
- package/dist/signing.d.ts.map +1 -0
- package/dist/signing.js +233 -0
- package/dist/transport/financial-events.d.ts +90 -35
- package/dist/transport/financial-events.d.ts.map +1 -1
- package/dist/transport/financial-events.js +7 -1
- package/dist/transport/generated/oauth-api.d.ts +908 -440
- package/dist/transport/generated/oauth-api.d.ts.map +1 -1
- package/dist/transport/index.d.ts +0 -1
- package/dist/transport/index.d.ts.map +1 -1
- package/dist/transport/index.js +0 -1
- package/dist/transport/intents.d.ts +155 -23
- package/dist/transport/intents.d.ts.map +1 -1
- package/dist/transport/intents.js +192 -59
- package/dist/transport/rest.d.ts +18 -8
- package/dist/transport/rest.d.ts.map +1 -1
- package/dist/transport/rest.js +1 -1
- package/dist/urls.d.ts.map +1 -1
- package/dist/urls.js +1 -1
- package/dist/userinfo.d.ts +10 -1
- package/dist/userinfo.d.ts.map +1 -1
- package/dist/userinfo.js +10 -1
- package/dist/utils.d.ts +15 -0
- package/dist/utils.d.ts.map +1 -1
- package/dist/utils.js +31 -0
- package/dist/webhooks.d.ts +154 -0
- package/dist/webhooks.d.ts.map +1 -0
- package/dist/webhooks.js +249 -0
- package/package.json +18 -1
- package/dist/automatic-charge.d.ts +0 -314
- package/dist/automatic-charge.d.ts.map +0 -1
- package/dist/automatic-charge.js +0 -126
- package/dist/bank-account-authorization.d.ts +0 -6
- package/dist/bank-account-authorization.d.ts.map +0 -1
- package/dist/bank-account-authorization.js +0 -13
- package/dist/messages/authorization-response.d.ts +0 -12
- package/dist/messages/authorization-response.d.ts.map +0 -1
- package/dist/messages/authorization-response.js +0 -9
- package/dist/transport/webhooks.d.ts +0 -27
- package/dist/transport/webhooks.d.ts.map +0 -1
- package/dist/transport/webhooks.js +0 -68
- package/dist/webhook-input.d.ts +0 -22
- package/dist/webhook-input.d.ts.map +0 -1
- package/dist/webhook-input.js +0 -11
- package/dist/webhook-signature.d.ts +0 -54
- package/dist/webhook-signature.d.ts.map +0 -1
- package/dist/webhook-signature.js +0 -74
|
@@ -1,54 +0,0 @@
|
|
|
1
|
-
/** Header names Andco signs a webhook delivery with. */
|
|
2
|
-
export declare const ANDCO_WEBHOOK_HEADERS: {
|
|
3
|
-
readonly signature: "andco-signature";
|
|
4
|
-
readonly eventId: "andco-event-id";
|
|
5
|
-
readonly timestamp: "andco-timestamp";
|
|
6
|
-
};
|
|
7
|
-
/** Default tolerance for the delivery timestamp, in seconds. */
|
|
8
|
-
export declare const ANDCO_WEBHOOK_TOLERANCE_SECONDS = 300;
|
|
9
|
-
/** Everything a verification needs, however the runtime spells its headers. */
|
|
10
|
-
export type AndCoWebhookVerifyInput = {
|
|
11
|
-
/** The exact bytes of the request body, before any JSON parsing. */
|
|
12
|
-
body: string;
|
|
13
|
-
/** `Andco-Signature`, including its `v1=` prefix. */
|
|
14
|
-
signature: string | null | undefined;
|
|
15
|
-
/** `Andco-Event-Id`. */
|
|
16
|
-
eventId: string | null | undefined;
|
|
17
|
-
/** `Andco-Timestamp`, in seconds. */
|
|
18
|
-
timestamp: string | null | undefined;
|
|
19
|
-
/** The subscription's signing secret. */
|
|
20
|
-
secret: string | Uint8Array;
|
|
21
|
-
/** How far the delivery timestamp may drift. Defaults to five minutes. */
|
|
22
|
-
toleranceSeconds?: number;
|
|
23
|
-
/** Current time in seconds, for tests. */
|
|
24
|
-
now?: number;
|
|
25
|
-
};
|
|
26
|
-
/**
|
|
27
|
-
* Whether a webhook delivery really came from Andco.
|
|
28
|
-
*
|
|
29
|
-
* The signature covers `{timestamp}.{eventId}.{body}`, so it binds the payload to one delivery and
|
|
30
|
-
* one moment: replaying an old body under a new timestamp does not verify, and neither does
|
|
31
|
-
* reusing a valid signature for a different event.
|
|
32
|
-
*
|
|
33
|
-
* Two details are easy to get wrong when this is written by hand, and both are handled here: the
|
|
34
|
-
* comparison is constant-time, so a wrong signature leaks nothing through how long the check takes,
|
|
35
|
-
* and a delivery outside the tolerance window is rejected even when its signature is valid.
|
|
36
|
-
*
|
|
37
|
-
* The body must be the raw bytes. A framework that parses JSON before your handler runs has already
|
|
38
|
-
* destroyed the thing being signed — re-serializing it produces different bytes and the check fails.
|
|
39
|
-
*
|
|
40
|
-
* @example
|
|
41
|
-
* ```ts
|
|
42
|
-
* const raw = await request.text();
|
|
43
|
-
* const trusted = await andCoWebhookVerify({
|
|
44
|
-
* body: raw,
|
|
45
|
-
* signature: request.headers.get(ANDCO_WEBHOOK_HEADERS.signature),
|
|
46
|
-
* eventId: request.headers.get(ANDCO_WEBHOOK_HEADERS.eventId),
|
|
47
|
-
* timestamp: request.headers.get(ANDCO_WEBHOOK_HEADERS.timestamp),
|
|
48
|
-
* secret: process.env.ANDCO_WEBHOOK_SECRET!,
|
|
49
|
-
* });
|
|
50
|
-
* if (!trusted) return new Response(null, { status: 400 });
|
|
51
|
-
* ```
|
|
52
|
-
*/
|
|
53
|
-
export declare function andCoWebhookVerify(input: AndCoWebhookVerifyInput): Promise<boolean>;
|
|
54
|
-
//# sourceMappingURL=webhook-signature.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"webhook-signature.d.ts","sourceRoot":"","sources":["../src/webhook-signature.ts"],"names":[],"mappings":"AAAA,wDAAwD;AACxD,eAAO,MAAM,qBAAqB;;;;CAIxB,CAAC;AAEX,gEAAgE;AAChE,eAAO,MAAM,+BAA+B,MAAM,CAAC;AAInD,+EAA+E;AAC/E,MAAM,MAAM,uBAAuB,GAAG;IACpC,oEAAoE;IACpE,IAAI,EAAE,MAAM,CAAC;IACb,qDAAqD;IACrD,SAAS,EAAE,MAAM,GAAG,IAAI,GAAG,SAAS,CAAC;IACrC,wBAAwB;IACxB,OAAO,EAAE,MAAM,GAAG,IAAI,GAAG,SAAS,CAAC;IACnC,qCAAqC;IACrC,SAAS,EAAE,MAAM,GAAG,IAAI,GAAG,SAAS,CAAC;IACrC,yCAAyC;IACzC,MAAM,EAAE,MAAM,GAAG,UAAU,CAAC;IAC5B,0EAA0E;IAC1E,gBAAgB,CAAC,EAAE,MAAM,CAAC;IAC1B,0CAA0C;IAC1C,GAAG,CAAC,EAAE,MAAM,CAAC;CACd,CAAC;AAEF;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;AACH,wBAAsB,kBAAkB,CAAC,KAAK,EAAE,uBAAuB,GAAG,OAAO,CAAC,OAAO,CAAC,CA0BzF"}
|
|
@@ -1,74 +0,0 @@
|
|
|
1
|
-
/** Header names Andco signs a webhook delivery with. */
|
|
2
|
-
export const ANDCO_WEBHOOK_HEADERS = {
|
|
3
|
-
signature: "andco-signature",
|
|
4
|
-
eventId: "andco-event-id",
|
|
5
|
-
timestamp: "andco-timestamp",
|
|
6
|
-
};
|
|
7
|
-
/** Default tolerance for the delivery timestamp, in seconds. */
|
|
8
|
-
export const ANDCO_WEBHOOK_TOLERANCE_SECONDS = 300;
|
|
9
|
-
const SIGNATURE_PREFIX = "v1=";
|
|
10
|
-
/**
|
|
11
|
-
* Whether a webhook delivery really came from Andco.
|
|
12
|
-
*
|
|
13
|
-
* The signature covers `{timestamp}.{eventId}.{body}`, so it binds the payload to one delivery and
|
|
14
|
-
* one moment: replaying an old body under a new timestamp does not verify, and neither does
|
|
15
|
-
* reusing a valid signature for a different event.
|
|
16
|
-
*
|
|
17
|
-
* Two details are easy to get wrong when this is written by hand, and both are handled here: the
|
|
18
|
-
* comparison is constant-time, so a wrong signature leaks nothing through how long the check takes,
|
|
19
|
-
* and a delivery outside the tolerance window is rejected even when its signature is valid.
|
|
20
|
-
*
|
|
21
|
-
* The body must be the raw bytes. A framework that parses JSON before your handler runs has already
|
|
22
|
-
* destroyed the thing being signed — re-serializing it produces different bytes and the check fails.
|
|
23
|
-
*
|
|
24
|
-
* @example
|
|
25
|
-
* ```ts
|
|
26
|
-
* const raw = await request.text();
|
|
27
|
-
* const trusted = await andCoWebhookVerify({
|
|
28
|
-
* body: raw,
|
|
29
|
-
* signature: request.headers.get(ANDCO_WEBHOOK_HEADERS.signature),
|
|
30
|
-
* eventId: request.headers.get(ANDCO_WEBHOOK_HEADERS.eventId),
|
|
31
|
-
* timestamp: request.headers.get(ANDCO_WEBHOOK_HEADERS.timestamp),
|
|
32
|
-
* secret: process.env.ANDCO_WEBHOOK_SECRET!,
|
|
33
|
-
* });
|
|
34
|
-
* if (!trusted) return new Response(null, { status: 400 });
|
|
35
|
-
* ```
|
|
36
|
-
*/
|
|
37
|
-
export async function andCoWebhookVerify(input) {
|
|
38
|
-
const { body, signature, eventId, timestamp, secret } = input;
|
|
39
|
-
if (!signature || !eventId || !timestamp)
|
|
40
|
-
return false;
|
|
41
|
-
if (!signature.startsWith(SIGNATURE_PREFIX))
|
|
42
|
-
return false;
|
|
43
|
-
const seconds = Number(timestamp);
|
|
44
|
-
if (!Number.isFinite(seconds))
|
|
45
|
-
return false;
|
|
46
|
-
const now = input.now ?? Math.floor(Date.now() / 1_000);
|
|
47
|
-
const tolerance = input.toleranceSeconds ?? ANDCO_WEBHOOK_TOLERANCE_SECONDS;
|
|
48
|
-
if (Math.abs(now - seconds) > tolerance)
|
|
49
|
-
return false;
|
|
50
|
-
const provided = decodeHex(signature.slice(SIGNATURE_PREFIX.length));
|
|
51
|
-
if (!provided)
|
|
52
|
-
return false;
|
|
53
|
-
const key = await crypto.subtle.importKey("raw", typeof secret === "string" ? new TextEncoder().encode(secret) : secret, { name: "HMAC", hash: "SHA-256" }, false, ["sign"]);
|
|
54
|
-
const expected = new Uint8Array(await crypto.subtle.sign("HMAC", key, new TextEncoder().encode(`${timestamp}.${eventId}.${body}`)));
|
|
55
|
-
return timingSafeEqual(provided, expected);
|
|
56
|
-
}
|
|
57
|
-
function decodeHex(value) {
|
|
58
|
-
if (value.length === 0 || value.length % 2 !== 0 || !/^[0-9a-fA-F]+$/.test(value))
|
|
59
|
-
return null;
|
|
60
|
-
const bytes = new Uint8Array(value.length / 2);
|
|
61
|
-
for (let index = 0; index < bytes.length; index += 1) {
|
|
62
|
-
bytes[index] = Number.parseInt(value.slice(index * 2, index * 2 + 2), 16);
|
|
63
|
-
}
|
|
64
|
-
return bytes;
|
|
65
|
-
}
|
|
66
|
-
/** Compares in time that does not depend on where the first difference is. */
|
|
67
|
-
function timingSafeEqual(a, b) {
|
|
68
|
-
if (a.length !== b.length)
|
|
69
|
-
return false;
|
|
70
|
-
let difference = 0;
|
|
71
|
-
for (let index = 0; index < a.length; index += 1)
|
|
72
|
-
difference |= a[index] ^ b[index];
|
|
73
|
-
return difference === 0;
|
|
74
|
-
}
|