Skip to content
LogoLogo

WalletApi2CredentialProvider

Answers the OpenID4VP 1.0 (DCQL) request of a node with the native SSI module (pontusx-node, ssiInitiate) from walt.id wallet-api2, the wallet of the pontusx identity stack. nautilus opens the session before and polls ssiStatus after (PolicySessionResolver), so this is only needed for assets with an SSIpolicyV2 (or deprecated SSIpolicy) entry.

For a node with a policy server, use WaltIdCredentialProvider.

Usage

const  = await .(, {
  ,
  : new ({ 
    : 'https://wallet-api.example.org', 
    :  
  }) 
})
 
// Unchanged at the call site: the exchange happens inside.
const {  } = await .({ : 'did:ope:1234abcd...' })

token is the account's session token (a Hanko session JWT on the pontusx platform): pass the token, or a function that returns a current one; it is asked for on every request and never logged. Scripts and CI jobs sign in with the key of an organisation address instead: withAddressSignIn.

withAddressSignIn

const  = .({ 
  : 'https://wallet.example.org/api/address-gateway', 
   
  // chainId?: from signer.provider.getNetwork()
  // smartAccount?: 'auto' (default) | true | false
  // scopes?: ['present'] (default) | ['present', 'sign-ddo']
}) 
 
.(await ..()) // what the address may do
const  = await .(, { ,  })

Builds an AddressSignIn for the wallet UI's address gateway and a provider bound to the same gateway; credentials.signIn is the sign-in (for check(), signOut() and WalletApi2VcSigner). Takes the options of AddressSignIn and of the provider (walletId, holderDid, expectedVerifierHost, onSelectCredentials, allowInsecureTransport). With it:

  • the provider presents from the address's own wallet (the token is for that wallet only), and lists no wallets;
  • prepare() signs in, checks that the address signed in is the consumer ("Signed in as 0xA, but the order is for 0xB", signer_mismatch) and that a pinned walletId is its wallet (wallet_mismatch), and runs check(): no verifier, a missing grant for the node's announced verifier (or expectedVerifierHost when unannounced; case-insensitive host, :443 implied), or nothing it may present (no_presentable_credentials) fails before any node session is opened. The answer is reused for the same token for at most a minute, and dropped when prepare() fails, so an admin's fix takes effect at the next call;
  • a preview evicted by newer previews of the same token (handle_evicted) is made again once. That is a new preview: onSelectCredentials is asked again.

Setup and CI guidance: Sign in from scripts and CI.

Options

OptionTypePurpose
walletApistringwallet-api2 base URL. Required unless wallet is given.
tokenstring | () => string | Promise<string> | WalletApi2TokenSourceThe account's session token, or a token source (an AddressSignIn). Required with walletApi.
walletWalletApi2Supply your own client instead (a backend-for-frontend, tests).
walletIdstringPin a wallet. By default the organisation's wallet of the consumer's address (GET /org/wallets).
holderDidstringThe DID to sign as. By default wallet-api2's choice for the request.
expectedVerifierHoststringThe verifier host to require when the node does not announce one.
onSelectCredentials(matches, preview) => Promise<Record<string, string[]>>Choose credentials (ids by DCQL query id) from a UI.
allowInsecureTransportbooleanAccept plain http:// wallet and request URLs on a non-loopback host. Default false.

What it does

  1. prepare(), before nautilus opens the node session: finds the consumer's wallet (GET /org/wallets), so a missing wallet or a rejected token fails with wallet-setup and leaves no pending session at the node.
  2. Checks the request: an openid4vp:// URL whose request_uri is https:// (or http:// on a loopback host) and on the node's announced verifier host (status.ssi.verifierPublicHost).
  3. POST /wallet/{walletId}/credentials/present/preview-handle: wallet-api2 resolves the request once and keeps it behind a single-use handle.
  4. Checks the preview, and declines it (reject-handle) when the presentation would be posted off the verifier host, the wallet offers credentials for a DCQL query the node did not ask for, or transaction_data is not the node's org.oceanenterprise.transaction-data.asset-access item for this consumer, asset and service.
  5. POST …/present/submit-handle with the chosen credentials: exactly the request that was previewed is signed and sent.

Errors

A CredentialPresentationError with reason:

  • request-invalid: a check above failed, or the wallet found the request invalid; also a policy-server challenge (protocol: 'policy-server');
  • wallet-setup: no wallet for the consumer's address, or wallet-api2 refused the token (401/403);
  • no-matching-credential: a required combination cannot be met (details.missing);
  • none-selected: onSelectCredentials chose nothing, or something not offered;
  • wallet-failed: wallet-api2 failed;
  • verifier-rejected: the verifier refused the presentation. nautilus then reads ssiStatus and throws a PolicyDeniedError naming the failed checks, with this error as cause;
  • sign-in: the address could not sign in, its token was refused, or a Hanko token was sent to the address gateway;
  • not-permitted (address sign-in only): the address may not do this; an organisation admin changes its settings.

With an address token, details.code carries wallet-api2's or the gateway's code (with details.hint, status, retryAfter), also for wallet-failed (e.g. rate_limited), and no-matching-credential adds that organisation credentials appear only once an admin put the address on their access list. Every code, its cause and who fixes it: AddressSignIn errors. A Hanko token keeps the reasons above (wallet-setup for a 401/403, except the gateway's hanko_token_not_accepted).