Skip to content
LogoLogo

WalletApi2VcSigner

Sign the DDO with a key held in walt.id wallet-api2 (POST /wallet/{walletId}/keys/{keyId}/sign), authenticated by an address sign-in with the sign-ddo scope. The asset's issuer is then a DID of the address's wallet, as when the market publishes.

Usage

const  = .({
  : 'https://wallet.example.org/api/address-gateway',
  ,
  : ['present', 'sign-ddo']
})
 
// Trusted public JWKs keyed by their full DID verification method IDs.
const : <string, > = .(
  ('./issuer-verification-methods.json', 'utf8')
)
const  = new (.())
 
const  = new ({ 
  : ., 
  : 'publisher-key', 
  : 'did:web:example.org', 
  : () => .() 
}) 
 
const  = await .(, { , ,  })

An organisation admin turns on "Sign asset descriptions (DDOs)" for the address in the wallet UI. Signing as the organisation's did:web also needs "Present as …".

Options

OptionTypePurpose
signInWalletApi2TokenSourcecredentials.signIn, or an AddressSignIn, with the scope sign-ddo. Required.
keyIdstringThe wallet-api2 key to sign with. Required.
issuerstringThe DID the credential is issued as; keyId's key must be one of its verification methods. Required.
resolveVerificationKeyFunctionRequired. Return the trusted public JWK authorised by the issuer for this exact verification method DID URL, or undefined for an unknown or unauthorised method. Throw or reject if the lookup fails.
walletIdstringDefault: the address's wallet.
walletApistringDefault: the sign-in's gateway.
allowInsecureTransport, timeoutMs, fetchImplAs for AddressSignIn.

The document it signs

For address tokens wallet-api2 signs only the market's DDO credential: top-level @context, id, type (['VerifiableCredential']), issuer, version, credentialSubject and additionalDdos, and in credentialSubject only chainId, nftAddress, metadata, services, credentials, license, dataspace and stats. So, unlike the other signers, it adds no iss, sub or jti.

prepareDocument(ddo) returns the DDO in that shape (it leaves out credentialSubject.id, credentialSubject.version and indexer fields). publish() and edit() call it before they validate, so the document that is validated, signed and returned in PublishResponse.ddo is one document. sign() refuses a DDO with other fields before sending it.

The answer must be a compact JWS of exactly the posted credential, with a kid of the issuer's DID document (<issuer>#…), a signature that verifies with that method's trusted public key, and a header and signature within JWS_SIGNING_ALLOWANCE (1024 characters); the publish flow then checks the payload against the validated DDO, as for every signer.

The field lists are exported as WALLET_API2_DDO_FIELDS and WALLET_API2_DDO_SUBJECT_FIELDS, for code that builds such a document itself.

Errors

Every error is a WaltIdWalletError with code and a hint that says who fixes it:

  • code: 'scope_not_enabled': the sign-in has no sign-ddo scope (refused before anything is sent), or DDO signing is off for the address;
  • code: 'not_a_ddo': the DDO has fields wallet-api2 does not sign (call prepareDocument() first; refused before anything is sent), or wallet-api2 refused the body's shape;
  • code: 'issuer_mismatch': the DDO declares another issuer than issuer;
  • A thrown or rejected key lookup produces code: 'verification_key_lookup_failed'.
  • code: 'signature_invalid': the answer is not a JWS nautilus accepts: a header with members other than alg, kid and typ (no crit, b64, jwk), an algorithm that is not a JOSE signature algorithm (none, HS256), a kid outside the issuer's DID document, a payload with a duplicate key or other than the posted credential, or a header and signature over JWS_SIGNING_ALLOWANCE;
  • no code, status 400 or 404: wallet-api2's own refusal ("Key not found", "The DDO issuer is not a DID of this wallet"), with a hint to check keyId, walletId and the issuer;
  • code: 'did_web_holder_disabled': the issuer is the organisation's did:web and "Present as …" is off;
  • the sign-in codes of AddressSignIn.