A lightweight TypeScript SDK to resolve did:near:<identifier> DIDs from a NEAR smart contract registry and/or NEAR accounts.
npm install near-api-js bs58Or with Yarn:
yarn add near-api-js bs58import NearDIDResolver from './NearDIDResolver';
const resolver = new NearDIDResolver(
'registry.contract.testnet',
'https://rpc.testnet.near.org',
'testnet'
);
const didDocument = await resolver.resolveDID('did:near:CF5RiJYh4EVmEt8UADTjoP3XaZo1NPWxv6w5TmkLqjpR');
console.log(didDocument);new NearDIDResolver(contractId: string, rpcUrl: string, networkId: string = 'testnet')contractId: The NEAR smart contract that implementsidentity_owner.rpcUrl: RPC URL for NEAR network.networkId: NEAR network (e.g.,testnet,mainnet).
Resolves a did:near:<base58PublicKey | accountId> into a DID Document.
- Calls the
identity_ownerview function on the specified contract. - If the result is a
did:near:<key>, it strips the prefix. - Otherwise assumes it’s a base58-encoded Ed25519 public key.
{
"@context": "https://w3id.org/did/v1",
"id": "did:near:CF5Ri...",
"verificationMethod": [
{
"id": "did:near:CF5Ri...#owner",
"type": "Ed25519VerificationKey2018",
"controller": "did:near:CF5Ri...",
"publicKeyBase58": "CF5Ri..."
}
],
"authentication": ["did:near:CF5Ri...#owner"],
"assertionMethod": ["did:near:CF5Ri...#owner"]
}Fetches the public key of a NEAR account directly from the RPC (not from the registry).
-
Uses Ed25519 public keys encoded in base58.
-
Compatible with
Ed25519VerificationKey2018type in the DID Document spec. -
Supports keys stored:
- Directly on-chain in the smart contract
- From NEAR account keys using
view_account
To test your resolver:
- Deploy a compatible
NearDIDRegistrycontract. - Register a DID and owner.
- Call
resolveDID(...)from this SDK. - Validate it against a DID resolver or JWT verifier like
did-jwt.
MIT — use freely in your own DID resolver stacks and NEAR integrations.