AccessKeyTokenSource
AccessKeyTokenSource is a WalletApi2TokenSource for an access key (pxk_…) that an
organisation admin issued in the wallet UI. It exchanges the key at the wallet UI's API gateway
(POST auth/access-key/token) for access tokens (pxt_…). It authorizes each wallet call with
Authorization: DPoP pxt_… and a fresh DPoP proof.
You rarely make one yourself.
WalletApi2CredentialProvider.withAccessKey
and WalletApi2VcSigner.withAccessKey make one and
expose it as tokenSource. The guide
Use an access key in scripts, CI and MCP covers setup and CI.
Usage
const = new ({
: 'https://wallet.example.org/api/gateway',
: .. as string
})
const = await .() // asks GET auth/account what the key may do
.(., .)
await .() // ends the token. The key keeps working.
// Or read PONTUSX_ACCESS_KEY or PONTUSX_ACCESS_KEY_FILE, and PONTUSX_WALLET_URL
const = .()Options
| Option | Type | Purpose |
|---|---|---|
gateway | string | The API gateway, <wallet URL>/api/gateway (AccessKeyTokenSource.gatewayUrl(walletUrl) builds it). Required. It must use https:// and be written as a URL parser reads it. |
accessKey | string | The key, pxk_…. nautilus checks its form and CRC-32 offline. Give this or accessKeyFile. |
accessKeyFile | string | A file that holds the key (a mounted secret). nautilus reads and trims it at once. It reads the file again when the gateway refuses the key, so it picks up a rotated key. |
scopes | ('present' | 'sign_ddo')[] | Defaults to ['present']. |
walletId, address | string | The wallet to act from, for a key with several wallets. The provider defaults address to the consumer. |
organization | string | The organisation the key must belong to. nautilus checks it on every token and in check(). |
resource | string | The RFC 8707 resource, which is wallet-api2's ACCESS_KEYS_PUBLIC_URL. Defaults to gateway. |
actor | string | () => string | undefined | Promise<…> | An opaque end-user id that nautilus sends as X-Access-Key-Actor on wallet calls, for the audit log. Printable ASCII (0x20 to 0x7e, spaces allowed), 1 to 128 characters, not blank. nautilus refuses a value that contains pxk_ or pxt_ (any case) or a JWT with invalid_request before it sends anything. A function may return undefined for no actor. It only attributes calls and must never hold an inbound token. |
dpopSigner | DpopSigner | { jwk, sign(input) } for a DPoP key held elsewhere (HSM, KMS, a key pinned to the access key). Defaults to a new non-extractable P-256 key in memory. A signer that throws or answers a signature that is not 64 bytes fails with dpop_signer_failed. |
allowInsecureTransport | boolean | Accept http:// on localhost, 127.0.0.1 or ::1 (a local stack). Other hosts always need https://. |
timeoutMs | number | The timeout of each request, 1 to 2147483647 ms. Defaults to 30 s. |
fetchImpl | typeof fetch | A fetch implementation for tests. |
Methods and properties
| Member | What it does |
|---|---|
getToken(signal?) | Returns a current token, the cached one or a new one. Concurrent callers share one request. |
authorize({ method, url, signal }) | Returns the Authorization and DPoP headers, and X-Access-Key-Actor, for one request to the gateway. Refuses any other URL with wrong_endpoint. |
invalidate(token?) | Forgets the token, if it is still the current one. |
check(signal?) | Calls GET auth/account and returns the key id and name, organisation, wallet and address, scopes, expiry, credential ids, presentAsOrg, ddoSigning, unboundRequests and the DDO signing identity (signing: { keyId, did }). It first forgets the refusals the source answers from memory for 60 seconds, so it asks the gateway again. For a key with several wallets, pin walletId or address, or the gateway answers wallet_required. |
revoke(signal?) | Ends the current token at the gateway, with its proof. Waits for a pending token request first. Also ends the tokens of earlier revocations that failed for a passing reason, and those of the per-address sources the provider made. |
revokeKey(signal?) | Revokes the key itself and all its tokens. You cannot undo it. |
keyId | The key id, ak_…. It is not secret. |
walletId, address, organization | The values of the current token, once the gateway issued one. |
gateway, endpoint, scopes, resource | The configured values. |
toJSON(), toString(), util.inspect | Show the key id and the display form pxk_<id>…<last 4>, never the key or a token. The last 4 are the last 4 characters of the full key, as the wallet UI shows them. |
parseAccessKey(value) checks a key offline and returns { keyId, display }.
Token handling
- nautilus sends the key only in the form body of
POST auth/access-key/token(withgrant_type,resource,scopeandwallet_idoraddress) and ofrevokeKey(), withredirect: 'error'. It never puts the key in a header, a URL or a log, and never sends it to a wallet route. - nautilus checks each token answer for the
pxt_form, the typeDPoP, a lifetime of 1 s to 24 h, the scopes asked for, the key id, and the expected organisation, address and wallet. - nautilus uses a token until 30 seconds before it expires, or until half its lifetime when
that is under a minute. Then it renews the token once for all callers. If a renewal fails for
a passing reason (
rate_limited, a network error), nautilus keeps the old token while it has more than 5 seconds left. It revokes a renewed token's predecessor in the background. - When a wallet call gets
token_invalidortoken_expired, nautilus gets one new token and sends the call once more. Afterdpop_invalid, it sends the call once more with a fresh proof. - A coded
401is retried by its code only.dpop_requiredoraccess_key_not_accepted_herenever fetch a new token, even whenWWW-Authenticatesaysinvalid_token. - The source answers a refusal that a new request would only repeat from memory, so it does
not send the key again.
invalid_client,key_revokedandkey_expiredstay for the life of the source.key_suspended,key_disabled,access_keys_not_allowed_for_organization,ip_not_allowed,invalid_target,invalid_scopeandorganization_mismatchstay for 60 seconds, or untilcheck(). Thewallet_*refusals andconsumer_mismatchstay for 60 seconds for the address asked for. WithaccessKeyFilethe source reads the file again meanwhile and uses a changed key at once. - After a
429the source asks for no token untilRetry-Afterhas passed (seconds or an HTTP date) and at least a backoff of 1 s, doubled per429in a row up to 60 s. It uses a token that still works meanwhile.retryAfteron the error is in seconds. - A token that the source refuses after the gateway issued it (another organisation, wallet, address or scope) is revoked in the background, so it does not hold a live-token slot.
- One source holds one token and one DPoP key, so it is safe in a long-running server. Each
process or replica makes its own source. Together they must stay under the key's
maxLiveTokens. A provider made bywithAccessKeywithoutwalletIdoraddressholds one token per consumer address on the same DPoP key, so concurrent orders for different addresses never share a token.
Errors
The source throws WaltIdWalletError with code and hint (who fixes it), and with status
and retryAfter when they are known. The guide's
error table lists the codes and their causes.