1.7.1 • Published 2 years ago

@arcblock/did-agent-storage v1.7.1

Weekly downloads
1
License
Apache-2.0
Repository
github
Last release
2 years ago

@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

NameWebsite
wangshijunhttps://ocap.arcblock.io
1.7.1

2 years ago

1.7.0

2 years ago

1.6.3

3 years ago

1.6.2

3 years ago

1.6.1

3 years ago

1.6.0

3 years ago

1.5.8

3 years ago

1.5.7

3 years ago

1.5.6

3 years ago

1.5.5

3 years ago

1.5.4

3 years ago

1.5.3

3 years ago

1.5.2

3 years ago

1.5.1

3 years ago

1.5.0

3 years ago

1.4.8

3 years ago

1.4.7

3 years ago

1.4.6

3 years ago

1.4.5

3 years ago

1.4.4

3 years ago

1.4.3

3 years ago

1.4.2

4 years ago

1.4.1

4 years ago

1.4.0

4 years ago

1.2.7

4 years ago

1.0.13

4 years ago

1.0.4

4 years ago

1.0.0

4 years ago

0.41.0

4 years ago

0.40.11

4 years ago

0.40.10

4 years ago

0.40.9

5 years ago