Portkey DID SDK

npm-image-version npm-image-downloads

Getting started

Typescript

The @portkey/did library is a collection of modules that contain functionality for the did ecosystem.

  • @portkey/accounts is for the portkey account.

  • @portkey/utils is for the portkey utils.

  • @portkey/contracts is for the portkey contracts.

  • @portkey/graphql is for the portkey graphql.

  • @portkey/contracts is for the portkey request.

  • @portkey/types is for the portkey types.

  • @portkey/utils is for the portkey utils.

  • @portkey/validator is for the portkey validator.

Installation

Using NPM

npm install @portkey/did

Using Yarn

yarn add @portkey/did

After that, you need configure did server node、graphQL node、storage suite.

class Store implements IStorageSuite {
  async getItem(key: string) {
    return localStorage.getItem(key);
  }
  async setItem(key: string, value: string) {
    return localStorage.setItem(key, value);
  }
  async removeItem(key: string) {
    return localStorage.removeItem(key);
  }
}
did.setConfig({
  requestDefaults: {
    baseURL: "your did server node",
    timeout: "timeout", // optional default 8000ms
  },
  graphQLUrl: "your graphQL node",
  storageMethod: new Store(),
});

That’s it! Now you can use the did object.

API Reference

Typescript

Portkey

portkey.did
did.setConfig

Where you configure did server node, graphQL node, storage suite.

did.setConfig({
  requestDefaults: {
    baseURL: "you did server node",
    timeout: "timeout", // optional default 8000ms
  },
  graphQLUrl: "your graphQL node",
  storageMethod: "your storage suite",
});
did.login

loginAccount

Email or phone number login.

did.login(type: 'loginAccount', params: AccountLoginParams): Promise<LoginResult>;

Example

did.login("loginAccount", {
  chainId: "chainId",
  loginGuardianIdentifier: "loginGuardianIdentifier",
  guardiansApproved: [
    {
      type: "Email",
      identifier: "identifier",
      verifierId: "verifierId",
      verificationDoc: "verificationDoc",
      signature: "signature",
    },
  ],
  extraData: "extraData",
  context: {
    requestId: "requestId",
    clientId: "clientId",
  },
});

type:scan

Logged in management to add management.

login(type: 'scan', params: ScanLoginParams): Promise<true>;

Example

did.login('scan',{
  chainId: 'chainId',
  caHash: 'caHash',
  managerInfo: {
    address: 'address',
    extraData: 'extraData'
  };
})

getLoginStatus

getLoginStatus(params: { chainId: ChainId; sessionId: string }): Promise<RecoverStatusResult>;

Example

did.getLoginStatus({
  chainId: "chainId",
  sessionId: "sessionId",
});
Logout
logout(params: EditManagementParams): Promise<boolean>;

Example

did.logout({ chainId: "chainId" });
register
register(params: Omit<RegisterParams, 'manager'>): Promise<RegisterResult>;

Example

did.register({
  type: "Email",
  loginGuardianIdentifier: "loginGuardianIdentifier",
  extraData: "extraData",
  chainId: "chainId",
  verifierId: "verifierId",
  verificationDoc: "verificationDoc",
  signature: "signature",
  context: {
    requestId: "requestId",
    clientId: "clientId",
  },
});

getRegisterStatus

getRegisterStatus(params: { chainId: ChainId; sessionId: string }): Promise<RegisterStatusResult>;

Example

did.getRegisterStatus({
  chainId: "chainId",
  sessionId: "sessionId",
});
getHolderInfo

getHolderInfo by graphQL.

getHolderInfo(params: Pick<GetHolderInfoParams, 'manager' | 'chainId'>): Promise<GetCAHolderByManagerResult>;

Example

did.getHolderInfo({
  manager: "manager", // optional
  chainId: "chainId",
});

getHolderInfo by server.

getHolderInfo(params: Omit<GetHolderInfoParams, 'manager'>): Promise<IHolderInfo>;

Example

did.getHolderInfo({
  caHash: "caHash", // loginGuardianIdentifier and caHash choose one
  loginGuardianIdentifier: "loginGuardianIdentifier", // loginGuardianIdentifier and caHash choose one
  chainId: "chainId",
});
getVerifierServers

Get the VerifierServer information of the corresponding chain.

getVerifierServers(chainId: ChainId): Promise<VerifierItem[]>;

Example

did.getVerifierServers({
  chainId: "chainId",
});
Services

services.getVerificationCode

send verification code.

getVerificationCode(params: SendVerificationCodeParams): Promise<SendVerificationCodeResult>;

Example

did.services.getVerificationCode({
  chainId: "chainId",
  guardianIdentifier: "guardianIdentifier",
  type: "Email",
  verifierId: "verifierId",
});

services.verifyVerificationCode

verify verification code.

verifyVerificationCode(params: VerifyVerificationCodeParams): Promise<VerifyVerificationCodeResult>;

Example

did.services.verifyVerificationCode({
  verifierSessionId: "verifierSessionId",
  chainId: "chainId",
  guardianIdentifier: "guardianIdentifier",
  verifierId: "verifierId",
  verificationCode: "verificationCode",
});