---
name: upbond-transfer-api
description: Integrate the UPBOND Transfer API (JPYC transfers from a corporate vault). Use when writing or reviewing a client for POST /v1/transactions, the private_key_jwt token flow, the RSA-OAEP-SHA256 signing-secret envelope, idempotency/externalTxId handling, or status polling.
license: Proprietary — UPBOND Inc. Redistribution to customers permitted.
---

# UPBOND Transfer API — integration skill

Canonical docs: https://docs.upbond.io/transfer-api/ (Japanese). Machine-readable:
- https://docs.upbond.io/llms.txt (page index) and https://docs.upbond.io/llms-full.txt
- https://docs.upbond.io/transfer-api/openapi.yaml (OpenAPI 3.1, version 1.3.0)

Read the OpenAPI file before generating any request or type. Never invent fields: unknown
body fields on POST and unknown query parameters on the list endpoint are rejected with
HTTP 400 / code 1101.

## Configuration the customer receives from UPBOND

- API key ID (sent as `X-API-Key`; equals the OAuth client_id)
- API host name per environment (STG / PROD); the auth server is
  `https://auth.stg.upbond.io` (STG) or `https://auth.upbond.io` (PROD)
- Vault account ID (`source.id`), `assetId` (one per environment: `JPYC_FUJI` on STG —
  Avalanche Fuji, chainId 43113; `JPYC_AVALANCHE` on PROD — Avalanche C-Chain, chainId 43114;
  gas is paid in AVAX), and the confirmation count for `COMPLETED`

Secrets: the customer's RSA private key (for the client assertion) and the **signing secret**
(base64, 44 chars, issued once by the vault owner in the UPBOND wallet settings > API access).
Read both from environment variables or a secret manager. Never print or log them.

## Authentication (every request)

Headers: `X-API-Key: <apiKeyId>`, `Authorization: Bearer <access_token>`,
`Content-Type: application/json` on POST.

Access token = OAuth 2.0 client_credentials with `private_key_jwt` (RFC 7523):

1. Build a JWT (RS256, signed with the registered private key) with
   `iss` = `sub` = apiKeyId, `aud` = auth server URL (e.g. `https://auth.upbond.io`),
   `jti` = fresh UUID, `iat` = now, `exp` = now + 60.
2. `POST {authBase}/oauth/token` (form-urlencoded) with
   `grant_type=client_credentials`,
   `client_assertion_type=urn:ietf:params:oauth:client-assertion-type:jwt-bearer`,
   `client_assertion=<jwt>`. Do NOT send `scope` or `resource`; `client_id` is optional and,
   if sent, must equal `iss`.
3. The response `access_token` is OPAQUE (not a JWT). `expires_in` is 300. Cache it and
   reuse until 30 s before expiry. Do not fetch a token per request.

Rate limit: 10 requests/s, burst 20, per API key → 429 with `Retry-After` (seconds).

## Signing-secret envelope (auto-signing mode, required on every POST)

1. `GET /v1/upbond/signer` → `{ keyId, publicKeyPem, attestation, expiresAt }`.
   Cache until `expiresAt`; refresh at least daily. `attestation` is currently empty.
2. Build the request body first (everything except `signer`), then the BOUND plaintext
   (73 bytes, version 1):
   - byte 0: `0x01`
   - bytes 1–32: the RAW 32 bytes obtained by base64-decoding the signing secret
   - bytes 33–64: SHA-256 of the canonical request = the UTF-8 string
     `assetId + "\n" + source.id + "\n" + destination.oneTimeAddress.address + "\n" + amount + "\n" + feeLevel + "\n" + externalTxId + "\n" + note`,
     each value EXACTLY as it appears in the body (no case folding, no amount reformatting;
     `feeLevel` is `MEDIUM` when the body omits it; `note` is the empty string when the body
     omits it, so the string then ends with a newline; `operation` and `signer` are not
     included). `externalTxId` must not contain control characters; strings must be
     well-formed Unicode (no lone surrogates) — 400 / 1102 otherwise.
   - bytes 65–72: `issuedAt`, unsigned 64-bit big-endian Unix epoch MILLISECONDS, taken when
     the envelope is built (must be within ±5 min of UPBOND's clock)
3. Envelope = RSA-OAEP over those 73 bytes with hash SHA-256, MGF1-SHA-256, empty label;
   output standard base64 (≤ 4096 chars).
   - Node: `publicEncrypt({ key, padding: RSA_PKCS1_OAEP_PADDING, oaepHash: 'sha256' }, Buffer.concat([Buffer.from([1]), secret, createHash('sha256').update(canonical, 'utf8').digest(), ts]))`
     where `ts = Buffer.alloc(8); ts.writeBigUInt64BE(BigInt(Date.now()))`.
   - PHP: phpseclib3 `PublicKeyLoader::load($pem)->withPadding(RSA::ENCRYPTION_OAEP)->withHash('sha256')->withMGFHash('sha256')`
     over `"\x01" . $secret . hash('sha256', $canonical, true) . pack('J', (int) floor(microtime(true) * 1000))`.
     On PHP <= 8.4, `openssl_public_encrypt()` is SHA-1-only and WILL fail (422 / 1411): use
     phpseclib3 there (PHP 8.5 adds a `digest_algo` argument).
4. Send `"signer": { "keyId": "<keyId>", "envelope": "<base64>" }` in the POST body.
   Build a fresh envelope for every request, right before sending. The envelope is bound to
   that body: another body is 422 / 1414, an `issuedAt` outside ±5 min is 422 / 1415, the
   legacy unbound 32-byte plaintext is 422 / 1411, and re-sending a used envelope is a
   duplicate `externalTxId` (409 / 1201) that signs nothing. Never log or persist envelopes.

## Creating a transfer

`POST /v1/transactions` with header `Idempotency-Key` (≤ 255 chars; use the same value as
`externalTxId`) and body:

```json
{
  "operation": "TRANSFER",
  "assetId": "<assetId>",
  "source": { "type": "VAULT_ACCOUNT", "id": "<vaultAccountId>" },
  "destination": { "type": "ONE_TIME_ADDRESS", "oneTimeAddress": { "address": "0x…40 hex…" } },
  "amount": "12345.00",
  "externalTxId": "<customer id, unique per vault forever, 1–255 chars>",
  "note": "optional, ≤ 500 chars",
  "feeLevel": "MEDIUM",
  "signer": { "keyId": "…", "envelope": "…" }
}
```

- `amount` is a decimal STRING in JPYC units, ≤ 18 fractional digits, > 0.
- The call signs and broadcasts synchronously: allow a 60–90 s HTTP timeout.
- Response is `{ id, status }` only. `status` is usually `BROADCASTING`; `BLOCKED` = over the
  per-transaction or daily cumulative cap (resets 00:00 JST), or destination not on the owner's
  allowlist; `FAILED` = read `subStatus` via GET. `txHash` comes from GET. A failed
  broadcast RPC is not terminal: the record stays `BROADCASTING` and UPBOND reconciles it from
  chain. A missing receipt alone never fails it (see "Retries and idempotency"). `signedBy` is `[]` until
  the transfer reaches `BROADCASTING`, then `["api-factor"]`.

## Retries and idempotency (get these right)

- 429 and 5xx, timeouts, lost responses: retry with the SAME `Idempotency-Key` and body.
- 4xx responses are NOT recorded against the key; fix the cause and retry with the same key.
- 422 / 1410 (stale `keyId`): re-fetch `/v1/upbond/signer`, rebuild the envelope, re-send the
  SAME request (same `Idempotency-Key`, same `externalTxId`). The idempotency comparison
  excludes `signer`, so a new envelope is not a "different body".
- 422 / 1414 or 1415 (envelope bound to another body / outside the time window): rebuild the
  envelope from the exact body being sent, right before sending, and re-send the same request.
- 409 / 1201 (`externalTxId` exists): do not retry; call
  `GET /v1/transactions/external_tx_id/{externalTxId}`.
- 409 / 1202: same key with a different body — use a new key. 409 / 1203: in progress — wait.
- 422 / 1303 (vault reconnect required): stop and notify an operator; the vault owner must
  reconnect. 422 / 1304 (no owner-signed transfer limits, or revoked) and 422 / 1305 (owner's
  limits expired / not yet valid): stop and notify an operator; the VAULT OWNER signs limits in
  the wallet (Settings > API access > Transfer API limits) — UPBOND cannot set or raise them.
  Afterwards the same request can be re-sent unchanged. 403 / 1412 or 1413: signing secret
  revoked / not registered.
- `FAILED` / `CONNECTIVITY_ERROR`: UPBOND could not read the chain (balance / nonce) before
  signing. Nothing was signed or broadcast and the signing secret is fine; re-create later
  under a NEW externalTxId (the failed one is terminal).
- 500 / 5000 AFTER the transaction was created: it may stay `PENDING_SIGNATURE`. A retry with
  the same Idempotency-Key returns that transaction's `{ id, status }` and does not sign again.
  If it stays `PENDING_SIGNATURE` for minutes, escalate to UPBOND. Never create a second
  externalTxId for the same payout.
- NEVER re-create a transaction that is still `BROADCASTING` / `CONFIRMING`, however long it
  has been there. The signed transaction stays valid until its nonce is spent and can settle
  later (e.g. when fees fall), so a second externalTxId can pay twice. UPBOND only reports
  `FAILED` / `DROPPED_BY_BLOCKCHAIN` once the transaction provably cannot settle (another
  transaction of the vault spent its nonce and is confirmed). If it stays `BROADCASTING` for
  more than 30 minutes, escalate to UPBOND with `id` and `txHash`.
- A terminal transaction (`COMPLETED`, `BLOCKED`, `REJECTED`, `CANCELLED`, `FAILED`) can never be
  retried under the same `externalTxId`; create a new one with a new id.

## Reading status

- `GET /v1/transactions/{txId}` and `GET /v1/transactions/external_tx_id/{externalTxId}`.
- `GET /v1/transactions?after=<ms>&before=<ms>&status=A,B&orderBy=createdAt|lastUpdated&sort=ASC|DESC&limit=1..500`.
  Follow the `next-page` response header verbatim (it carries `cursor`). Poll every ≥ 30 s with
  an `after` that overlaps the previous window by 10 minutes; re-read unfinished ids
  individually.
- Only `COMPLETED` is business completion. Terminal set: COMPLETED, BLOCKED, REJECTED,
  CANCELLED, FAILED. REJECTED / CANCELLED (and subStatus REJECTED_BY_USER / TIMEOUT) are
  reserved for approval mode and are not emitted today. Treat unknown statuses as in progress.
- `subStatus` values: CONFIRMED, BLOCKED_BY_POLICY, INSUFFICIENT_FUNDS, INSUFFICIENT_FUNDS_FOR_FEE,
  REJECTED_BY_BLOCKCHAIN, DROPPED_BY_BLOCKCHAIN, SIGNING_FAILED, OWNER_REAUTH_REQUIRED,
  CONNECTIVITY_ERROR, REJECTED_BY_USER, TIMEOUT.

## Error envelope

`{ "message": string, "code": number }`. Branch on `code`, never on `message`. Full table:
https://docs.upbond.io/transfer-api/errors

## Before declaring the integration done

1. Token endpoint returns 200 and `GET /v1/transactions?limit=1` returns 200 on STG.
2. One STG transfer reaches `COMPLETED` and the client handles `BROADCASTING → CONFIRMING →
   COMPLETED` plus a `FAILED` with `subStatus`.
3. The 1410 path (re-fetch signer, same Idempotency-Key) and the 409 / 1201 path are exercised.
4. No secret appears in logs, code, or version control.
