@andco/protocol 0.0.14 → 0.0.15

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 (90) hide show
  1. package/README.md +2 -2
  2. package/dist/api-errors.d.ts +9 -9
  3. package/dist/api-errors.js +9 -9
  4. package/dist/authorization-preparation.js +2 -2
  5. package/dist/authorization.d.ts +1 -1
  6. package/dist/authorization.js +1 -1
  7. package/dist/consent.d.ts +2 -2
  8. package/dist/consent.js +2 -2
  9. package/dist/errors.d.ts +9 -9
  10. package/dist/errors.js +9 -9
  11. package/dist/index.d.ts +1 -0
  12. package/dist/index.d.ts.map +1 -1
  13. package/dist/index.js +1 -0
  14. package/dist/intent-input.d.ts +431 -872
  15. package/dist/intent-input.d.ts.map +1 -1
  16. package/dist/intent-input.js +142 -121
  17. package/dist/miniapp-manifest.d.ts +1 -1
  18. package/dist/native-intent.d.ts +82 -68
  19. package/dist/native-intent.d.ts.map +1 -1
  20. package/dist/native-intent.js +134 -84
  21. package/dist/native.d.ts +1 -1
  22. package/dist/rar/account-matchers.d.ts +35 -30
  23. package/dist/rar/account-matchers.d.ts.map +1 -1
  24. package/dist/rar/account-matchers.js +27 -21
  25. package/dist/rar/bank.d.ts +81 -81
  26. package/dist/rar/bank.js +1 -1
  27. package/dist/rar/catalog.d.ts +48 -48
  28. package/dist/rar/catalog.js +6 -6
  29. package/dist/rar/detail.d.ts +1 -1
  30. package/dist/rar/detail.js +1 -1
  31. package/dist/rar/json-schemas.generated.d.ts +1 -1
  32. package/dist/rar/json-schemas.generated.d.ts.map +1 -1
  33. package/dist/rar/json-schemas.generated.js +25 -21
  34. package/dist/rar/subject-data.d.ts +1 -1
  35. package/dist/rar/subject-data.js +1 -1
  36. package/dist/rar/subject.d.ts +1 -1
  37. package/dist/rar/subject.js +1 -1
  38. package/dist/rest/accounts.d.ts +28 -28
  39. package/dist/rest/accounts.d.ts.map +1 -1
  40. package/dist/rest/accounts.js +22 -22
  41. package/dist/rest/api-error.d.ts +1 -1
  42. package/dist/rest/api-error.js +1 -1
  43. package/dist/rest/catalog.d.ts +3 -3
  44. package/dist/rest/catalog.js +2 -2
  45. package/dist/rest/common.d.ts +3 -3
  46. package/dist/rest/common.js +3 -3
  47. package/dist/rest/contract.d.ts +905 -528
  48. package/dist/rest/contract.d.ts.map +1 -1
  49. package/dist/rest/contract.js +17 -5
  50. package/dist/rest/events.d.ts +1 -1
  51. package/dist/rest/events.d.ts.map +1 -1
  52. package/dist/rest/events.js +2 -2
  53. package/dist/rest/identity.d.ts +22 -22
  54. package/dist/rest/identity.js +5 -5
  55. package/dist/rest/index.d.ts +1 -0
  56. package/dist/rest/index.d.ts.map +1 -1
  57. package/dist/rest/index.js +1 -0
  58. package/dist/rest/intents.d.ts +787 -716
  59. package/dist/rest/intents.d.ts.map +1 -1
  60. package/dist/rest/intents.js +62 -53
  61. package/dist/rest/signatures.d.ts +11 -5
  62. package/dist/rest/signatures.d.ts.map +1 -1
  63. package/dist/rest/signatures.js +10 -0
  64. package/dist/rest/transfers.d.ts +612 -0
  65. package/dist/rest/transfers.d.ts.map +1 -0
  66. package/dist/rest/transfers.js +115 -0
  67. package/dist/scopes.d.ts +1 -1
  68. package/dist/signing.d.ts +12 -2
  69. package/dist/signing.d.ts.map +1 -1
  70. package/dist/signing.js +6 -0
  71. package/dist/transfer.d.ts +363 -0
  72. package/dist/transfer.d.ts.map +1 -0
  73. package/dist/transfer.js +287 -0
  74. package/dist/transport/financial-events.d.ts +21 -17
  75. package/dist/transport/financial-events.d.ts.map +1 -1
  76. package/dist/transport/generated/oauth-api.d.ts +1017 -194
  77. package/dist/transport/generated/oauth-api.d.ts.map +1 -1
  78. package/dist/transport/intents.d.ts +28 -12
  79. package/dist/transport/intents.d.ts.map +1 -1
  80. package/dist/transport/intents.js +1 -1
  81. package/dist/transport/rest.d.ts +4 -4
  82. package/dist/urls.d.ts +2 -2
  83. package/dist/urls.js +3 -3
  84. package/dist/userinfo.d.ts +2 -2
  85. package/dist/userinfo.js +2 -2
  86. package/dist/webhooks.d.ts +16 -16
  87. package/dist/webhooks.js +14 -14
  88. package/dist/window-features.d.ts +2 -2
  89. package/dist/window-features.js +2 -2
  90. package/package.json +2 -2
@@ -0,0 +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,0BAA0B,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAqBlE;;;;;GAKG;AACH,qBAAa,cAAe,SAAQ,eAAe,CAAC,mBASnD;gBACa,OAAO,CAAC,EAAE,MAAM;CAG7B;AAID;;;;;;;;;;;;;GAaG;AACH,eAAO,MAAM,QAAQ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;2RA0CpB,CAAC;AAEF,mDAAmD;AACnD,MAAM,MAAM,QAAQ,GAAG,CAAC,CAAC,WAAW,CAAC,OAAO,QAAQ,CAAC,CAAC;AAItD,+FAA+F;AAC/F,eAAO,MAAM,cAAc;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;4/BA2CR,CAAC;AAEpB,oEAAoE;AACpE,eAAO,MAAM,WAAW;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;sfAqBL,CAAC;AAEpB;;;GAGG;AACH,eAAO,MAAM,YAAY;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;YAGxB,CAAC;AAEF,2BAA2B;AAC3B,MAAM,MAAM,YAAY,GAAG,CAAC,CAAC,WAAW,CAAC,OAAO,YAAY,CAAC,CAAC;AAE9D;;;GAGG;AACH,eAAO,MAAM,aAAa;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;mNAiBH,CAAC"}
@@ -0,0 +1,115 @@
1
+ import { oc } from "@orpc/contract";
2
+ import * as v from "valibot";
3
+ import { SignedTransferEnvelopeSchema, TransferReceiverSchema, TransferSenderSchema } from "../transfer.js";
4
+ 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 { 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";
13
+ const uuid = /* @__PURE__ */ v.pipe(v.string(), v.uuid());
14
+ const dateTime = /* @__PURE__ */ v.pipe(v.string(), v.isoTimestamp());
15
+ /**
16
+ * oRPC describes a request body as `application/json`. A signed transfer travels as
17
+ * `application/jose+json` instead, the same JSON object under the media type RFC 7515 gives it: this
18
+ * moves the body there. It is the `spec` of `createTransfer`'s {@link http} meta.
19
+ */
20
+ function servedAsSignedTransfer(operation) {
21
+ const requestBody = operation["requestBody"];
22
+ const json = requestBody?.content?.["application/json"];
23
+ if (requestBody === undefined || json === undefined) {
24
+ throw new Error("The operation has no JSON body to serve as a signed transfer.");
25
+ }
26
+ return { ...operation, requestBody: { ...requestBody, content: { [SIGNED_TRANSFER_MEDIA_TYPE]: json } } };
27
+ }
28
+ // -- Errors -------------------------------------------------------------------------------------
29
+ /**
30
+ * The signed `sender` is not the account it names: its `country` is `CL`, its `bank_code` AndCo's
31
+ * (`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.
34
+ */
35
+ 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
+ constructor(message) {
37
+ super({}, message);
38
+ }
39
+ }
40
+ // -- Transfers ----------------------------------------------------------------------------------
41
+ /**
42
+ * 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.
48
+ *
49
+ * @example
50
+ * 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
+ * };
54
+ */
55
+ export const Transfer = /* @__PURE__ */ v.pipe(v.strictObject({
56
+ object: v.literal("transfer"),
57
+ 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."));
68
+ // -- Operations ---------------------------------------------------------------------------------
69
+ /** Uploads a signed transfer: one General JSON JWS (`application/jose+json`), one Transfer. */
70
+ export const createTransfer = /* @__PURE__ */ oc
71
+ .meta(http({
72
+ method: "POST",
73
+ 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.",
76
+ successStatus: 201,
77
+ successDescription: "The Transfer uploaded, or the same one from a repeated instruction",
78
+ spec: servedAsSignedTransfer,
79
+ }))
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))
81
+ .input(SignedTransferEnvelopeSchema)
82
+ .output(Transfer);
83
+ /** Reads one Transfer uploaded under the same exact OAuth Grant. */
84
+ export const getTransfer = /* @__PURE__ */ oc
85
+ .meta(http({
86
+ method: "GET",
87
+ 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",
90
+ }))
91
+ .errors(errors(InvalidIdentifier, InvalidToken, InvalidOrigin, NotFound, UnsupportedVersion, ServerError, TemporarilyUnavailable))
92
+ .input(v.object({ transfer_id: uuid }))
93
+ .output(Transfer);
94
+ /**
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.
97
+ */
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.");
99
+ /**
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.
102
+ */
103
+ export const listTransfers = /* @__PURE__ */ oc
104
+ .meta(http({
105
+ method: "GET",
106
+ 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",
110
+ }))
111
+ .errors(errors(InvalidRequest, InvalidToken, InvalidOrigin, UnsupportedVersion, ServerError, TemporarilyUnavailable))
112
+ .input(v.object({
113
+ jti: v.pipe(uuid, v.description("The `jti` of the Signed Instruction that uploaded the Transfer.")),
114
+ }))
115
+ .output(TransferPage);
package/dist/scopes.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  /**
2
- * OAuth scopes Andco supports, suggested by TypeScript editors: OpenID Connect and session concerns
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,13 @@
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
+ /** JWS `alg` values a Signing Key registered with an AndCo OAuth Client may carry. */
12
12
  export type AndCoSigningAlgorithm = "ES256" | "ES384" | "ES512" | "RS256" | "EdDSA";
13
13
  /**
14
14
  * A Signing Key bound once to its `kid` and algorithm, ready to sign any number of claim sets.
15
15
  *
16
16
  * 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
17
+ * public surface is {@link AndCoSigner.sign} and {@link AndCoSigner.signTransfer}, so nothing here can produce a header a caller typed
18
18
  * incorrectly.
19
19
  */
20
20
  export type AndCoSigner = {
@@ -29,6 +29,16 @@ export type AndCoSigner = {
29
29
  * because the whole reason this type exists is that a caller never has to think about it.
30
30
  */
31
31
  sign(claims: Record<string, unknown>): Promise<string>;
32
+ /**
33
+ * Signs a transfer's payload for one signature of a General JSON JWS (RFC 7515 §7.2.1). `payload` is
34
+ * the base64url of the claims, the same string for every key that signs the transfer; the protected
35
+ * header is always exactly `{ alg, kid, typ: "transfer.v1+jwt" }`. The signature covers
36
+ * `protected.payload`. It does not check `alg`: whether the Platform accepts it is its answer to give.
37
+ */
38
+ signTransfer(payload: string): Promise<{
39
+ protected: string;
40
+ signature: string;
41
+ }>;
32
42
  };
33
43
  /** Input accepted by {@link createAndCoSigner}. */
34
44
  export type AndCoSignerOptions = {
@@ -1 +1 @@
1
- {"version":3,"file":"signing.d.ts","sourceRoot":"","sources":["../src/signing.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAEH,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;CACxD,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;;;;;;;;;;;;;GAaG;AACH,wBAAsB,iBAAiB,CAAC,OAAO,EAAE,kBAAkB,GAAG,OAAO,CAAC,WAAW,CAAC,CA4CzF"}
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,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;;;;;;;;;;;;;GAaG;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) {
@@ -84,6 +85,11 @@ export async function createAndCoSigner(options) {
84
85
  const signature = await subtle.sign(signAlgorithm, key, new TextEncoder().encode(signingInput));
85
86
  return `${signingInput}.${BASE64URL_BYTES(new Uint8Array(signature))}`;
86
87
  },
88
+ async signTransfer(payload) {
89
+ const protectedHeader = BASE64URL(JSON.stringify({ alg, kid, typ: SIGNED_TRANSFER_TYP }));
90
+ const signature = await subtle.sign(signAlgorithm, key, new TextEncoder().encode(`${protectedHeader}.${payload}`));
91
+ return { protected: protectedHeader, signature: BASE64URL_BYTES(new Uint8Array(signature)) };
92
+ },
87
93
  };
88
94
  }
89
95
  function SUBTLE_CRYPTO() {
@@ -0,0 +1,363 @@
1
+ import * as v from "valibot";
2
+ import { type Issue, type ParseResult } from "./issues.js";
3
+ /**
4
+ * A transfer in Andco Core's own vocabulary (ADR 0093, ADR 0092): the Remitente is `sender`, the
5
+ * Receptor is `receiver`, and each carries the fields of Core's `POST /api/transfer` body, so no
6
+ * system translates between the Platform and the core.
7
+ */
8
+ /**
9
+ * A bank as Core names it: four digits. The schema checks only the form, because Core validates the
10
+ * code against its own catalog and a copy of that list would drift. {@link CHILEAN_BANK_CODES} names
11
+ * the known ones, and no validation reads it.
12
+ *
13
+ * @example
14
+ * v.parse(BankCodeSchema, CHILEAN_BANK_CODES.andco); // "0739"
15
+ */
16
+ export declare const BankCodeSchema: v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.RegexAction<string, undefined>, v.DescriptionAction<string, "The bank's four-digit code in Core's catalog. Andco is `0739`.">]>;
17
+ /**
18
+ * The Chilean banks of Core's catalog by code, as Core lists them (`GET /catalogs/banks`). A helper
19
+ * for whoever writes a `bank_code`: no schema reads it, so a bank Core adds later is accepted
20
+ * before this list knows it.
21
+ *
22
+ * @example
23
+ * const receiver = { bank_code: CHILEAN_BANK_CODES.banco_estado }; // "0012"
24
+ */
25
+ export declare const CHILEAN_BANK_CODES: {
26
+ readonly banco_de_chile: "0001";
27
+ readonly banco_internacional: "0009";
28
+ readonly banco_estado: "0012";
29
+ readonly scotiabank: "0014";
30
+ readonly bci: "0016";
31
+ readonly banco_do_brasil: "0017";
32
+ readonly corpbanca: "0027";
33
+ readonly bice: "0028";
34
+ readonly hsbc_bank_chile: "0031";
35
+ readonly santander: "0037";
36
+ readonly banco_itau: "0039";
37
+ readonly jp_morgan: "0041";
38
+ readonly security: "0049";
39
+ readonly banco_falabella: "0051";
40
+ readonly banco_ripley: "0053";
41
+ readonly banco_consorcio: "0055";
42
+ readonly banco_paris: "0057";
43
+ readonly tanner: "0062";
44
+ readonly scotiabank_azul: "0504";
45
+ readonly banco_del_desarrollo: "0507";
46
+ readonly coopeuch: "0672";
47
+ readonly la_polar_prepago: "0697";
48
+ readonly prepago_los_heroes: "0729";
49
+ readonly tenpo_prepago: "0730";
50
+ readonly tapp: "0732";
51
+ readonly global_66: "0738";
52
+ readonly andco: "0739";
53
+ readonly copec_pay: "0741";
54
+ readonly prex: "0743";
55
+ readonly sumup: "0744";
56
+ readonly fintual: "0746";
57
+ readonly metromuv: "0747";
58
+ readonly fintoc: "0764";
59
+ readonly mercado_pago: "0875";
60
+ };
61
+ /** The largest transfer amount: Core stores an amount as int4. */
62
+ export declare const TRANSFER_AMOUNT_MAX = 2147483647;
63
+ /**
64
+ * A transfer amount as Core's body carries it: a JSON integer in the minor unit of the currency (CLP:
65
+ * whole pesos), from 1 to {@link TRANSFER_AMOUNT_MAX}, because Core stores it as int4. A larger one is
66
+ * refused with the issue type `max_value` and `requirement` 2147483647.
67
+ *
68
+ * @example
69
+ * v.parse(PesosSchema, 40000); // 40000
70
+ */
71
+ export declare const PesosSchema: v.SchemaWithPipe<readonly [v.NumberSchema<undefined>, v.IntegerAction<number, undefined>, v.MinValueAction<number, 1, undefined>, v.MaxValueAction<number, 2147483647, undefined>, v.DescriptionAction<number, "An integer in the minor unit of the currency (CLP: whole pesos), from 1 to 2147483647, because Core stores it as int4. A larger one is refused with `max_value`.">]>;
72
+ /**
73
+ * A Chilean account type as Core's catalog codes it: `"10"` savings, `"20"` checking and `"40"`
74
+ * debit (cuenta vista). Every Andco account is `"40"`.
75
+ */
76
+ export declare const TransferAccountTypeSchema: v.SchemaWithPipe<readonly [v.PicklistSchema<["10", "20", "40"], undefined>, v.DescriptionAction<"10" | "20" | "40", "Core's account type code: `\"10\"` savings, `\"20\"` checking, `\"40\"` debit (cuenta vista).">]>;
77
+ /** A Chilean account type as Core's catalog codes it. */
78
+ export type TransferAccountType = v.InferOutput<typeof TransferAccountTypeSchema>;
79
+ /**
80
+ * The Remitente: the account the money leaves and its holder, as Core's `sender`. Core checks it
81
+ * against the account's holder (`country`, `bank_code` `0739`, the account's own `account_type` and
82
+ * the holder's RUT) and stores `name` as it arrives.
83
+ *
84
+ * @example
85
+ * const sender: TransferSender = {
86
+ * country: "CL", bank_code: "0739", account_type: "40", account_number: "000123456789",
87
+ * name: "ACME SpA", national_kind_id: "RUT", national_id: "76.111.111-1",
88
+ * };
89
+ */
90
+ export declare const TransferSenderSchema: v.SchemaWithPipe<readonly [v.VariantSchema<"country", [v.StrictObjectSchema<{
91
+ country: v.LiteralSchema<"CL", undefined>;
92
+ bank_code: v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.RegexAction<string, undefined>, v.DescriptionAction<string, "The bank's four-digit code in Core's catalog. Andco is `0739`.">]>;
93
+ account_type: v.SchemaWithPipe<readonly [v.PicklistSchema<["10", "20", "40"], undefined>, v.DescriptionAction<"10" | "20" | "40", "Core's account type code: `\"10\"` savings, `\"20\"` checking, `\"40\"` debit (cuenta vista).">]>;
94
+ account_number: v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.MinLengthAction<string, 1, undefined>, v.MaxLengthAction<string, 64, undefined>, v.DescriptionAction<string, "The account number, as its bank writes it.">]>;
95
+ name: v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.MinLengthAction<string, 1, undefined>, v.DescriptionAction<string, "The holder's name. Core stores it as it arrives and never compares it.">]>;
96
+ national_kind_id: v.LiteralSchema<"RUT", undefined>;
97
+ national_id: v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.MinLengthAction<string, 1, undefined>, v.MaxLengthAction<string, 64, undefined>, v.DescriptionAction<string, "The holder's RUT. Core compares it as a normalized RUT.">]>;
98
+ }, undefined>], undefined>, v.DescriptionAction<{
99
+ country: "CL";
100
+ bank_code: string;
101
+ account_type: "10" | "20" | "40";
102
+ account_number: string;
103
+ name: string;
104
+ national_kind_id: "RUT";
105
+ national_id: string;
106
+ }, "The Remitente, as Core's `sender`: the account the money leaves and its holder. `country` and `national_kind_id` are always declared. Core checks the country, the bank (`0739`), the account's own type and the holder's RUT; it stores `name` as it arrives.">]>;
107
+ /** The Remitente, as Core's `sender`. */
108
+ export type TransferSender = v.InferOutput<typeof TransferSenderSchema>;
109
+ /**
110
+ * The Receptor: the account the money lands on, its holder and the amount, as Core's `receiver`.
111
+ * The amount is an integer number of pesos.
112
+ *
113
+ * @example
114
+ * const receiver: TransferReceiver = {
115
+ * country: "CL", bank_code: "0012", account_type: "20", account_number: "12345678",
116
+ * name: "Proveedor SpA", national_kind_id: "RUT", national_id: "76.123.456-7",
117
+ * amount: 500000, currency: "CLP",
118
+ * };
119
+ */
120
+ export declare const TransferReceiverSchema: v.SchemaWithPipe<readonly [v.VariantSchema<"country", [v.StrictObjectSchema<{
121
+ readonly amount: v.SchemaWithPipe<readonly [v.NumberSchema<undefined>, v.IntegerAction<number, undefined>, v.MinValueAction<number, 1, undefined>, v.MaxValueAction<number, 2147483647, undefined>, v.DescriptionAction<number, "An integer in the minor unit of the currency (CLP: whole pesos), from 1 to 2147483647, because Core stores it as int4. A larger one is refused with `max_value`.">]>;
122
+ readonly currency: v.LiteralSchema<"CLP", undefined>;
123
+ readonly email: v.SchemaWithPipe<readonly [v.OptionalSchema<v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.EmailAction<string, undefined>]>, undefined>, v.DescriptionAction<string | undefined, "Where Core notifies the Receptor.">]>;
124
+ readonly country: v.LiteralSchema<"CL", undefined>;
125
+ readonly bank_code: v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.RegexAction<string, undefined>, v.DescriptionAction<string, "The bank's four-digit code in Core's catalog. Andco is `0739`.">]>;
126
+ readonly account_type: v.SchemaWithPipe<readonly [v.PicklistSchema<["10", "20", "40"], undefined>, v.DescriptionAction<"10" | "20" | "40", "Core's account type code: `\"10\"` savings, `\"20\"` checking, `\"40\"` debit (cuenta vista).">]>;
127
+ readonly account_number: v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.MinLengthAction<string, 1, undefined>, v.MaxLengthAction<string, 64, undefined>, v.DescriptionAction<string, "The account number, as its bank writes it.">]>;
128
+ readonly name: v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.MinLengthAction<string, 1, undefined>, v.DescriptionAction<string, "The holder's name. Core stores it as it arrives and never compares it.">]>;
129
+ readonly national_kind_id: v.LiteralSchema<"RUT", undefined>;
130
+ readonly national_id: v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.MinLengthAction<string, 1, undefined>, v.MaxLengthAction<string, 64, undefined>, v.DescriptionAction<string, "The holder's RUT. Core compares it as a normalized RUT.">]>;
131
+ }, undefined>], undefined>, v.DescriptionAction<{
132
+ amount: number;
133
+ currency: "CLP";
134
+ email?: string | undefined;
135
+ country: "CL";
136
+ bank_code: string;
137
+ account_type: "10" | "20" | "40";
138
+ account_number: string;
139
+ name: string;
140
+ national_kind_id: "RUT";
141
+ national_id: string;
142
+ }, "The Receptor, as Core's `receiver`: the account the money lands on, its holder, and the amount, an integer in the minor unit of the currency. `country` and `national_kind_id` are always declared.">]>;
143
+ /** The Receptor, as Core's `receiver`. */
144
+ export type TransferReceiver = v.InferOutput<typeof TransferReceiverSchema>;
145
+ /**
146
+ * The claims of a signed transfer, version 2: Core's `POST /api/transfer` body, signed, plus the
147
+ * envelope (`iss`, `aud`, `jti`, `exp`) and `approved`. `metadata` is the signer's own data, kept as
148
+ * it arrives and read by nothing that decides; there is no `expires_at`, `iat` or `nbf`, because the
149
+ * deadline is `exp`. The core verifies the signature and runs the
150
+ * payload as its command, so nothing here names an Account Key or an Andco account id, and an
151
+ * unknown claim is refused.
152
+ *
153
+ * - `jti` is a UUID: it names the Transfer and is Core's `Idempotency-Key`.
154
+ * - `exp` bounds execution in the core, and is part of what the `jti` names.
155
+ * - `approved: true` orders the transfer sent as soon as it is uploaded; it needs `bank_transfer`
156
+ * `approve` in the Project's Grant.
157
+ *
158
+ * @example
159
+ * const claims: SignedTransferClaims = {
160
+ * iss: clientId, aud: "https://api.andco.com", jti: crypto.randomUUID(), exp: 1795000000, approved: true,
161
+ * sender, receiver, comment: "Factura 42",
162
+ * };
163
+ */
164
+ export declare const SignedTransferClaimsSchema: v.SchemaWithPipe<readonly [v.StrictObjectSchema<{
165
+ readonly iss: v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.MinLengthAction<string, 1, undefined>, v.MaxLengthAction<string, 64, undefined>, v.DescriptionAction<string, "The signing Project's `client_id`.">]>;
166
+ readonly aud: v.LiteralSchema<"https://api.andco.com", undefined>;
167
+ readonly jti: v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.UuidAction<string, undefined>, v.DescriptionAction<string, "Names the Transfer: Core's `Idempotency-Key`. The same `jti` with other content is a conflict.">]>;
168
+ readonly exp: v.SchemaWithPipe<readonly [v.NumberSchema<undefined>, v.IntegerAction<number, undefined>, v.DescriptionAction<number, "Unix seconds after which the core refuses to execute the transfer.">]>;
169
+ readonly approved: v.SchemaWithPipe<readonly [v.BooleanSchema<undefined>, v.DescriptionAction<boolean, "`true` orders the transfer sent to the core as soon as it is uploaded, which needs `bank_transfer` `approve` in the Grant.">]>;
170
+ readonly sender: v.SchemaWithPipe<readonly [v.VariantSchema<"country", [v.StrictObjectSchema<{
171
+ country: v.LiteralSchema<"CL", undefined>;
172
+ bank_code: v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.RegexAction<string, undefined>, v.DescriptionAction<string, "The bank's four-digit code in Core's catalog. Andco is `0739`.">]>;
173
+ account_type: v.SchemaWithPipe<readonly [v.PicklistSchema<["10", "20", "40"], undefined>, v.DescriptionAction<"10" | "20" | "40", "Core's account type code: `\"10\"` savings, `\"20\"` checking, `\"40\"` debit (cuenta vista).">]>;
174
+ account_number: v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.MinLengthAction<string, 1, undefined>, v.MaxLengthAction<string, 64, undefined>, v.DescriptionAction<string, "The account number, as its bank writes it.">]>;
175
+ name: v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.MinLengthAction<string, 1, undefined>, v.DescriptionAction<string, "The holder's name. Core stores it as it arrives and never compares it.">]>;
176
+ national_kind_id: v.LiteralSchema<"RUT", undefined>;
177
+ national_id: v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.MinLengthAction<string, 1, undefined>, v.MaxLengthAction<string, 64, undefined>, v.DescriptionAction<string, "The holder's RUT. Core compares it as a normalized RUT.">]>;
178
+ }, undefined>], undefined>, v.DescriptionAction<{
179
+ country: "CL";
180
+ bank_code: string;
181
+ account_type: "10" | "20" | "40";
182
+ account_number: string;
183
+ name: string;
184
+ national_kind_id: "RUT";
185
+ national_id: string;
186
+ }, "The Remitente, as Core's `sender`: the account the money leaves and its holder. `country` and `national_kind_id` are always declared. Core checks the country, the bank (`0739`), the account's own type and the holder's RUT; it stores `name` as it arrives.">]>;
187
+ readonly receiver: v.SchemaWithPipe<readonly [v.VariantSchema<"country", [v.StrictObjectSchema<{
188
+ readonly amount: v.SchemaWithPipe<readonly [v.NumberSchema<undefined>, v.IntegerAction<number, undefined>, v.MinValueAction<number, 1, undefined>, v.MaxValueAction<number, 2147483647, undefined>, v.DescriptionAction<number, "An integer in the minor unit of the currency (CLP: whole pesos), from 1 to 2147483647, because Core stores it as int4. A larger one is refused with `max_value`.">]>;
189
+ readonly currency: v.LiteralSchema<"CLP", undefined>;
190
+ readonly email: v.SchemaWithPipe<readonly [v.OptionalSchema<v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.EmailAction<string, undefined>]>, undefined>, v.DescriptionAction<string | undefined, "Where Core notifies the Receptor.">]>;
191
+ readonly country: v.LiteralSchema<"CL", undefined>;
192
+ readonly bank_code: v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.RegexAction<string, undefined>, v.DescriptionAction<string, "The bank's four-digit code in Core's catalog. Andco is `0739`.">]>;
193
+ readonly account_type: v.SchemaWithPipe<readonly [v.PicklistSchema<["10", "20", "40"], undefined>, v.DescriptionAction<"10" | "20" | "40", "Core's account type code: `\"10\"` savings, `\"20\"` checking, `\"40\"` debit (cuenta vista).">]>;
194
+ readonly account_number: v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.MinLengthAction<string, 1, undefined>, v.MaxLengthAction<string, 64, undefined>, v.DescriptionAction<string, "The account number, as its bank writes it.">]>;
195
+ readonly name: v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.MinLengthAction<string, 1, undefined>, v.DescriptionAction<string, "The holder's name. Core stores it as it arrives and never compares it.">]>;
196
+ readonly national_kind_id: v.LiteralSchema<"RUT", undefined>;
197
+ readonly national_id: v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.MinLengthAction<string, 1, undefined>, v.MaxLengthAction<string, 64, undefined>, v.DescriptionAction<string, "The holder's RUT. Core compares it as a normalized RUT.">]>;
198
+ }, undefined>], undefined>, v.DescriptionAction<{
199
+ amount: number;
200
+ currency: "CLP";
201
+ email?: string | undefined;
202
+ country: "CL";
203
+ bank_code: string;
204
+ account_type: "10" | "20" | "40";
205
+ account_number: string;
206
+ name: string;
207
+ national_kind_id: "RUT";
208
+ national_id: string;
209
+ }, "The Receptor, as Core's `receiver`: the account the money lands on, its holder, and the amount, an integer in the minor unit of the currency. `country` and `national_kind_id` are always declared.">]>;
210
+ readonly comment: v.SchemaWithPipe<readonly [v.OptionalSchema<v.StringSchema<undefined>, undefined>, v.DescriptionAction<string | undefined, "What both sides read next to the movement.">]>;
211
+ readonly metadata: v.SchemaWithPipe<readonly [v.OptionalSchema<v.RecordSchema<v.StringSchema<undefined>, v.UnknownSchema, undefined>, undefined>, v.DescriptionAction<{
212
+ [x: string]: unknown;
213
+ } | undefined, "The signer's own data, signed and kept as it arrives. Nothing reads it to decide anything.">]>;
214
+ }, undefined>, v.DescriptionAction<{
215
+ iss: string;
216
+ aud: "https://api.andco.com";
217
+ jti: string;
218
+ exp: number;
219
+ approved: boolean;
220
+ sender: {
221
+ country: "CL";
222
+ bank_code: string;
223
+ account_type: "10" | "20" | "40";
224
+ account_number: string;
225
+ name: string;
226
+ national_kind_id: "RUT";
227
+ national_id: string;
228
+ };
229
+ receiver: {
230
+ amount: number;
231
+ currency: "CLP";
232
+ email?: string | undefined;
233
+ country: "CL";
234
+ bank_code: string;
235
+ account_type: "10" | "20" | "40";
236
+ account_number: string;
237
+ name: string;
238
+ national_kind_id: "RUT";
239
+ national_id: string;
240
+ };
241
+ comment?: string | undefined;
242
+ metadata?: {
243
+ [x: string]: unknown;
244
+ } | undefined;
245
+ }, "The claims of a signed transfer (`typ` `transfer.v1+jwt`): Core's `POST /api/transfer` body (with its optional `metadata`) plus `iss`, `aud`, `jti`, `exp` and `approved`. Strict: an unknown claim, country or document is refused, nothing names an Account Key or an Andco account id, and the only deadline is `exp`.">]>;
246
+ /** The claims of a signed transfer, version 2. */
247
+ export type SignedTransferClaims = v.InferOutput<typeof SignedTransferClaimsSchema>;
248
+ /** The most bytes Core keeps of a transfer's comment, counted in UTF-8. */
249
+ export declare const TRANSFER_COMMENT_MAX_BYTES = 60;
250
+ /**
251
+ * The rules of signed transfer claims that JSON Schema does not say, over claims that already have
252
+ * their shape ({@link SignedTransferClaimsSchema}): `comment_too_long` when the comment has more
253
+ * than {@link TRANSFER_COMMENT_MAX_BYTES} bytes of UTF-8. JSON Schema counts characters, never
254
+ * bytes, so this limit is a rule.
255
+ *
256
+ * @example
257
+ * signedTransferClaimsIssues({ ...claims, comment: "ñ".repeat(31) });
258
+ * // [{ type: "comment_too_long", path: [{ key: "comment" }], requirement: 60 }]
259
+ */
260
+ export declare function signedTransferClaimsIssues(claims: SignedTransferClaims): Issue[];
261
+ /**
262
+ * The rule of a transfer's comment, wherever it sits (signed claims, an Intent proposal, a
263
+ * confirmation): `comment_too_long` at `path` when it has more than
264
+ * {@link TRANSFER_COMMENT_MAX_BYTES} bytes of UTF-8.
265
+ *
266
+ * @example
267
+ * transferCommentIssues("ñ".repeat(31), [{ key: "comment" }]);
268
+ * // [{ type: "comment_too_long", path: [{ key: "comment" }], requirement: 60 }]
269
+ */
270
+ export declare function transferCommentIssues(comment: string | undefined, path: Issue["path"]): Issue[];
271
+ /**
272
+ * Parses the claims of a signed transfer: their shape and then their rules. Parsing never verifies
273
+ * a signature.
274
+ *
275
+ * @example
276
+ * const parsed = parseSignedTransferClaims(claims);
277
+ * if (!parsed.success) console.log(parsed.issues.map((issue) => issue.type));
278
+ */
279
+ export declare function parseSignedTransferClaims(input: unknown): ParseResult<SignedTransferClaims>;
280
+ /** The `typ` of the protected header of every signature over transfer claims v2. */
281
+ export declare const SIGNED_TRANSFER_TYP = "transfer.v1+jwt";
282
+ /**
283
+ * The protected header of one signature, decoded: the algorithm, the `kid` of a Signing Key Pair
284
+ * registered in the Platform and in the core, and the versioned `typ`. Strict, so a parameter the
285
+ * verifiers do not understand (`crit`, `b64`) is refused rather than ignored.
286
+ *
287
+ * @example
288
+ * const header: SignedTransferHeader = { alg: "ES256", kid, typ: "transfer.v1+jwt" };
289
+ */
290
+ export declare const SignedTransferHeaderSchema: v.SchemaWithPipe<readonly [v.StrictObjectSchema<{
291
+ readonly alg: v.PicklistSchema<["ES256", "RS256"], undefined>;
292
+ readonly kid: v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.MinLengthAction<string, 1, undefined>]>;
293
+ readonly typ: v.LiteralSchema<"transfer.v1+jwt", undefined>;
294
+ }, undefined>, v.DescriptionAction<{
295
+ alg: "ES256" | "RS256";
296
+ kid: string;
297
+ typ: "transfer.v1+jwt";
298
+ }, "The protected header of one signature, decoded: `alg` (`ES256` or `RS256`), the `kid` of a registered Signing Key Pair, and `typ` `transfer.v1+jwt`.">]>;
299
+ /** The protected header of one signature over transfer claims, decoded. */
300
+ export type SignedTransferHeader = v.InferOutput<typeof SignedTransferHeaderSchema>;
301
+ /**
302
+ * A signed transfer as it travels: a JWS in the General JSON Serialization (RFC 7515 §7.2.1), one
303
+ * `payload` (the base64url of {@link SignedTransferClaimsSchema}) and a `signatures` array with at
304
+ * least one entry. One signature is an array of one. The same object travels unchanged to the core,
305
+ * which verifies every signature. Every header member is protected: an unprotected `header` is
306
+ * refused, because nothing outside the signature may name the key.
307
+ *
308
+ * Each `protected` must decode to {@link SignedTransferHeaderSchema}; that is a rule, because JSON
309
+ * Schema cannot read inside base64url ({@link parseSignedTransferEnvelope}).
310
+ *
311
+ * @example
312
+ * const envelope: SignedTransferEnvelope = {
313
+ * payload: "eyJpc3MiOi…",
314
+ * signatures: [{ protected: "eyJhbGciOiJFUzI1NiIs…", signature: "MEUCIQ…" }],
315
+ * };
316
+ */
317
+ export declare const SignedTransferEnvelopeSchema: v.SchemaWithPipe<readonly [v.StrictObjectSchema<{
318
+ readonly payload: v.SchemaWithPipe<readonly [v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.RegexAction<string, undefined>]>, v.DescriptionAction<string, "The base64url of the JSON claims (`SignedTransferClaims`).">]>;
319
+ readonly signatures: v.SchemaWithPipe<readonly [v.ArraySchema<v.StrictObjectSchema<{
320
+ readonly protected: v.SchemaWithPipe<readonly [v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.RegexAction<string, undefined>]>, v.DescriptionAction<string, "The base64url of the JSON protected header (`SignedTransferHeader`).">]>;
321
+ readonly signature: v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.RegexAction<string, undefined>]>;
322
+ }, undefined>, undefined>, v.MinLengthAction<{
323
+ protected: string;
324
+ signature: string;
325
+ }[], 1, undefined>, v.DescriptionAction<{
326
+ protected: string;
327
+ signature: string;
328
+ }[], "At least one signature over the same payload; the core verifies every one.">]>;
329
+ }, undefined>, v.DescriptionAction<{
330
+ payload: string;
331
+ signatures: {
332
+ protected: string;
333
+ signature: string;
334
+ }[];
335
+ }, "A signed transfer: a JWS in the General JSON Serialization (RFC 7515 §7.2.1), with one `payload` and at least one signature, each with a protected header of `typ` `transfer.v1+jwt`. Sent as `application/jose+json`.">]>;
336
+ /** A signed transfer as it travels: a JWS in the General JSON Serialization. */
337
+ export type SignedTransferEnvelope = v.InferOutput<typeof SignedTransferEnvelopeSchema>;
338
+ /**
339
+ * The rules of an envelope that JSON Schema does not say, over an envelope that already has its
340
+ * shape ({@link SignedTransferEnvelopeSchema}). At each signature's `protected`:
341
+ *
342
+ * - `malformed_protected_header` when it is not the base64url of a JSON value;
343
+ * - the issues of {@link SignedTransferHeaderSchema} when the header it decodes to is not one (a
344
+ * `typ` other than `transfer.v1+jwt`, no `kid`, another algorithm).
345
+ *
346
+ * It never verifies a signature.
347
+ *
348
+ * @example
349
+ * signedTransferEnvelopeIssues({ payload, signatures: [{ protected: "bm90LWpzb24", signature }] });
350
+ * // [{ type: "malformed_protected_header", path: [{ key: "signatures" }, { key: 0 }, { key: "protected" }] }]
351
+ */
352
+ export declare function signedTransferEnvelopeIssues(envelope: SignedTransferEnvelope): Issue[];
353
+ /**
354
+ * Parses a signed transfer envelope: its shape and then each signature's protected header. It
355
+ * neither verifies a signature nor reads the payload; the claims are parsed apart with
356
+ * {@link parseSignedTransferClaims} once a signature verifies.
357
+ *
358
+ * @example
359
+ * const parsed = parseSignedTransferEnvelope(await request.json());
360
+ * if (!parsed.success) console.log(parsed.issues.map((issue) => issue.type));
361
+ */
362
+ export declare function parseSignedTransferEnvelope(input: unknown): ParseResult<SignedTransferEnvelope>;
363
+ //# sourceMappingURL=transfer.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"transfer.d.ts","sourceRoot":"","sources":["../src/transfer.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,CAAC,MAAM,SAAS,CAAC;AAE7B,OAAO,EAAE,KAAK,KAAK,EAAsB,KAAK,WAAW,EAAkB,MAAM,aAAa,CAAC;AAE/F;;;;GAIG;AAEH;;;;;;;GAOG;AACH,eAAO,MAAM,cAAc,yLAI1B,CAAC;AAEF;;;;;;;GAOG;AACH,eAAO,MAAM,kBAAkB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAmCrB,CAAC;AAEX,kEAAkE;AAClE,eAAO,MAAM,mBAAmB,aAAgB,CAAC;AAEjD;;;;;;;GAOG;AACH,eAAO,MAAM,WAAW,sXAQvB,CAAC;AAEF;;;GAGG;AACH,eAAO,MAAM,yBAAyB,wNAGrC,CAAC;AAEF,yDAAyD;AACzD,MAAM,MAAM,mBAAmB,GAAG,CAAC,CAAC,WAAW,CAAC,OAAO,yBAAyB,CAAC,CAAC;AAkClF;;;;;;;;;;GAUG;AACH,eAAO,MAAM,oBAAoB;;;;;;;;;;;;;;;;sQAKhC,CAAC;AAEF,yCAAyC;AACzC,MAAM,MAAM,cAAc,GAAG,CAAC,CAAC,WAAW,CAAC,OAAO,oBAAoB,CAAC,CAAC;AAExE;;;;;;;;;;GAUG;AACH,eAAO,MAAM,sBAAsB;;;;;;;;;;;;;;;;;;;;;;2MAYlC,CAAC;AAEF,0CAA0C;AAC1C,MAAM,MAAM,gBAAgB,GAAG,CAAC,CAAC,WAAW,CAAC,OAAO,sBAAsB,CAAC,CAAC;AAE5E;;;;;;;;;;;;;;;;;;GAkBG;AACH,eAAO,MAAM,0BAA0B;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;iUA+BtC,CAAC;AAEF,kDAAkD;AAClD,MAAM,MAAM,oBAAoB,GAAG,CAAC,CAAC,WAAW,CAAC,OAAO,0BAA0B,CAAC,CAAC;AAEpF,2EAA2E;AAC3E,eAAO,MAAM,0BAA0B,KAAK,CAAC;AAE7C;;;;;;;;;GASG;AACH,wBAAgB,0BAA0B,CAAC,MAAM,EAAE,oBAAoB,GAAG,KAAK,EAAE,CAEhF;AAED;;;;;;;;GAQG;AACH,wBAAgB,qBAAqB,CAAC,OAAO,EAAE,MAAM,GAAG,SAAS,EAAE,IAAI,EAAE,KAAK,CAAC,MAAM,CAAC,GAAG,KAAK,EAAE,CAK/F;AAED;;;;;;;GAOG;AACH,wBAAgB,yBAAyB,CAAC,KAAK,EAAE,OAAO,GAAG,WAAW,CAAC,oBAAoB,CAAC,CAE3F;AAED,oFAAoF;AACpF,eAAO,MAAM,mBAAmB,oBAAoB,CAAC;AAIrD;;;;;;;GAOG;AACH,eAAO,MAAM,0BAA0B;;;;;;;;4JAStC,CAAC;AAEF,2EAA2E;AAC3E,MAAM,MAAM,oBAAoB,GAAG,CAAC,CAAC,WAAW,CAAC,OAAO,0BAA0B,CAAC,CAAC;AAEpF;;;;;;;;;;;;;;;GAeG;AACH,eAAO,MAAM,4BAA4B;;;;;;;;;;;;;;;;;;8NAoBxC,CAAC;AAEF,gFAAgF;AAChF,MAAM,MAAM,sBAAsB,GAAG,CAAC,CAAC,WAAW,CAAC,OAAO,4BAA4B,CAAC,CAAC;AAaxF;;;;;;;;;;;;;GAaG;AACH,wBAAgB,4BAA4B,CAAC,QAAQ,EAAE,sBAAsB,GAAG,KAAK,EAAE,CAetF;AAED;;;;;;;;GAQG;AACH,wBAAgB,2BAA2B,CAAC,KAAK,EAAE,OAAO,GAAG,WAAW,CAAC,sBAAsB,CAAC,CAE/F"}