1.7.1 • Published 2 years ago
@arcblock/did-auth-storage-keystone v1.7.1
@arcblock/did-auth-storage-keystone
Storage engine that uses keystone.js to store data, implements interfaces defined in
@arcblock/did-auth-storage
.
Table of Contents
Install
npm install @arcblock/did-auth-storage-keystone keystone
// or
yarn add @arcblock/did-auth-storage-keystone keystone
Usage
1. Create model when bootstrap keystone
const KeystoneStorage = require('@arcblock/did-auth-storage-keystone');
const keystone = require('keystone');
KeystoneStorage.init();
2. Create storage instance when setup routes
const { Handlers, Authenticator } = require('@arcblock/did-auth');
const { fromSecretKey, WalletType } = require('@arcblock/forge-wallet');
const KeystoneStorage = require('@arcblock/did-auth-storage-keystone');
const Mcrypto = require('@arcblock/mcrypto');
const keystone = require('keystone');
const type = WalletType({
role: Mcrypto.types.RoleType.ROLE_APPLICATION,
pk: Mcrypto.types.KeyType.ED25519,
hash: Mcrypto.types.HashType.SHA3,
});
const wallet = fromSecretKey(process.env.APP_SK, type).toJSON();
// Setup keystone.js
keystone.set('routes', app => {
const handler = new Handlers({
tokenGenerator: req => req.sessionID + Date.now(),
tokenStorage: new KeystoneStorage(),
authenticator: new Authenticator({
wallet,
baseUrl: 'http://wangshijun.natapp1.cc',
appInfo: {
chainHost: 'http://did-workshop.arcblock.co:8210/api',
chainId: 'forge',
chainToken: 'TBA',
copyright: 'https://example-application/copyright',
decimals: 16,
description: 'Starter projects to develop web application on forge',
icon: '/images/logo@2x.png',
name: 'Forge Web Starter',
path: 'https://arcwallet.io/i/',
publisher: `did:abt:${wallet.address}`,
subtitle: 'Starter projects to develop web application on forge',
},
}),
});
// Enable payment
handler.attach({
app,
action: 'payment',
claims: {
signature: {
txType: 'TransferTx',
txData: {
to: wallet.address,
value: {
value: fromTokenToUnit(100).toBuffer(),
minus: false,
},
},
description: 'Please pay 100 TBA to unlock the secret document',
},
},
onAuth: async ({ claims, did }) => {
console.log('pay.onAuth', { claims, did });
},
onComplete: (req, { did }) => {
console.log('pay.onComplete', { did });
},
});
// Now keystone app have route handlers attached to the following url
// - `GET /api/did/payment/token` create new token
// - `GET /api/did/payment/status` check for token status
// - `GET /api/did/payment/auth` create auth response
// - `POST /api/did/payment/auth` process payment request
});
Contributors
Name | Website |
---|---|
wangshijun | https://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.0
4 years ago
0.41.0
4 years ago
0.40.10
4 years ago
0.40.9
5 years ago
0.40.6
5 years ago
0.40.5
5 years ago
0.40.0
5 years ago
0.39.7
5 years ago
0.39.3
5 years ago
0.39.1
5 years ago
0.39.0
5 years ago
0.38.10
5 years ago
0.21.1
5 years ago
0.21.0
5 years ago
0.20.1
5 years ago
0.20.0
5 years ago
0.19.0
5 years ago
0.18.0
5 years ago
0.17.1
5 years ago
0.17.0
5 years ago