@andco/protocol 0.0.14 → 0.1.0-ti.0
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/README.md +2 -2
- package/dist/api-errors.d.ts +9 -9
- package/dist/api-errors.js +9 -9
- package/dist/authorization-preparation.d.ts +1 -1
- package/dist/authorization-preparation.js +2 -2
- package/dist/authorization.d.ts +1 -1
- package/dist/authorization.js +1 -1
- package/dist/consent.d.ts +2 -2
- package/dist/consent.js +2 -2
- package/dist/errors.d.ts +10 -10
- package/dist/errors.js +10 -10
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -0
- package/dist/intent-input.d.ts +452 -880
- package/dist/intent-input.d.ts.map +1 -1
- package/dist/intent-input.js +164 -127
- package/dist/intent-status.d.ts +5 -6
- package/dist/intent-status.d.ts.map +1 -1
- package/dist/intent-status.js +12 -7
- package/dist/miniapp-manifest.d.ts +3 -3
- package/dist/miniapp-manifest.js +1 -1
- package/dist/native-intent.d.ts +82 -68
- package/dist/native-intent.d.ts.map +1 -1
- package/dist/native-intent.js +137 -84
- package/dist/native.d.ts +1 -1
- package/dist/rar/account-matchers.d.ts +35 -30
- package/dist/rar/account-matchers.d.ts.map +1 -1
- package/dist/rar/account-matchers.js +27 -21
- package/dist/rar/bank.d.ts +357 -85
- package/dist/rar/bank.d.ts.map +1 -1
- package/dist/rar/bank.js +43 -5
- package/dist/rar/catalog.d.ts +174 -49
- package/dist/rar/catalog.d.ts.map +1 -1
- package/dist/rar/catalog.js +6 -6
- package/dist/rar/detail.d.ts +1 -1
- package/dist/rar/detail.js +1 -1
- package/dist/rar/json-schemas.generated.d.ts +1 -1
- package/dist/rar/json-schemas.generated.d.ts.map +1 -1
- package/dist/rar/json-schemas.generated.js +393 -21
- package/dist/rar/money.d.ts +1 -1
- package/dist/rar/money.js +1 -1
- package/dist/rar/subject-data.d.ts +1 -1
- package/dist/rar/subject-data.js +1 -1
- package/dist/rar/subject.d.ts +1 -1
- package/dist/rar/subject.js +1 -1
- package/dist/rest/accounts.d.ts +28 -28
- package/dist/rest/accounts.d.ts.map +1 -1
- package/dist/rest/accounts.js +22 -22
- package/dist/rest/api-error.d.ts +1 -1
- package/dist/rest/api-error.js +1 -1
- package/dist/rest/catalog.d.ts +3 -3
- package/dist/rest/catalog.js +2 -2
- package/dist/rest/common.d.ts +3 -3
- package/dist/rest/common.js +3 -3
- package/dist/rest/contract.d.ts +1183 -547
- package/dist/rest/contract.d.ts.map +1 -1
- package/dist/rest/contract.js +21 -5
- package/dist/rest/events.d.ts +1 -1
- package/dist/rest/events.d.ts.map +1 -1
- package/dist/rest/events.js +2 -2
- package/dist/rest/identity.d.ts +22 -22
- package/dist/rest/identity.d.ts.map +1 -1
- package/dist/rest/identity.js +5 -5
- package/dist/rest/index.d.ts +1 -0
- package/dist/rest/index.d.ts.map +1 -1
- package/dist/rest/index.js +1 -0
- package/dist/rest/intents.d.ts +973 -743
- package/dist/rest/intents.d.ts.map +1 -1
- package/dist/rest/intents.js +112 -89
- package/dist/rest/signatures.d.ts +25 -5
- package/dist/rest/signatures.d.ts.map +1 -1
- package/dist/rest/signatures.js +52 -0
- package/dist/rest/transfers.d.ts +988 -0
- package/dist/rest/transfers.d.ts.map +1 -0
- package/dist/rest/transfers.js +142 -0
- package/dist/scopes.d.ts +1 -1
- package/dist/signing.d.ts +17 -3
- package/dist/signing.d.ts.map +1 -1
- package/dist/signing.js +8 -1
- package/dist/transfer.d.ts +399 -0
- package/dist/transfer.d.ts.map +1 -0
- package/dist/transfer.js +313 -0
- package/dist/transport/financial-events.d.ts +82 -27
- package/dist/transport/financial-events.d.ts.map +1 -1
- package/dist/transport/financial-events.js +34 -0
- package/dist/transport/generated/oauth-api.d.ts +1420 -333
- package/dist/transport/generated/oauth-api.d.ts.map +1 -1
- package/dist/transport/intents.d.ts +29 -13
- package/dist/transport/intents.d.ts.map +1 -1
- package/dist/transport/intents.js +1 -1
- package/dist/transport/rest.d.ts +5 -5
- package/dist/urls.d.ts +2 -2
- package/dist/urls.js +3 -3
- package/dist/userinfo.d.ts +2 -2
- package/dist/userinfo.js +2 -2
- package/dist/webhooks.d.ts +16 -16
- package/dist/webhooks.js +14 -14
- package/dist/window-features.d.ts +2 -2
- package/dist/window-features.js +2 -2
- package/package.json +2 -2
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"transfers.d.ts","sourceRoot":"","sources":["../../src/rest/transfers.ts"],"names":[],"mappings":"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"}
|
|
@@ -0,0 +1,142 @@
|
|
|
1
|
+
import { oc } from "@orpc/contract";
|
|
2
|
+
import * as v from "valibot";
|
|
3
|
+
import { PesosSchema, SignedTransferEnvelopeSchema, SignedTransferJtiSchema, TransferPartySchema, } from "../transfer.js";
|
|
4
|
+
import { InvalidCursor } from "./accounts.js";
|
|
5
|
+
import { AndcoAPIError, errors } from "./api-error.js";
|
|
6
|
+
import { connection, cursorlessConnection, ForwardPageQuery, InsufficientAuthorization, InvalidIdentifier, InvalidOrigin, InvalidRequest, InvalidToken, NotFound, PayloadTooLarge, ServerError, TemporarilyUnavailable, UnsupportedMediaType, UnsupportedVersion, } from "./common.js";
|
|
7
|
+
import { http } from "./http.js";
|
|
8
|
+
import { AmountOutOfGrant, ApprovalRequiredUseIntents, BankConnectionUnavailable, BankRefused, BankRejected, BankReviewRequired, ExpiredSignedInstruction, IdempotencyConflict, IdempotencyKeyNotAllowed, InsufficientFunds, IntentInteractionRequired, InvalidDestination, InvalidSignedInstruction, InvalidSource, NotImplemented, TransferSenderIdentityUnavailable, } from "./intents.js";
|
|
9
|
+
import { SIGNED_TRANSFER_MEDIA_TYPE } from "./signatures.js";
|
|
10
|
+
export { SIGNED_TRANSFER_MEDIA_TYPE };
|
|
11
|
+
const uuid = /* @__PURE__ */ v.pipe(v.string(), v.uuid());
|
|
12
|
+
const dateTime = /* @__PURE__ */ v.pipe(v.string(), v.isoTimestamp());
|
|
13
|
+
/**
|
|
14
|
+
* oRPC describes a request body as `application/json`. A signed transfer travels as
|
|
15
|
+
* `application/jose+json` instead, the same JSON object under the media type RFC 7515 gives it: this
|
|
16
|
+
* moves the body there. It is the `spec` of `createTransfer`'s {@link http} meta.
|
|
17
|
+
*/
|
|
18
|
+
function servedAsSignedTransfer(operation) {
|
|
19
|
+
const requestBody = operation["requestBody"];
|
|
20
|
+
const json = requestBody?.content?.["application/json"];
|
|
21
|
+
if (requestBody === undefined || json === undefined) {
|
|
22
|
+
throw new Error("The operation has no JSON body to serve as a signed transfer.");
|
|
23
|
+
}
|
|
24
|
+
return { ...operation, requestBody: { ...requestBody, content: { [SIGNED_TRANSFER_MEDIA_TYPE]: json } } };
|
|
25
|
+
}
|
|
26
|
+
// -- Errors -------------------------------------------------------------------------------------
|
|
27
|
+
/**
|
|
28
|
+
* The signed `sender` is not the account it names: its `country` is `CL`, its `bank_code` AndCo's
|
|
29
|
+
* (`0739`), its `account_type` the account's own and its `national_id` the RUT of the account's
|
|
30
|
+
* holder, compared as normalized RUTs. Its `name` is never compared. The API runs this check
|
|
31
|
+
* before anything is stored, so the mistake fails early.
|
|
32
|
+
*/
|
|
33
|
+
export class SenderMismatch extends /* @__PURE__ */ AndcoAPIError.define("sender_mismatch", 422, v.pipe(v.object({}), v.description("The signed sender is not the account: country `CL`, bank `0739`, its own account type and its holder's RUT."))) {
|
|
34
|
+
constructor(message) {
|
|
35
|
+
super({}, message);
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
// -- Transfers ----------------------------------------------------------------------------------
|
|
39
|
+
/**
|
|
40
|
+
* Where a Transfer stands. `requires_action`: the person still owes the bank a step. `processing`: the
|
|
41
|
+
* bank holds the transfer and has not answered for good. `succeeded`, `failed` and `cancelled` are final.
|
|
42
|
+
* There is no `rejected`: a rejection ends an Intent, and a rejected Intent has no Transfer.
|
|
43
|
+
*/
|
|
44
|
+
export const TransferStatus = /* @__PURE__ */ v.pipe(v.picklist(["requires_action", "processing", "succeeded", "failed", "cancelled"]), v.description("Where the Transfer stands: `requires_action` while the person still owes the bank a step, `processing` while the bank holds it and has not answered for good, then `succeeded`, `failed` or `cancelled`, which are final. `status_detail` says why. There is no `rejected` Transfer: a rejection ends an Intent, and a rejected Intent has no Transfer."));
|
|
45
|
+
/**
|
|
46
|
+
* A Transfer: the movement of an amount from a Remitente (`sender`) to a Receptor (`receiver`), as
|
|
47
|
+
* AndCo represents it. It has one shape for every origin: a Project's Intent (`oauth`), a person in
|
|
48
|
+
* the AndCo web app (`platform`), or the issuer's own channels, for example its mobile app
|
|
49
|
+
* (`emisor`). A Transfer exists after its approval.
|
|
50
|
+
*
|
|
51
|
+
* @example
|
|
52
|
+
* const transfer: Transfer = {
|
|
53
|
+
* object: "transfer", id, status: "succeeded", status_detail: "confirmed", origin: "oauth",
|
|
54
|
+
* amount: 500000, currency: "CLP", sender, receiver, comment: "Factura 42",
|
|
55
|
+
* intent_id, jti: null, transaction_id: "88213", created_at,
|
|
56
|
+
* };
|
|
57
|
+
*/
|
|
58
|
+
export const Transfer = /* @__PURE__ */ v.pipe(v.strictObject({
|
|
59
|
+
object: v.literal("transfer"),
|
|
60
|
+
id: v.pipe(uuid, v.description("The Transfer's own id: what `GET /transfers/{transfer_id}` reads.")),
|
|
61
|
+
status: TransferStatus,
|
|
62
|
+
status_detail: v.pipe(v.nullable(v.string()), v.description("The word that says why, null when the status has none: `bank_refused` for a `failed` Transfer the bank refused for sure, `expired` for a `cancelled` one whose deadline passed, `grant_revoked` or `grant_expired` for one whose Grant ended. The vocabulary is open: a detail added later appears here as it is, so decide on `status`.")),
|
|
63
|
+
origin: v.pipe(v.picklist(["oauth", "platform", "emisor"]), v.description("Who made it: `oauth`, a Project through the API; `platform`, a person in the AndCo web app; `emisor`, a person in the issuer's own channels, for example its mobile app.")),
|
|
64
|
+
amount: v.pipe(PesosSchema, v.description("An integer in the minor unit of the currency (CLP: whole pesos), from 1 to 2147483647.")),
|
|
65
|
+
currency: v.literal("CLP"),
|
|
66
|
+
sender: v.pipe(TransferPartySchema, v.description("The Remitente: the account the money leaves and its holder.")),
|
|
67
|
+
receiver: v.pipe(TransferPartySchema, v.description("The Receptor: the account the money lands on and its holder.")),
|
|
68
|
+
comment: v.pipe(v.nullable(v.string()), v.description("The Nota de operación, at most 60 bytes of UTF-8, or null when there is none.")),
|
|
69
|
+
intent_id: v.pipe(v.nullable(uuid), v.description("The Intent this Transfer came from. Null for origin `emisor` (no request came first) and for a signed transfer with `approved: true` (its signature approved it, so there was no request).")),
|
|
70
|
+
jti: v.pipe(v.nullable(SignedTransferJtiSchema), v.description("The `jti` of the signed transfer with `approved: true` that submitted it, a UUID in lowercase. Null for any other Transfer: the `jti` of a signed Intent stays on the Intent. `GET /transfers?jti=` finds only a Transfer that has one.")),
|
|
71
|
+
transaction_id: v.pipe(v.nullable(v.string()), v.description("The ledger id of the debit once the Transfer succeeded, else null. A Movement carries the same id.")),
|
|
72
|
+
created_at: v.pipe(dateTime, v.description("When the Transfer came to exist.")),
|
|
73
|
+
}), v.description("A Transfer, with one shape for every origin. `sender` and `receiver` have the same fields, and `amount` and `currency` sit on the Transfer. It has no `approved` and no deadline: the decision belongs to the Intent."));
|
|
74
|
+
// -- Operations ---------------------------------------------------------------------------------
|
|
75
|
+
/** Submits a signed transfer: one General JSON JWS (`application/jose+json`), one Transfer. */
|
|
76
|
+
export const createTransfer = /* @__PURE__ */ oc
|
|
77
|
+
.meta(http({
|
|
78
|
+
method: "POST",
|
|
79
|
+
path: "/transfers",
|
|
80
|
+
summary: "Submit a signed transfer",
|
|
81
|
+
description: "Submits one Transfer as a Signed Instruction: a `SignedTransferEnvelope`, a JWS in the General JSON Serialization sent as `application/jose+json`, whose payload is `SignedTransferClaims`. Every value the operation uses comes from the verified claims; the envelope is kept unchanged. Any other `Content-Type` answers `415 unsupported_media_type`, and an `Idempotency-Key` header `400 idempotency_key_not_allowed`: the `jti` is the idempotency-key.\n\nThe signature is the approval: the claims must have `approved: true`, and the Transfer exists as soon as it is submitted, with no decision to wait for. A signed transfer with `approved: false` answers `400 approval_required_use_intents` and nothing is stored: send it to `POST /intents`, which creates an Intent that waits for a decision.\n\nBefore anything is stored: the token's Grant must hold `bank_transfer` `create` (`403 insufficient_authorization`). The envelope must have its shape and at least one signature, each with a protected header of `typ` `transfer.v1+jwt` (`400 invalid_signed_instruction` with `reason` `malformed_assertion` and its `issues`, or `missing_signature`). Every signature must verify, each with a key registered under a Project of the holder, the Grant's subject: `unknown_key` (a `kid` that is no key of the holder's Projects, a key of another holder included), `revoked_key`, `expired_key`, `unusable_key`, `disallowed_algorithm` or `invalid_signature`. `unusable_key` means that the key is registered, but AndCo could not load it to check this signature: its person registers a new key and revokes this one, then you sign again. The claims must be `SignedTransferClaims` (`invalid_claims` with `issues`; the `jti` must be a UUID in lowercase) and `iss` the presenting client (`wrong_issuer`); an `exp` that passed answers `401 expired_signed_instruction`, and the `exp` of a new `jti` less than 15 minutes after the submission `400 invalid_signed_instruction` with `reason` `expiration_too_soon` (nothing is stored), so sign with an `exp` at least 15 minutes ahead (`bank-sdk` signs 30 minutes ahead). The floor applies only to a new `jti`: the same instruction sent again (same `jti`, same content) is never refused for it, however little of its `exp` is left, and answers or releases the same Transfer as before. That is how a stored Transfer is released after `409 interaction_required` or `503 temporarily_unavailable`. A client that lost the answer can also read the Transfer with `GET /transfers?jti=`, which finds it even after its `exp`. The `sender` must be an AndCo account of the holder that the Grant's `sources` cover (`422 invalid_source`, found by its `account_number`) and must match it (`422 sender_mismatch`; `422 transfer_sender_identity_unavailable` while AndCo knows no RUT for the holder). The Grant's `destinations` must cover the `receiver` (`422 invalid_destination`) and its limits the amount (`422 amount_out_of_grant`). The signed transfer needs `bank_transfer` `approve` within its maximum: `403 insufficient_authorization` otherwise, never a transfer that waits silently.\n\nThe same `jti` with the same claims answers the same Transfer and never moves money twice; the same `jti` with any other content, `exp` included, answers `409 idempotency_conflict`. To sign again with a new `exp`, use a new `jti`.\n\nA key that AndCo does not accept yet for signed transfers answers `unsynced_key`.\n\nA transfer between two accounts of the same holder works where AndCo serves that rail (otherwise `501 not_implemented` with `code: own_account_transfer_not_implemented`): it is released at once with nobody present and answers `processing` or `succeeded`, or the release's refusals of `POST /intents/{intent_id}/approve` (`409 interaction_required` with `bank_connection_*` when the web session that acts for the holder needs its person; sending the same instruction again once they acted releases it). A transfer that leaves its holder answers `501 not_implemented` with `code: signed_outgoing_transfer_not_implemented` while AndCo does not serve that rail, and nothing is created; otherwise it is sent at once with nobody present: no web AndPass and no SMS code, because the signature itself authorizes it. It is still screened. It answers `processing` once AndCo accepts it, and later `succeeded`; it answers `failed` with its `status_detail` when the screening refuses it (`fraud_rejected`), when the signature is refused (`unknown_key`, `revoked_key`, `invalid_signature`, `expired_signed_instruction`, `sender_mismatch`) or when the bank refuses the request (`bank_refused`). A signature that needs a proof only a person can give fails too: send the same transfer as an Intent that a person confirms. On either rail, a key that signed it and is revoked or expired when the Transfer executes fails it with `expired_key` or `revoked_key`, even if the key was valid at submission, and nothing is sent; so does a key AndCo no longer holds, with `unknown_key`, for one that leaves its holder. While no final answer is known it reads `processing`: read it later with `GET /transfers/{transfer_id}`, or send the same envelope again, which never moves money twice. `503 temporarily_unavailable` means it was stored and not sent, because the sender account already had two transfer evaluations in the last minute (the `message` says until when): send the same envelope again after that. `409 interaction_required` with `bank_connection_*` means the web session that acts for the holder needs its person, and nothing was created.",
|
|
82
|
+
successStatus: 201,
|
|
83
|
+
successDescription: "The Transfer submitted, or the same one from a repeated instruction",
|
|
84
|
+
spec: servedAsSignedTransfer,
|
|
85
|
+
}))
|
|
86
|
+
.errors(errors(InvalidRequest, IdempotencyKeyNotAllowed, ApprovalRequiredUseIntents, InvalidSignedInstruction, InvalidToken, ExpiredSignedInstruction, InvalidOrigin, InsufficientAuthorization, UnsupportedVersion, ServerError, IdempotencyConflict, IntentInteractionRequired, PayloadTooLarge, UnsupportedMediaType, SenderMismatch, TransferSenderIdentityUnavailable, AmountOutOfGrant, InvalidSource, InvalidDestination, BankConnectionUnavailable, BankRefused, InsufficientFunds, BankRejected, BankReviewRequired, NotImplemented, TemporarilyUnavailable))
|
|
87
|
+
.input(SignedTransferEnvelopeSchema)
|
|
88
|
+
.output(Transfer);
|
|
89
|
+
/** Reads one Transfer the Grant may read. */
|
|
90
|
+
export const getTransfer = /* @__PURE__ */ oc
|
|
91
|
+
.meta(http({
|
|
92
|
+
method: "GET",
|
|
93
|
+
path: "/transfers/{transfer_id}",
|
|
94
|
+
summary: "Read one Transfer",
|
|
95
|
+
description: "A client reads the Transfers that it created for the same subject, under any of its active Grants that holds `bank_transfer` `create`, `approve` or `reject`. A Grant with `bank_transfer` `read` also reads the Transfers of any origin whose sender account it covers. Any other Transfer answers `404`, as if it did not exist.",
|
|
96
|
+
successDescription: "The Transfer",
|
|
97
|
+
}))
|
|
98
|
+
.errors(errors(InvalidIdentifier, InvalidToken, InvalidOrigin, NotFound, UnsupportedVersion, ServerError, TemporarilyUnavailable))
|
|
99
|
+
.input(v.object({ transfer_id: uuid }))
|
|
100
|
+
.output(Transfer);
|
|
101
|
+
/**
|
|
102
|
+
* A page of Transfers found by `jti`: zero or one edge, and no cursor on it. The list of an account
|
|
103
|
+
* has its own page, {@link TransferListPage}.
|
|
104
|
+
*/
|
|
105
|
+
export const TransferPage = /* @__PURE__ */ cursorlessConnection(Transfer, "A connection of the Transfers that `GET /transfers?jti=` found: zero edges or one, and an edge's `cursor` is null, because AndCo names no position inside it. The list of an account has its own page, `TransferListPage`, with a cursor on each edge.");
|
|
106
|
+
/**
|
|
107
|
+
* Finds the Transfer that a `jti` names: for a client that lost the answer to `POST /transfers` and
|
|
108
|
+
* whose `exp` has passed.
|
|
109
|
+
*/
|
|
110
|
+
export const listTransfers = /* @__PURE__ */ oc
|
|
111
|
+
.meta(http({
|
|
112
|
+
method: "GET",
|
|
113
|
+
path: "/transfers",
|
|
114
|
+
summary: "Find a Transfer by the jti of its signed instruction",
|
|
115
|
+
description: "It finds one Transfer by the `jti` of the signed transfer with `approved: true` that submitted it, and `jti` is required (`400 invalid_request` when it is missing or is not a UUID in lowercase). The answer is a collection of zero or one Transfer, with the reach of `GET /transfers/{transfer_id}`. A `jti` belongs to the client and the Grant's subject, across the client's Grants: a `jti` that another client or another subject used finds nothing, and so does the `jti` of a signed Intent, which stays on the Intent. The collection is empty in those cases, so no answer tells them apart. It finds a Transfer whose `exp` has passed, which is its purpose: after a lost answer to `POST /transfers`, read by `jti` before signing again. To list the Transfers of an account, use `GET /accounts/{bank_account_id}/transfers`.",
|
|
116
|
+
successDescription: "The Transfers found: zero or one",
|
|
117
|
+
}))
|
|
118
|
+
.errors(errors(InvalidRequest, InvalidToken, InvalidOrigin, UnsupportedVersion, ServerError, TemporarilyUnavailable))
|
|
119
|
+
.input(v.object({
|
|
120
|
+
jti: v.pipe(SignedTransferJtiSchema, v.description("The `jti` of the signed transfer that submitted the Transfer, a UUID in lowercase.")),
|
|
121
|
+
}))
|
|
122
|
+
.output(TransferPage);
|
|
123
|
+
/**
|
|
124
|
+
* A page of the Transfers of one account, newest first, with a cursor on each edge. The cursor
|
|
125
|
+
* encodes the order key, so it stays stable when new Transfers arrive.
|
|
126
|
+
*/
|
|
127
|
+
export const TransferListPage = /* @__PURE__ */ connection(Transfer, "A connection of Transfers, newest first, walked forward with `after` and `first`. Each edge has its own opaque `cursor`, which encodes the order key (creation time and id), so a walk never skips or repeats a Transfer when new ones arrive. `pageInfo.endCursor` is the cursor of the last edge, and `hasNextPage` is false when no Transfer follows, also on a page of exactly `first` items.");
|
|
128
|
+
/** Lists the Transfers whose sender is one account, newest first. */
|
|
129
|
+
export const listAccountTransfers = /* @__PURE__ */ oc
|
|
130
|
+
.meta(http({
|
|
131
|
+
method: "GET",
|
|
132
|
+
path: "/accounts/{bank_account_id}/transfers",
|
|
133
|
+
summary: "List the Transfers that leave one account",
|
|
134
|
+
description: "The Transfers whose sender is this account, newest first, one page at a time: feed `pageInfo.endCursor` back as `?after=` while `pageInfo.hasNextPage`. The account is named by its identifier or by its Account Key, whichever the integrator knows: a segment shaped like a UUID is an identifier, any other is an Account Key of the Grant's subject. An account the Grant does not reach, by identifier or by key, and a key that names no account of the subject answer `404`, as if it did not exist. With a `bank_transfer` `read` detail whose `accounts` reach the account, the page holds every Transfer that leaves it, in any status (failed and cancelled included) and of any origin: another Project, the AndCo web app or the issuer's own channels. Without `read`, the page holds only the Transfers that this client created for the same subject, under any of its active Grants that holds `bank_transfer` `create`, `approve` or `reject`, in any status. The route never answers `403` for a narrower Grant: it answers a smaller page, which can be empty. It holds no Intent and no draft: the Intents stay under `/intents`. Money that arrives in the account is not a Transfer of it: it shows as a credit Movement. Each edge has its own cursor, which stays stable when new Transfers arrive. `before`, `last`, `offset` and `limit` answer `invalid_request`.",
|
|
135
|
+
successDescription: "A page of Transfers, newest first",
|
|
136
|
+
}))
|
|
137
|
+
.errors(errors(InvalidRequest, InvalidCursor, InvalidToken, InvalidOrigin, NotFound, UnsupportedVersion, ServerError, TemporarilyUnavailable))
|
|
138
|
+
.input(v.object({
|
|
139
|
+
bank_account_id: v.pipe(v.string(), v.maxLength(64), v.description("The account's identifier (a UUID) or its Account Key.")),
|
|
140
|
+
...ForwardPageQuery,
|
|
141
|
+
}))
|
|
142
|
+
.output(TransferListPage);
|
package/dist/scopes.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* OAuth scopes
|
|
2
|
+
* OAuth scopes AndCo supports, suggested by TypeScript editors: OpenID Connect and session concerns
|
|
3
3
|
* only. Every resource permission is an authorization detail (`identity`, `address`, `bank_account`…).
|
|
4
4
|
*/
|
|
5
5
|
export type AndCoKnownScope = "openid" | "email" | "profile" | "phone" | "offline_access";
|
package/dist/signing.d.ts
CHANGED
|
@@ -8,13 +8,16 @@
|
|
|
8
8
|
* `globalThis.crypto.subtle`, which every runtime the SDK targets (Node 18+, browsers, Bun) already
|
|
9
9
|
* carries.
|
|
10
10
|
*/
|
|
11
|
-
/**
|
|
11
|
+
/**
|
|
12
|
+
* JWS `alg` values the signer can produce. The Platform registers only `ES256` (EC P-256) and `RS256`
|
|
13
|
+
* (RSA 2048 to 8192 bits) as Signing Keys, so a transfer refuses the others.
|
|
14
|
+
*/
|
|
12
15
|
export type AndCoSigningAlgorithm = "ES256" | "ES384" | "ES512" | "RS256" | "EdDSA";
|
|
13
16
|
/**
|
|
14
17
|
* A Signing Key bound once to its `kid` and algorithm, ready to sign any number of claim sets.
|
|
15
18
|
*
|
|
16
19
|
* Built with {@link createAndCoSigner} and passed by call, never constructed by hand: the only
|
|
17
|
-
* public surface is {@link AndCoSigner.sign}, so nothing here can produce a header a caller typed
|
|
20
|
+
* public surface is {@link AndCoSigner.sign} and {@link AndCoSigner.signTransfer}, so nothing here can produce a header a caller typed
|
|
18
21
|
* incorrectly.
|
|
19
22
|
*/
|
|
20
23
|
export type AndCoSigner = {
|
|
@@ -29,6 +32,16 @@ export type AndCoSigner = {
|
|
|
29
32
|
* because the whole reason this type exists is that a caller never has to think about it.
|
|
30
33
|
*/
|
|
31
34
|
sign(claims: Record<string, unknown>): Promise<string>;
|
|
35
|
+
/**
|
|
36
|
+
* Signs a transfer's payload for one signature of a General JSON JWS (RFC 7515 §7.2.1). `payload` is
|
|
37
|
+
* the base64url of the claims, the same string for every key that signs the transfer; the protected
|
|
38
|
+
* header is always exactly `{ alg, kid, typ: "transfer.v1+jwt" }`. The signature covers
|
|
39
|
+
* `protected.payload`. It does not check `alg`: whether the Platform accepts it is its answer to give.
|
|
40
|
+
*/
|
|
41
|
+
signTransfer(payload: string): Promise<{
|
|
42
|
+
protected: string;
|
|
43
|
+
signature: string;
|
|
44
|
+
}>;
|
|
32
45
|
};
|
|
33
46
|
/** Input accepted by {@link createAndCoSigner}. */
|
|
34
47
|
export type AndCoSignerOptions = {
|
|
@@ -45,7 +58,8 @@ export declare class AndCoSignerError extends Error {
|
|
|
45
58
|
* The algorithm is read from the key itself -- an EC key's curve OID selects `ES256`/`ES384`/
|
|
46
59
|
* `ES512`, an RSA key signs `RS256`, and Ed25519 signs `EdDSA` -- so passing the wrong key never
|
|
47
60
|
* produces a mismatched header, and there is nothing about the algorithm for a caller to get wrong.
|
|
48
|
-
* An RSA key under 2048 bits throws {@link AndCoSignerError}.
|
|
61
|
+
* An RSA key under 2048 bits throws {@link AndCoSignerError}. The signer builds more kinds of key than
|
|
62
|
+
* the Platform registers: only ES256 (P-256) and RS256 are Signing Keys there.
|
|
49
63
|
*
|
|
50
64
|
* @example
|
|
51
65
|
* ```ts
|
package/dist/signing.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"signing.d.ts","sourceRoot":"","sources":["../src/signing.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;
|
|
1
|
+
{"version":3,"file":"signing.d.ts","sourceRoot":"","sources":["../src/signing.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAIH;;;GAGG;AACH,MAAM,MAAM,qBAAqB,GAAG,OAAO,GAAG,OAAO,GAAG,OAAO,GAAG,OAAO,GAAG,OAAO,CAAC;AAEpF;;;;;;GAMG;AACH,MAAM,MAAM,WAAW,GAAG;IACxB,gFAAgF;IAChF,QAAQ,CAAC,GAAG,EAAE,MAAM,CAAC;IACrB,mFAAmF;IACnF,QAAQ,CAAC,GAAG,EAAE,qBAAqB,CAAC;IACpC;;;;;OAKG;IACH,IAAI,CAAC,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,OAAO,CAAC,MAAM,CAAC,CAAC;IACvD;;;;;OAKG;IACH,YAAY,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC;QAAE,SAAS,EAAE,MAAM,CAAC;QAAC,SAAS,EAAE,MAAM,CAAA;KAAE,CAAC,CAAC;CAClF,CAAC;AAEF,mDAAmD;AACnD,MAAM,MAAM,kBAAkB,GAAG;IAC/B,2CAA2C;IAC3C,UAAU,EAAE,MAAM,CAAC;CACpB,CAAC;AAEF,mFAAmF;AACnF,qBAAa,gBAAiB,SAAQ,KAAK;gBACtB,OAAO,EAAE,MAAM;CAInC;AAoBD;;;;;;;;;;;;;;GAcG;AACH,wBAAsB,iBAAiB,CAAC,OAAO,EAAE,kBAAkB,GAAG,OAAO,CAAC,WAAW,CAAC,CAqDzF"}
|
package/dist/signing.js
CHANGED
|
@@ -8,6 +8,7 @@
|
|
|
8
8
|
* `globalThis.crypto.subtle`, which every runtime the SDK targets (Node 18+, browsers, Bun) already
|
|
9
9
|
* carries.
|
|
10
10
|
*/
|
|
11
|
+
import { SIGNED_TRANSFER_TYP } from "./transfer.js";
|
|
11
12
|
/** Raised when a PEM does not decode into a private key this signer recognizes. */
|
|
12
13
|
export class AndCoSignerError extends Error {
|
|
13
14
|
constructor(message) {
|
|
@@ -33,7 +34,8 @@ const CURVE_OIDS = {
|
|
|
33
34
|
* The algorithm is read from the key itself -- an EC key's curve OID selects `ES256`/`ES384`/
|
|
34
35
|
* `ES512`, an RSA key signs `RS256`, and Ed25519 signs `EdDSA` -- so passing the wrong key never
|
|
35
36
|
* produces a mismatched header, and there is nothing about the algorithm for a caller to get wrong.
|
|
36
|
-
* An RSA key under 2048 bits throws {@link AndCoSignerError}.
|
|
37
|
+
* An RSA key under 2048 bits throws {@link AndCoSignerError}. The signer builds more kinds of key than
|
|
38
|
+
* the Platform registers: only ES256 (P-256) and RS256 are Signing Keys there.
|
|
37
39
|
*
|
|
38
40
|
* @example
|
|
39
41
|
* ```ts
|
|
@@ -84,6 +86,11 @@ export async function createAndCoSigner(options) {
|
|
|
84
86
|
const signature = await subtle.sign(signAlgorithm, key, new TextEncoder().encode(signingInput));
|
|
85
87
|
return `${signingInput}.${BASE64URL_BYTES(new Uint8Array(signature))}`;
|
|
86
88
|
},
|
|
89
|
+
async signTransfer(payload) {
|
|
90
|
+
const protectedHeader = BASE64URL(JSON.stringify({ alg, kid, typ: SIGNED_TRANSFER_TYP }));
|
|
91
|
+
const signature = await subtle.sign(signAlgorithm, key, new TextEncoder().encode(`${protectedHeader}.${payload}`));
|
|
92
|
+
return { protected: protectedHeader, signature: BASE64URL_BYTES(new Uint8Array(signature)) };
|
|
93
|
+
},
|
|
87
94
|
};
|
|
88
95
|
}
|
|
89
96
|
function SUBTLE_CRYPTO() {
|