@andco/protocol 0.0.15 → 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.
Files changed (61) hide show
  1. package/dist/authorization-preparation.d.ts +1 -1
  2. package/dist/errors.d.ts +1 -1
  3. package/dist/errors.js +1 -1
  4. package/dist/intent-input.d.ts +67 -54
  5. package/dist/intent-input.d.ts.map +1 -1
  6. package/dist/intent-input.js +39 -23
  7. package/dist/intent-status.d.ts +5 -6
  8. package/dist/intent-status.d.ts.map +1 -1
  9. package/dist/intent-status.js +12 -7
  10. package/dist/miniapp-manifest.d.ts +2 -2
  11. package/dist/miniapp-manifest.js +1 -1
  12. package/dist/native-intent.d.ts +12 -12
  13. package/dist/native-intent.d.ts.map +1 -1
  14. package/dist/native-intent.js +7 -4
  15. package/dist/rar/account-matchers.d.ts +10 -10
  16. package/dist/rar/account-matchers.js +2 -2
  17. package/dist/rar/bank.d.ts +284 -12
  18. package/dist/rar/bank.d.ts.map +1 -1
  19. package/dist/rar/bank.js +42 -4
  20. package/dist/rar/catalog.d.ts +130 -5
  21. package/dist/rar/catalog.d.ts.map +1 -1
  22. package/dist/rar/json-schemas.generated.d.ts.map +1 -1
  23. package/dist/rar/json-schemas.generated.js +372 -4
  24. package/dist/rar/money.d.ts +1 -1
  25. package/dist/rar/money.js +1 -1
  26. package/dist/rar/subject-data.d.ts +1 -1
  27. package/dist/rar/subject-data.js +1 -1
  28. package/dist/rest/accounts.d.ts +3 -3
  29. package/dist/rest/accounts.js +1 -1
  30. package/dist/rest/catalog.d.ts +3 -3
  31. package/dist/rest/catalog.js +2 -2
  32. package/dist/rest/contract.d.ts +561 -302
  33. package/dist/rest/contract.d.ts.map +1 -1
  34. package/dist/rest/contract.js +6 -2
  35. package/dist/rest/identity.d.ts +22 -22
  36. package/dist/rest/identity.d.ts.map +1 -1
  37. package/dist/rest/identity.js +4 -4
  38. package/dist/rest/intents.d.ts +301 -142
  39. package/dist/rest/intents.d.ts.map +1 -1
  40. package/dist/rest/intents.js +66 -52
  41. package/dist/rest/signatures.d.ts +19 -5
  42. package/dist/rest/signatures.d.ts.map +1 -1
  43. package/dist/rest/signatures.js +47 -5
  44. package/dist/rest/transfers.d.ts +738 -362
  45. package/dist/rest/transfers.d.ts.map +1 -1
  46. package/dist/rest/transfers.js +71 -44
  47. package/dist/signing.d.ts +6 -2
  48. package/dist/signing.d.ts.map +1 -1
  49. package/dist/signing.js +2 -1
  50. package/dist/transfer.d.ts +101 -65
  51. package/dist/transfer.d.ts.map +1 -1
  52. package/dist/transfer.js +69 -43
  53. package/dist/transport/financial-events.d.ts +64 -13
  54. package/dist/transport/financial-events.d.ts.map +1 -1
  55. package/dist/transport/financial-events.js +34 -0
  56. package/dist/transport/generated/oauth-api.d.ts +352 -88
  57. package/dist/transport/generated/oauth-api.d.ts.map +1 -1
  58. package/dist/transport/intents.d.ts +6 -6
  59. package/dist/transport/intents.d.ts.map +1 -1
  60. package/dist/transport/rest.d.ts +4 -4
  61. package/package.json +1 -1
@@ -1 +1 @@
1
- {"version":3,"file":"transfers.d.ts","sourceRoot":"","sources":["../../src/rest/transfers.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,CAAC,MAAM,SAAS,CAAC;AAG7B,OAAO,EACL,yBAAyB,EACzB,iBAAiB,EACjB,aAAa,EACb,cAAc,EACd,YAAY,EACZ,QAAQ,EACR,eAAe,EACf,WAAW,EACX,sBAAsB,EACtB,oBAAoB,EACpB,kBAAkB,EAEnB,MAAM,aAAa,CAAC;AAErB,OAAO,EACL,gBAAgB,EAChB,yBAAyB,EACzB,WAAW,EACX,YAAY,EACZ,kBAAkB,EAClB,wBAAwB,EACxB,mBAAmB,EACnB,wBAAwB,EACxB,iBAAiB,EACjB,yBAAyB,EAEzB,kBAAkB,EAClB,wBAAwB,EACxB,aAAa,EACb,cAAc,EACd,iCAAiC,EAClC,MAAM,cAAc,CAAC;AAEtB;;;GAGG;AACH,eAAO,MAAM,0BAA0B,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AAW,CAAC,OAAO,gBAAgB,CAAC,CAAC;AAEtE,qEAAqE;AACrE,eAAO,MAAM,oBAAoB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;0PAiCN,CAAC"}
@@ -1,15 +1,13 @@
1
1
  import { oc } from "@orpc/contract";
2
2
  import * as v from "valibot";
3
- import { SignedTransferEnvelopeSchema, TransferReceiverSchema, TransferSenderSchema } from "../transfer.js";
3
+ import { PesosSchema, SignedTransferEnvelopeSchema, SignedTransferJtiSchema, TransferPartySchema, } from "../transfer.js";
4
+ import { InvalidCursor } from "./accounts.js";
4
5
  import { AndcoAPIError, errors } from "./api-error.js";
5
- import { InsufficientAuthorization, InvalidIdentifier, InvalidOrigin, InvalidRequest, InvalidToken, NotFound, PayloadTooLarge, ServerError, TemporarilyUnavailable, UnsupportedMediaType, UnsupportedVersion, cursorlessConnection, } from "./common.js";
6
+ import { connection, cursorlessConnection, ForwardPageQuery, InsufficientAuthorization, InvalidIdentifier, InvalidOrigin, InvalidRequest, InvalidToken, NotFound, PayloadTooLarge, ServerError, TemporarilyUnavailable, UnsupportedMediaType, UnsupportedVersion, } from "./common.js";
6
7
  import { http } from "./http.js";
7
- import { AmountOutOfGrant, BankConnectionUnavailable, BankRefused, BankRejected, BankReviewRequired, ExpiredSignedInstruction, IdempotencyConflict, IdempotencyKeyNotAllowed, InsufficientFunds, IntentInteractionRequired, IntentStatus, InvalidDestination, InvalidSignedInstruction, InvalidSource, NotImplemented, TransferSenderIdentityUnavailable, } from "./intents.js";
8
- /**
9
- * The media type a signed transfer travels as: a JWS in the General JSON Serialization (RFC 7515
10
- * §7.2.1), the {@link SignedTransferEnvelopeSchema} itself.
11
- */
12
- export const SIGNED_TRANSFER_MEDIA_TYPE = "application/jose+json";
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 };
13
11
  const uuid = /* @__PURE__ */ v.pipe(v.string(), v.uuid());
14
12
  const dateTime = /* @__PURE__ */ v.pipe(v.string(), v.isoTimestamp());
15
13
  /**
@@ -29,8 +27,8 @@ function servedAsSignedTransfer(operation) {
29
27
  /**
30
28
  * The signed `sender` is not the account it names: its `country` is `CL`, its `bank_code` AndCo's
31
29
  * (`0739`), its `account_type` the account's own and its `national_id` the RUT of the account's
32
- * holder, compared as normalized RUTs. Its `name` is never compared. The core runs the same check
33
- * when it executes; the API runs it first so that the mistake fails before anything is stored.
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.
34
32
  */
35
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."))) {
36
34
  constructor(message) {
@@ -38,78 +36,107 @@ export class SenderMismatch extends /* @__PURE__ */ AndcoAPIError.define("sender
38
36
  }
39
37
  }
40
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."));
41
45
  /**
42
46
  * A Transfer: the movement of an amount from a Remitente (`sender`) to a Receptor (`receiver`), as
43
- * AndCo represents it (ADR 0093). One signature uploads one Transfer, named by its `jti`.
44
- *
45
- * `sender`, `receiver` and `comment` are what was signed, in Core's vocabulary and as they were
46
- * signed: what was signed never changes. `status` is where the Transfer stands, in the words an
47
- * Intent uses; `core_status` is the core's own word for its transfer, for the record only.
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.
48
50
  *
49
51
  * @example
50
52
  * const transfer: Transfer = {
51
- * object: "transfer", id, jti, status: "succeeded", core_status: "confirmed", approved: true,
52
- * sender, receiver, comment: "Factura 42", created_at, expires_at,
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,
53
56
  * };
54
57
  */
55
58
  export const Transfer = /* @__PURE__ */ v.pipe(v.strictObject({
56
59
  object: v.literal("transfer"),
57
60
  id: v.pipe(uuid, v.description("The Transfer's own id: what `GET /transfers/{transfer_id}` reads.")),
58
- jti: v.pipe(uuid, v.description("The `jti` of the Signed Instruction that uploaded it. Sending the same instruction again answers this same Transfer.")),
59
- status: v.pipe(IntentStatus, v.description("Where the Transfer stands, in the words an Intent uses (`IntentStatus`): decide on the base, never on the whole value. A signed transfer that is not approved is `requires_action` until a Grant with `bank_transfer` `approve` or a person approves it. A transfer between two accounts of the same holder is `processing.confirmed` from its release until AndCo answers for good, then `succeeded` or `failed.<code>`.")),
60
- core_status: v.pipe(v.nullable(v.pipe(v.string(), v.minLength(1))), v.description("The core bancario's own word for its transfer (`requested`, `confirmed`, `rejected_insufficient_funds`, …), for the record. Null while AndCo has not read one. Never branch on it: a word the core adds later appears here as it is, and `status` is what to decide on.")),
61
- approved: v.pipe(v.boolean(), v.description("The signed `approved`: whether the instruction ordered the transfer sent as soon as it was uploaded.")),
62
- sender: TransferSenderSchema,
63
- receiver: TransferReceiverSchema,
64
- comment: v.pipe(v.optional(v.string()), v.description("The signed comment, when there is one.")),
65
- created_at: v.pipe(dateTime, v.description("When the Transfer was uploaded.")),
66
- expires_at: v.pipe(dateTime, v.description("The Transfer's deadline: the signature's `exp`. A transfer still waiting for its approval at this instant expires.")),
67
- }), v.description("A Transfer uploaded as a Signed Instruction (ADR 0093), in Core's vocabulary: `sender`, `receiver` (with the amount, an integer in the minor unit of the currency) and `comment` exactly as signed. `status` is where it stands; `core_status` the core's own word, for the record."));
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."));
68
74
  // -- Operations ---------------------------------------------------------------------------------
69
- /** Uploads a signed transfer: one General JSON JWS (`application/jose+json`), one Transfer. */
75
+ /** Submits a signed transfer: one General JSON JWS (`application/jose+json`), one Transfer. */
70
76
  export const createTransfer = /* @__PURE__ */ oc
71
77
  .meta(http({
72
78
  method: "POST",
73
79
  path: "/transfers",
74
- summary: "Upload a signed transfer",
75
- description: "Uploads one Transfer as a Signed Instruction (ADR 0093, ADR 0092): 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, because the same object travels to the core. 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\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`, `disallowed_algorithm` or `invalid_signature`. The claims must be `SignedTransferClaims` (`invalid_claims` with `issues`) 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 upload `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`). `approved: true` 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\nWhere AndCo's core verifies signatures, every key must also be registered in the core, for any signed transfer (`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`): an approved one is released at once with nobody present and answers `processing.confirmed` 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` where AndCo does not verify signatures, and nothing is created; where it does, an approved one is sent to the core at once with nobody present: no web AndPass and no SMS code, because the core verifies the signature itself. The fraud engine still evaluates it. It answers `processing.confirmed` (or `succeeded`) once the core accepts it, `failed.fraud_rejected` when the engine refuses it, `failed.bank_challenge_required` when the engine asks for a challenge (nobody answers it: send the same transfer as an Intent a person confirms), and `failed.<code>` when the core refuses the signature (`unknown_key`, `revoked_key`, `invalid_signature`, `expired_signed_instruction`, `sender_mismatch`) or the request (`bank_refused`). On either rail, a key that signed it and is revoked or expired when the Transfer executes fails it with `failed.revoked_key` or `failed.expired_key`, even if the key was valid at upload, and nothing is sent; so does a key the core no longer holds, with `failed.unknown_key`, for one that leaves its holder. While the core's answer is not known it stays `requires_action`: read it later, 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 fraud 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. An unapproved Transfer waits, `requires_action`, for `POST /intents/{intent_id}/approve` with its `id`, or for a member of an Organization who may approve its transfers, and is sent the same way once approved.",
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.",
76
82
  successStatus: 201,
77
- successDescription: "The Transfer uploaded, or the same one from a repeated instruction",
83
+ successDescription: "The Transfer submitted, or the same one from a repeated instruction",
78
84
  spec: servedAsSignedTransfer,
79
85
  }))
80
- .errors(errors(InvalidRequest, IdempotencyKeyNotAllowed, InvalidSignedInstruction, InvalidToken, ExpiredSignedInstruction, InvalidOrigin, InsufficientAuthorization, UnsupportedVersion, ServerError, IdempotencyConflict, IntentInteractionRequired, PayloadTooLarge, UnsupportedMediaType, SenderMismatch, TransferSenderIdentityUnavailable, AmountOutOfGrant, InvalidSource, InvalidDestination, BankConnectionUnavailable, BankRefused, InsufficientFunds, BankRejected, BankReviewRequired, NotImplemented, TemporarilyUnavailable))
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))
81
87
  .input(SignedTransferEnvelopeSchema)
82
88
  .output(Transfer);
83
- /** Reads one Transfer uploaded under the same exact OAuth Grant. */
89
+ /** Reads one Transfer the Grant may read. */
84
90
  export const getTransfer = /* @__PURE__ */ oc
85
91
  .meta(http({
86
92
  method: "GET",
87
93
  path: "/transfers/{transfer_id}",
88
- summary: "Read one Transfer uploaded under the same exact OAuth Grant",
89
- successDescription: "The Transfer, as the Project that uploaded it reads it",
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",
90
97
  }))
91
98
  .errors(errors(InvalidIdentifier, InvalidToken, InvalidOrigin, NotFound, UnsupportedVersion, ServerError, TemporarilyUnavailable))
92
99
  .input(v.object({ transfer_id: uuid }))
93
100
  .output(Transfer);
94
101
  /**
95
- * A page of Transfers. Today the only way to get one is `GET /transfers?jti=`, so it holds zero or one
96
- * edge; a full listing can come later in the same shape.
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}.
97
104
  */
98
- export const TransferPage = /* @__PURE__ */ cursorlessConnection(Transfer, "A connection of Transfers uploaded under the same exact OAuth Grant. `GET /transfers?jti=` answers zero edges or one, and an edge's `cursor` is null: AndCo names no position inside it. A listing without `jti` can arrive later in this same shape, so read `edges` and never assume one.");
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.");
99
106
  /**
100
- * Finds the Transfer that a `jti` names, under the same exact OAuth Grant: for a client that lost the
101
- * answer to `POST /transfers` and whose `exp` has passed.
107
+ * Finds the Transfer that a `jti` names: for a client that lost the answer to `POST /transfers` and
108
+ * whose `exp` has passed.
102
109
  */
103
110
  export const listTransfers = /* @__PURE__ */ oc
104
111
  .meta(http({
105
112
  method: "GET",
106
113
  path: "/transfers",
107
- summary: "List the Transfers uploaded under the same exact OAuth Grant",
108
- description: "For now it only finds one Transfer by the `jti` of the Signed Instruction that uploaded it, and `jti` is required (`400 invalid_request` when it is missing or is not a UUID); a listing without it can come later in the same shape. The answer is a collection of zero or one Transfer, with the reach of `GET /transfers/{transfer_id}`: only a Transfer uploaded under the same OAuth Grant and the same client, never another's. For any other `jti`, or one that another Grant or client uploaded, the collection is empty, 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.",
109
- successDescription: "The Transfers found: zero or one, as the Project that uploaded them reads them",
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",
110
117
  }))
111
118
  .errors(errors(InvalidRequest, InvalidToken, InvalidOrigin, UnsupportedVersion, ServerError, TemporarilyUnavailable))
112
119
  .input(v.object({
113
- jti: v.pipe(uuid, v.description("The `jti` of the Signed Instruction that uploaded the Transfer.")),
120
+ jti: v.pipe(SignedTransferJtiSchema, v.description("The `jti` of the signed transfer that submitted the Transfer, a UUID in lowercase.")),
114
121
  }))
115
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/signing.d.ts CHANGED
@@ -8,7 +8,10 @@
8
8
  * `globalThis.crypto.subtle`, which every runtime the SDK targets (Node 18+, browsers, Bun) already
9
9
  * carries.
10
10
  */
11
- /** JWS `alg` values a Signing Key registered with an AndCo OAuth Client may carry. */
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.
@@ -55,7 +58,8 @@ export declare class AndCoSignerError extends Error {
55
58
  * The algorithm is read from the key itself -- an EC key's curve OID selects `ES256`/`ES384`/
56
59
  * `ES512`, an RSA key signs `RS256`, and Ed25519 signs `EdDSA` -- so passing the wrong key never
57
60
  * produces a mismatched header, and there is nothing about the algorithm for a caller to get wrong.
58
- * 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.
59
63
  *
60
64
  * @example
61
65
  * ```ts
@@ -1 +1 @@
1
- {"version":3,"file":"signing.d.ts","sourceRoot":"","sources":["../src/signing.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAIH,sFAAsF;AACtF,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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,EAAE,kBAAkB,GAAG,OAAO,CAAC,WAAW,CAAC,CAqDzF"}
package/dist/signing.js CHANGED
@@ -34,7 +34,8 @@ const CURVE_OIDS = {
34
34
  * The algorithm is read from the key itself -- an EC key's curve OID selects `ES256`/`ES384`/
35
35
  * `ES512`, an RSA key signs `RS256`, and Ed25519 signs `EdDSA` -- so passing the wrong key never
36
36
  * produces a mismatched header, and there is nothing about the algorithm for a caller to get wrong.
37
- * 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.
38
39
  *
39
40
  * @example
40
41
  * ```ts