Get unlimited public & private packages + team-based management with npm Teams.Learn more »

@arcblock/did-agent-storage

1.0.13 • Public • Published

@arcblock/did-agent-storage

styled with prettier

Interface for define a storage class that can be used by [@arcblock/did-auth].

Table of Contents

Motivation & Spec

Fields

Possible fields to exist in a did-agent storage record

  • authorizeId: Primary key
  • ownerDid: Owner DID
  • agentDid: Agent DID
  • appDid: Application DID
  • appPk: Application public key
  • appName: Application name
  • appDescription: Application description
  • appIcon: Application logo/icon
  • certificateContent: Application authorize content

APIs

Basic APIs that a did-agent storage should support:

  • create(authorizeId, payload): 创建记录
  • update(authorizeId, updates): 更新记录
  • read(authorizeId):按 authorizeId 查询
  • delete(authorizeId):删除记录
  • listByApp(appDid): 按应用查询
  • listByOwner(ownerDid): 按所有者查询

Install

npm install @arcblock/did-agent-storage
// or
yarn add @arcblock/did-agent-storage

Usage

const StorageInterface = require('@arcblock/did-agent-storage');
let storage = {};
module.exports = class MemoryAgentStorage extends StorageInterface {
  read(authorizeId) {
    return storage[authorizeId];
  }
 
  create(authorizeId, payload = {}) {
    storage[authorizeId] = Object.assign({ authorizeId }, payload);
    return this.read(authorizeId);
  }
 
  update(authorizeId, updates) {
    delete updates.authorizeId;
    storage[authorizeId] = Object.assign(storage[authorizeId], updates);
    return storage[authorizeId];
  }
 
  delete(authorizeId) {
    delete storage[authorizeId];
  }
 
  listByOwner(ownerDid) {
    Object.keys(storage)
      .filter(x => storage[x].ownerDid === ownerDid)
      .map(x => storage[x]);
  }
 
  listByApp(appDid) {
    Object.keys(storage)
      .filter(x => storage[x].appDid === appDid)
      .map(x => storage[x]);
  }
 
  clear() {
    storage = {};
  }
};

Contributors

Name Website
wangshijun https://ocap.arcblock.io

Install

npm i @arcblock/did-agent-storage

DownloadsWeekly Downloads

120

Version

1.0.13

License

Apache-2.0

Unpacked Size

7.46 kB

Total Files

5

Last publish

Collaborators

  • avatar
  • avatar