create-blocklet 0.9.6 → 0.9.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/common/.prettierrc +11 -1
- package/common/scripts/build-clean.mjs +0 -1
- package/common/scripts/bump-version.mjs +33 -29
- package/index.js +16 -10
- package/lib/did.js +10 -5
- package/package.json +1 -1
- package/templates/did-connect-dapp/.eslintrc.js +4 -0
- package/templates/did-connect-dapp/README.md +35 -0
- package/templates/did-connect-dapp/api/dev.js +5 -0
- package/templates/did-connect-dapp/api/hooks/pre-start.js +33 -0
- package/templates/did-connect-dapp/api/index.js +48 -0
- package/templates/did-connect-dapp/api/libs/auth.js +25 -0
- package/templates/did-connect-dapp/api/libs/env.js +9 -0
- package/templates/did-connect-dapp/api/libs/logger.js +3 -0
- package/templates/did-connect-dapp/api/libs/utils.js +70 -0
- package/templates/did-connect-dapp/api/routes/auth/index.js +15 -0
- package/templates/did-connect-dapp/api/routes/auth/request-digest-signature.js +51 -0
- package/templates/did-connect-dapp/api/routes/auth/request-multiple-claims.js +52 -0
- package/templates/did-connect-dapp/api/routes/auth/request-multiple-steps.js +57 -0
- package/templates/did-connect-dapp/api/routes/auth/request-nft.js +82 -0
- package/templates/did-connect-dapp/api/routes/auth/request-payment.js +72 -0
- package/templates/did-connect-dapp/api/routes/auth/request-profile.js +25 -0
- package/templates/did-connect-dapp/api/routes/auth/request-text-signature.js +44 -0
- package/templates/did-connect-dapp/api/routes/auth/request-transaction-signature.js +62 -0
- package/templates/did-connect-dapp/blocklet.md +5 -0
- package/templates/did-connect-dapp/blocklet.yml +57 -0
- package/templates/did-connect-dapp/index.html +17 -0
- package/templates/did-connect-dapp/package.json +86 -0
- package/templates/did-connect-dapp/src/app.jsx +20 -0
- package/templates/did-connect-dapp/src/assets/get_wallet_en.png +0 -0
- package/templates/did-connect-dapp/src/assets/get_wallet_zh.png +0 -0
- package/templates/did-connect-dapp/src/components/connect-item.jsx +39 -0
- package/templates/did-connect-dapp/src/components/connects/request-digest-signature.jsx +45 -0
- package/templates/did-connect-dapp/src/components/connects/request-multiple-claims.jsx +55 -0
- package/templates/did-connect-dapp/src/components/connects/request-multiple-steps.jsx +54 -0
- package/templates/did-connect-dapp/src/components/connects/request-nft.jsx +75 -0
- package/templates/did-connect-dapp/src/components/connects/request-payment.jsx +82 -0
- package/templates/did-connect-dapp/src/components/connects/request-profile.jsx +72 -0
- package/templates/did-connect-dapp/src/components/connects/request-text-signature.jsx +44 -0
- package/templates/did-connect-dapp/src/components/connects/request-transaction-signature.jsx +44 -0
- package/templates/did-connect-dapp/src/components/info-row.jsx +39 -0
- package/templates/did-connect-dapp/src/components/layout.jsx +26 -0
- package/templates/did-connect-dapp/src/index.jsx +6 -0
- package/templates/did-connect-dapp/src/libs/session.js +11 -0
- package/templates/did-connect-dapp/src/libs/utils.js +4 -0
- package/templates/did-connect-dapp/src/locales/en.js +115 -0
- package/templates/did-connect-dapp/src/locales/index.js +5 -0
- package/templates/did-connect-dapp/src/locales/zh.js +115 -0
- package/templates/did-connect-dapp/src/pages/main.jsx +95 -0
- package/templates/did-connect-dapp/template-info.json +12 -0
- package/templates/did-connect-dapp/vite.config.mjs +11 -0
- package/templates/did-wallet-dapp/blocklet.yml +1 -2
- package/templates/did-wallet-dapp/package.json +18 -18
- package/templates/express-api/blocklet.yml +0 -1
- package/templates/express-api/package.json +9 -8
- package/templates/html-static/blocklet.yml +0 -1
- package/templates/html-static/package.json +4 -3
- package/templates/monorepo/package.json +4 -3
- package/templates/monorepo/scripts/bump-version.mjs +36 -32
- package/templates/nestjs-api/blocklet.yml +0 -1
- package/templates/nestjs-api/package.json +16 -15
- package/templates/nextjs-dapp/blocklet.yml +0 -1
- package/templates/nextjs-dapp/package.json +7 -7
- package/templates/react-dapp/blocklet.yml +0 -1
- package/templates/react-dapp/package.json +16 -15
- package/templates/react-dapp-ts/blocklet.yml +0 -1
- package/templates/react-dapp-ts/package.json +19 -18
- package/templates/react-gun-dapp/blocklet.yml +0 -1
- package/templates/react-gun-dapp/package.json +15 -14
- package/templates/react-static/blocklet.yml +0 -1
- package/templates/react-static/package.json +11 -10
- package/templates/solidjs-dapp/blocklet.yml +0 -1
- package/templates/solidjs-dapp/package.json +14 -13
- package/templates/solidjs-static/blocklet.yml +0 -1
- package/templates/solidjs-static/package.json +9 -8
- package/templates/svelte-dapp/blocklet.yml +0 -1
- package/templates/svelte-dapp/package.json +13 -12
- package/templates/svelte-static/blocklet.yml +0 -1
- package/templates/svelte-static/package.json +9 -8
- package/templates/todo-list-example/blocklet.yml +0 -1
- package/templates/todo-list-example/package.json +13 -12
- package/templates/vue-dapp/blocklet.yml +0 -1
- package/templates/vue-dapp/package.json +16 -15
- package/templates/vue-static/blocklet.yml +0 -1
- package/templates/vue-static/package.json +11 -10
- package/templates/vue-ts-static/blocklet.yml +1 -2
- package/templates/vue-ts-static/package.json +12 -12
- package/templates/vue2-dapp/blocklet.yml +0 -1
- package/templates/vue2-dapp/package.json +13 -12
- package/templates/vue2-static/blocklet.yml +0 -1
- package/templates/vue2-static/package.json +9 -8
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
const { fromPublicKey } = require('@ocap/wallet');
|
|
2
|
+
const { toAddress, fromBase58, toBuffer } = require('@ocap/util');
|
|
3
|
+
const { toTypeInfo } = require('@arcblock/did');
|
|
4
|
+
|
|
5
|
+
const { verifyAssetClaim } = require('../../libs/utils');
|
|
6
|
+
const { wallet } = require('../../libs/auth');
|
|
7
|
+
const logger = require('../../libs/logger');
|
|
8
|
+
|
|
9
|
+
const validateAgentProof = (claim) => {
|
|
10
|
+
const ownerDid = toAddress(claim.ownerDid);
|
|
11
|
+
const ownerPk = fromBase58(claim.ownerPk);
|
|
12
|
+
if (!claim.agentProof) {
|
|
13
|
+
throw new Error('agent proof is empty');
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
if (typeof claim.agentProof === 'string') {
|
|
17
|
+
claim.agentProof = JSON.parse(claim.agentProof);
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
logger.info('claim.agentProof.nonce', claim.agentProof.nonce);
|
|
21
|
+
logger.info('claim.agentProof.signature', claim.agentProof.signature);
|
|
22
|
+
|
|
23
|
+
const { nonce } = claim.agentProof;
|
|
24
|
+
if (nonce < Math.ceil(Date.now() / 1000) - 5 * 60) {
|
|
25
|
+
throw new Error('agent proof is expired: ttl is 5 minutes');
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
const message = Buffer.concat([toBuffer(nonce.toString()), toBuffer(wallet.address)]);
|
|
29
|
+
const signer = fromPublicKey(ownerPk, toTypeInfo(ownerDid));
|
|
30
|
+
const signature = fromBase58(claim.agentProof.signature);
|
|
31
|
+
|
|
32
|
+
if (claim.type === 'asset') {
|
|
33
|
+
if (!signer.verify(message, signature)) {
|
|
34
|
+
throw new Error('agent proof is invalid for asset');
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
if (claim.type === 'verifiableCredential') {
|
|
39
|
+
if (!signer.verify(message, signature)) {
|
|
40
|
+
throw new Error('agent proof is invalid for vc');
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
const action = 'request-nft';
|
|
46
|
+
|
|
47
|
+
module.exports = {
|
|
48
|
+
action,
|
|
49
|
+
claims: {
|
|
50
|
+
assetOrVC: () => {
|
|
51
|
+
return {
|
|
52
|
+
description: 'Please provide NFT or VC to continue',
|
|
53
|
+
filters: [
|
|
54
|
+
{
|
|
55
|
+
type: ['NFTBadge', 'NFTCertificate'],
|
|
56
|
+
trustedIssuers: [
|
|
57
|
+
// wallet.address,
|
|
58
|
+
'zNKXAEjKYXEnf2hf18NjTQsa1JajA9gJ3haY',
|
|
59
|
+
],
|
|
60
|
+
},
|
|
61
|
+
],
|
|
62
|
+
};
|
|
63
|
+
},
|
|
64
|
+
},
|
|
65
|
+
onAuth: async ({ claims, challenge, updateSession }) => {
|
|
66
|
+
const asset = claims.find((x) => x.type === 'asset');
|
|
67
|
+
|
|
68
|
+
if (!asset) {
|
|
69
|
+
throw new Error('Neither NFT nor VC is provided');
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
logger.info(`${action}.onAuth.asset`, asset);
|
|
73
|
+
|
|
74
|
+
validateAgentProof(asset, challenge);
|
|
75
|
+
|
|
76
|
+
const assetState = await verifyAssetClaim({ claim: asset, challenge });
|
|
77
|
+
updateSession({
|
|
78
|
+
result: asset,
|
|
79
|
+
});
|
|
80
|
+
return { successMessage: `You provided asset: ${assetState.address}` };
|
|
81
|
+
},
|
|
82
|
+
};
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
/* eslint-disable no-console */
|
|
2
|
+
const { fromTokenToUnit } = require('@ocap/util');
|
|
3
|
+
const { fromAddress } = require('@ocap/wallet');
|
|
4
|
+
|
|
5
|
+
const { wallet, client } = require('../../libs/auth');
|
|
6
|
+
const { getTokenInfo, pickGasPayerHeaders } = require('../../libs/utils');
|
|
7
|
+
const env = require('../../libs/env');
|
|
8
|
+
const logger = require('../../libs/logger');
|
|
9
|
+
|
|
10
|
+
const action = 'request-payment';
|
|
11
|
+
module.exports = {
|
|
12
|
+
action,
|
|
13
|
+
claims: {
|
|
14
|
+
signature: async ({ userDid, userPk }) => {
|
|
15
|
+
const amount = 1;
|
|
16
|
+
const token = await getTokenInfo();
|
|
17
|
+
|
|
18
|
+
return {
|
|
19
|
+
type: 'TransferV2Tx',
|
|
20
|
+
data: {
|
|
21
|
+
from: userDid,
|
|
22
|
+
pk: userPk,
|
|
23
|
+
itx: {
|
|
24
|
+
to: wallet.address,
|
|
25
|
+
tokens: [
|
|
26
|
+
{
|
|
27
|
+
address: env.localTokenId,
|
|
28
|
+
value: fromTokenToUnit(amount, token.decimal).toString(),
|
|
29
|
+
},
|
|
30
|
+
],
|
|
31
|
+
},
|
|
32
|
+
},
|
|
33
|
+
description: `Please pay ${amount} ${token.symbol} to application`,
|
|
34
|
+
};
|
|
35
|
+
},
|
|
36
|
+
},
|
|
37
|
+
onAuth: async ({ req, claims, userDid, updateSession }) => {
|
|
38
|
+
try {
|
|
39
|
+
const claim = claims.find((x) => x.type === 'signature');
|
|
40
|
+
const tx = client.decodeTx(claim.origin);
|
|
41
|
+
const user = fromAddress(userDid);
|
|
42
|
+
if (claim.from) {
|
|
43
|
+
tx.from = claim.from;
|
|
44
|
+
}
|
|
45
|
+
if (claim.delegator) {
|
|
46
|
+
tx.delegator = claim.delegator;
|
|
47
|
+
}
|
|
48
|
+
const hash = await client.sendTransferV2Tx(
|
|
49
|
+
{
|
|
50
|
+
tx,
|
|
51
|
+
wallet: user,
|
|
52
|
+
signature: claim.sig,
|
|
53
|
+
},
|
|
54
|
+
pickGasPayerHeaders(req),
|
|
55
|
+
);
|
|
56
|
+
|
|
57
|
+
logger.info(`${action}.onAuth`, { claims, userDid, hash });
|
|
58
|
+
updateSession({
|
|
59
|
+
result: {
|
|
60
|
+
hash,
|
|
61
|
+
tx,
|
|
62
|
+
origin: claim.origin,
|
|
63
|
+
sig: claim.sig,
|
|
64
|
+
},
|
|
65
|
+
});
|
|
66
|
+
return { hash, tx: claim.origin };
|
|
67
|
+
} catch (err) {
|
|
68
|
+
logger.info(`${action}.onAuth.error`, err);
|
|
69
|
+
throw new Error('Send token failed!');
|
|
70
|
+
}
|
|
71
|
+
},
|
|
72
|
+
};
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
const omit = require('lodash/omit');
|
|
2
|
+
const logger = require('../../libs/logger');
|
|
3
|
+
|
|
4
|
+
const action = 'request-profile';
|
|
5
|
+
module.exports = {
|
|
6
|
+
action,
|
|
7
|
+
claims: {
|
|
8
|
+
profile: () => ({
|
|
9
|
+
description: 'Please provide your full profile',
|
|
10
|
+
fields: ['fullName', 'email', 'phone', 'signature', 'avatar', 'birthday'],
|
|
11
|
+
}),
|
|
12
|
+
},
|
|
13
|
+
|
|
14
|
+
onAuth: ({ userDid, userPk, claims, updateSession }) => {
|
|
15
|
+
const claim = claims.find((x) => x.type === 'profile');
|
|
16
|
+
logger.log(`${action}.onAuth`, { userDid, userPk, claim });
|
|
17
|
+
updateSession({
|
|
18
|
+
result: {
|
|
19
|
+
...omit(claim, ['type', 'signature']),
|
|
20
|
+
did: userDid,
|
|
21
|
+
pk: userPk,
|
|
22
|
+
},
|
|
23
|
+
});
|
|
24
|
+
},
|
|
25
|
+
};
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
/* eslint-disable no-console */
|
|
2
|
+
const { toTypeInfo } = require('@arcblock/did');
|
|
3
|
+
const { fromPublicKey } = require('@ocap/wallet');
|
|
4
|
+
const { fromBase58 } = require('@ocap/util');
|
|
5
|
+
|
|
6
|
+
const logger = require('../../libs/logger');
|
|
7
|
+
const { getRandomMessage } = require('../../libs/utils');
|
|
8
|
+
|
|
9
|
+
const action = 'request-text-signature';
|
|
10
|
+
module.exports = {
|
|
11
|
+
action,
|
|
12
|
+
claims: {
|
|
13
|
+
signature: () => {
|
|
14
|
+
const data = getRandomMessage();
|
|
15
|
+
|
|
16
|
+
return {
|
|
17
|
+
description: 'Please sign the text',
|
|
18
|
+
type: 'mime:text/plain',
|
|
19
|
+
data,
|
|
20
|
+
};
|
|
21
|
+
},
|
|
22
|
+
},
|
|
23
|
+
|
|
24
|
+
onAuth: ({ userDid, userPk, claims, updateSession }) => {
|
|
25
|
+
const type = toTypeInfo(userDid);
|
|
26
|
+
const user = fromPublicKey(userPk, type);
|
|
27
|
+
const claim = claims.find((x) => x.type === 'signature');
|
|
28
|
+
|
|
29
|
+
logger.info(`${action}.onAuth`, { userPk, userDid, claim });
|
|
30
|
+
|
|
31
|
+
if (claim.origin) {
|
|
32
|
+
if (user.verify(claim.origin, claim.sig, claim.method !== 'none') === false) {
|
|
33
|
+
throw new Error('Invalid origin signature');
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
updateSession({
|
|
38
|
+
result: {
|
|
39
|
+
origin: fromBase58(claim.origin).toString(),
|
|
40
|
+
sig: claim.sig,
|
|
41
|
+
},
|
|
42
|
+
});
|
|
43
|
+
},
|
|
44
|
+
};
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
/* eslint-disable no-console */
|
|
2
|
+
const { toTypeInfo } = require('@arcblock/did');
|
|
3
|
+
const { fromPublicKey } = require('@ocap/wallet');
|
|
4
|
+
const { toTxHash } = require('@ocap/mcrypto');
|
|
5
|
+
const { toBase58 } = require('@ocap/util');
|
|
6
|
+
|
|
7
|
+
const logger = require('../../libs/logger');
|
|
8
|
+
const env = require('../../libs/env');
|
|
9
|
+
const { wallet, client } = require('../../libs/auth');
|
|
10
|
+
|
|
11
|
+
const action = 'request-transaction-signature';
|
|
12
|
+
|
|
13
|
+
module.exports = {
|
|
14
|
+
action,
|
|
15
|
+
claims: {
|
|
16
|
+
signature: async ({ userPk, userDid }) => {
|
|
17
|
+
const value = await client.fromTokenToUnit(1);
|
|
18
|
+
const type = toTypeInfo(userDid);
|
|
19
|
+
|
|
20
|
+
const encoded = await client.encodeTransferV2Tx({
|
|
21
|
+
tx: {
|
|
22
|
+
itx: {
|
|
23
|
+
to: wallet.address,
|
|
24
|
+
tokens: [
|
|
25
|
+
{
|
|
26
|
+
address: env.localTokenId,
|
|
27
|
+
value: value.toString(),
|
|
28
|
+
},
|
|
29
|
+
],
|
|
30
|
+
},
|
|
31
|
+
},
|
|
32
|
+
wallet: fromPublicKey(userPk, type),
|
|
33
|
+
});
|
|
34
|
+
|
|
35
|
+
const origin = toBase58(encoded.buffer);
|
|
36
|
+
|
|
37
|
+
return {
|
|
38
|
+
description: 'Please sign the transaction',
|
|
39
|
+
type: 'fg:t:transaction',
|
|
40
|
+
data: origin,
|
|
41
|
+
};
|
|
42
|
+
},
|
|
43
|
+
},
|
|
44
|
+
|
|
45
|
+
onAuth: ({ userDid, userPk, claims, updateSession }) => {
|
|
46
|
+
const claim = claims.find((x) => x.type === 'signature');
|
|
47
|
+
const tx = client.decodeTx(claim.origin);
|
|
48
|
+
|
|
49
|
+
logger.info(`${action}.onAuth`, { userPk, userDid, claim });
|
|
50
|
+
const buffer = Buffer.from(claim.origin);
|
|
51
|
+
const hash = toTxHash(buffer);
|
|
52
|
+
|
|
53
|
+
updateSession({
|
|
54
|
+
result: {
|
|
55
|
+
hash,
|
|
56
|
+
tx,
|
|
57
|
+
origin: claim.origin,
|
|
58
|
+
sig: claim.sig,
|
|
59
|
+
},
|
|
60
|
+
});
|
|
61
|
+
},
|
|
62
|
+
};
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
title: DID Connect Playground
|
|
2
|
+
description: A Blocklet show DID Connect Playground
|
|
3
|
+
keywords:
|
|
4
|
+
- blocklet
|
|
5
|
+
- react
|
|
6
|
+
- did-connect
|
|
7
|
+
group: dapp
|
|
8
|
+
did: ''
|
|
9
|
+
main: api/index.js
|
|
10
|
+
author:
|
|
11
|
+
name: ArcBlock
|
|
12
|
+
email: blocklet@arcblock.io
|
|
13
|
+
url: https://github.com/blocklet
|
|
14
|
+
repository:
|
|
15
|
+
type: git
|
|
16
|
+
url: git+https://github.com/blocklet/create-blocklet.git
|
|
17
|
+
specVersion: 1.2.8
|
|
18
|
+
version: 0.1.0
|
|
19
|
+
logo: logo.png
|
|
20
|
+
files:
|
|
21
|
+
- dist
|
|
22
|
+
- logo.png
|
|
23
|
+
- screenshots
|
|
24
|
+
- api/hooks/pre-start.js
|
|
25
|
+
interfaces:
|
|
26
|
+
- type: web
|
|
27
|
+
name: publicUrl
|
|
28
|
+
path: /
|
|
29
|
+
prefix: '*'
|
|
30
|
+
port: BLOCKLET_PORT
|
|
31
|
+
protocol: http
|
|
32
|
+
community: ''
|
|
33
|
+
documentation: ''
|
|
34
|
+
homepage: ''
|
|
35
|
+
license: ''
|
|
36
|
+
payment:
|
|
37
|
+
price: []
|
|
38
|
+
share: []
|
|
39
|
+
timeout:
|
|
40
|
+
start: 60
|
|
41
|
+
requirements:
|
|
42
|
+
server: '>=1.16.31'
|
|
43
|
+
os: '*'
|
|
44
|
+
cpu: '*'
|
|
45
|
+
scripts:
|
|
46
|
+
preStart: node api/hooks/pre-start.js
|
|
47
|
+
dev: npm run start
|
|
48
|
+
environments:
|
|
49
|
+
- name: CHAIN_HOST
|
|
50
|
+
description: What's endpoint of the chain?
|
|
51
|
+
required: true
|
|
52
|
+
default: https://beta.abtnetwork.io/api/
|
|
53
|
+
secure: false
|
|
54
|
+
capabilities:
|
|
55
|
+
navigation: true
|
|
56
|
+
screenshots: []
|
|
57
|
+
components: []
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
<!DOCTYPE html>
|
|
2
|
+
<html lang="en">
|
|
3
|
+
|
|
4
|
+
<head>
|
|
5
|
+
<meta charset="UTF-8" />
|
|
6
|
+
<link rel="icon" href="/favicon.ico?imageFilter=convert&f=png&w=32" />
|
|
7
|
+
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0" />
|
|
8
|
+
<meta name="theme-color" content="#4F6AF5" />
|
|
9
|
+
</head>
|
|
10
|
+
|
|
11
|
+
<body>
|
|
12
|
+
<noscript> You need to enable JavaScript to run this app. </noscript>
|
|
13
|
+
<div id="app"></div>
|
|
14
|
+
<script type="module" src="/src/index.jsx"></script>
|
|
15
|
+
</body>
|
|
16
|
+
|
|
17
|
+
</html>
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "did-connect-dapp",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"private": "true",
|
|
5
|
+
"scripts": {
|
|
6
|
+
"dev": "blocklet dev",
|
|
7
|
+
"lint": "eslint src api --ext .mjs,.js,.jsx,.ts,.tsx",
|
|
8
|
+
"lint:fix": "npm run lint -- --fix",
|
|
9
|
+
"start": "cross-env NODE_ENV=development nodemon api/dev.js -w api",
|
|
10
|
+
"clean": "node scripts/build-clean.mjs",
|
|
11
|
+
"bundle": "npm run bundle:client && npm run bundle:api",
|
|
12
|
+
"bundle:client": "vite build",
|
|
13
|
+
"bundle:api": "npm run clean && blocklet bundle --compact --create-release",
|
|
14
|
+
"deploy": "npm run bundle && blocklet deploy .blocklet/bundle",
|
|
15
|
+
"upload": "npm run bundle && blocklet upload .blocklet/release/blocklet.json",
|
|
16
|
+
"prepare": "npx simple-git-hooks",
|
|
17
|
+
"bump-version": "zx --quiet scripts/bump-version.mjs"
|
|
18
|
+
},
|
|
19
|
+
"lint-staged": {
|
|
20
|
+
"*.{mjs,js,jsx,ts,tsx}": [
|
|
21
|
+
"prettier --write",
|
|
22
|
+
"eslint"
|
|
23
|
+
],
|
|
24
|
+
"*.{css,less,scss,json,graphql}": [
|
|
25
|
+
"prettier --write"
|
|
26
|
+
]
|
|
27
|
+
},
|
|
28
|
+
"browserslist": {
|
|
29
|
+
"production": [
|
|
30
|
+
">0.2%",
|
|
31
|
+
"not dead",
|
|
32
|
+
"not op_mini all"
|
|
33
|
+
],
|
|
34
|
+
"development": [
|
|
35
|
+
"last 1 chrome version",
|
|
36
|
+
"last 1 firefox version",
|
|
37
|
+
"last 1 safari version"
|
|
38
|
+
]
|
|
39
|
+
},
|
|
40
|
+
"dependencies": {
|
|
41
|
+
"@arcblock/did": "^1.18.135",
|
|
42
|
+
"@arcblock/did-auth": "^1.18.135",
|
|
43
|
+
"@arcblock/did-auth-storage-nedb": "^1.7.1",
|
|
44
|
+
"@blocklet/sdk": "^1.16.31",
|
|
45
|
+
"@ocap/client": "^1.18.135",
|
|
46
|
+
"@ocap/mcrypto": "^1.18.135",
|
|
47
|
+
"@ocap/util": "^1.18.135",
|
|
48
|
+
"@ocap/wallet": "^1.18.135",
|
|
49
|
+
"cookie-parser": "^1.4.6",
|
|
50
|
+
"dotenv-flow": "^4.1.0",
|
|
51
|
+
"express": "^4.21.0",
|
|
52
|
+
"express-async-errors": "^3.1.1",
|
|
53
|
+
"lodash": "^4.17.21"
|
|
54
|
+
},
|
|
55
|
+
"devDependencies": {
|
|
56
|
+
"@arcblock/did-connect": "^2.10.38",
|
|
57
|
+
"@arcblock/eslint-config": "^0.3.2",
|
|
58
|
+
"@arcblock/ux": "^2.10.38",
|
|
59
|
+
"@blocklet/ui-react": "^2.10.38",
|
|
60
|
+
"@emotion/react": "^11.13.3",
|
|
61
|
+
"@emotion/styled": "^11.13.0",
|
|
62
|
+
"@iconify-icons/material-symbols": "^1.2.58",
|
|
63
|
+
"@iconify/react": "^5.0.2",
|
|
64
|
+
"@mui/material": "^5.16.7",
|
|
65
|
+
"@trivago/prettier-plugin-sort-imports": "^4.3.0",
|
|
66
|
+
"@vitejs/plugin-react": "^4.3.1",
|
|
67
|
+
"bumpp": "^9.5.2",
|
|
68
|
+
"cross-env": "^7.0.3",
|
|
69
|
+
"eslint": "^8.57.1",
|
|
70
|
+
"flat": "^6.0.1",
|
|
71
|
+
"lint-staged": "^15.2.10",
|
|
72
|
+
"nodemon": "^3.1.7",
|
|
73
|
+
"prettier": "^3.3.3",
|
|
74
|
+
"prop-types": "^15.8.1",
|
|
75
|
+
"react": "~18.2.0",
|
|
76
|
+
"react-dom": "~18.2.0",
|
|
77
|
+
"rimraf": "^5.0.10",
|
|
78
|
+
"vite": "^5.4.8",
|
|
79
|
+
"vite-plugin-blocklet": "^0.9.8",
|
|
80
|
+
"vite-plugin-svgr": "^4.2.0",
|
|
81
|
+
"zx": "^8.1.8"
|
|
82
|
+
},
|
|
83
|
+
"simple-git-hooks": {
|
|
84
|
+
"pre-commit": "npx lint-staged"
|
|
85
|
+
}
|
|
86
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { LocaleProvider } from '@arcblock/ux/lib/Locale/context';
|
|
2
|
+
import { ThemeProvider } from '@arcblock/ux/lib/Theme';
|
|
3
|
+
|
|
4
|
+
import { SessionProvider } from './libs/session';
|
|
5
|
+
import { translations } from './locales';
|
|
6
|
+
import Main from './pages/main';
|
|
7
|
+
|
|
8
|
+
function App() {
|
|
9
|
+
return (
|
|
10
|
+
<ThemeProvider>
|
|
11
|
+
<LocaleProvider translations={translations}>
|
|
12
|
+
<SessionProvider>
|
|
13
|
+
<Main />
|
|
14
|
+
</SessionProvider>
|
|
15
|
+
</LocaleProvider>
|
|
16
|
+
</ThemeProvider>
|
|
17
|
+
);
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export default App;
|
|
Binary file
|
|
Binary file
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
/* eslint-disable react/require-default-props */
|
|
2
|
+
import ConnectButton from '@arcblock/did-connect/lib/Button';
|
|
3
|
+
import { useLocaleContext } from '@arcblock/ux/lib/Locale/context';
|
|
4
|
+
import { Box, Card, CardContent, Typography } from '@mui/material';
|
|
5
|
+
import PropTypes from 'prop-types';
|
|
6
|
+
|
|
7
|
+
export default function ConnectItem({ title, description = null, result = null, onClick = () => {} }) {
|
|
8
|
+
const { t } = useLocaleContext();
|
|
9
|
+
return (
|
|
10
|
+
<Box>
|
|
11
|
+
<Typography variant="h6" component="h5" color="textPrimary">
|
|
12
|
+
{title}
|
|
13
|
+
</Typography>
|
|
14
|
+
{description ? (
|
|
15
|
+
<Typography variant="body1" color="text.secondary" gutterBottom>
|
|
16
|
+
{description}
|
|
17
|
+
</Typography>
|
|
18
|
+
) : null}
|
|
19
|
+
<ConnectButton onClick={onClick} />
|
|
20
|
+
{result ? (
|
|
21
|
+
<Card sx={{ mt: 2 }} variant="outlined">
|
|
22
|
+
<CardContent>
|
|
23
|
+
<Typography sx={{ fontSize: 14 }} color="text.secondary" gutterBottom>
|
|
24
|
+
{t('result')}
|
|
25
|
+
</Typography>
|
|
26
|
+
{result}
|
|
27
|
+
</CardContent>
|
|
28
|
+
</Card>
|
|
29
|
+
) : null}
|
|
30
|
+
</Box>
|
|
31
|
+
);
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
ConnectItem.propTypes = {
|
|
35
|
+
title: PropTypes.any.isRequired,
|
|
36
|
+
description: PropTypes.any,
|
|
37
|
+
result: PropTypes.any,
|
|
38
|
+
onClick: PropTypes.func,
|
|
39
|
+
};
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { useLocaleContext } from '@arcblock/ux/lib/Locale/context';
|
|
2
|
+
import { useState } from 'react';
|
|
3
|
+
|
|
4
|
+
import { useSessionContext } from '../../libs/session';
|
|
5
|
+
import ConnectItem from '../connect-item';
|
|
6
|
+
import InfoRow from '../info-row';
|
|
7
|
+
|
|
8
|
+
export default function RequestDigestSignature() {
|
|
9
|
+
const [result, setResult] = useState(null);
|
|
10
|
+
const { locale, t } = useLocaleContext();
|
|
11
|
+
const { connectApi } = useSessionContext();
|
|
12
|
+
|
|
13
|
+
const requestFn = () => {
|
|
14
|
+
const action = 'request-digest-signature';
|
|
15
|
+
setResult(null);
|
|
16
|
+
connectApi.open({
|
|
17
|
+
locale,
|
|
18
|
+
action,
|
|
19
|
+
onSuccess(res) {
|
|
20
|
+
setResult(res.result);
|
|
21
|
+
},
|
|
22
|
+
messages: {
|
|
23
|
+
title: t('claims.requestDigestSig.connect.title'),
|
|
24
|
+
scan: t('claims.requestDigestSig.connect.scan'),
|
|
25
|
+
},
|
|
26
|
+
});
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
return (
|
|
30
|
+
<ConnectItem
|
|
31
|
+
title={t('claims.requestDigestSig.title')}
|
|
32
|
+
description={t('claims.requestDigestSig.description')}
|
|
33
|
+
onClick={requestFn}
|
|
34
|
+
result={
|
|
35
|
+
result ? (
|
|
36
|
+
<>
|
|
37
|
+
<InfoRow name={t('claims.requestDigestSig.result.origin')} value={result.origin} />
|
|
38
|
+
<InfoRow name={t('claims.requestDigestSig.result.digest')} value={result.digest} />
|
|
39
|
+
<InfoRow name={t('claims.requestDigestSig.result.signature')} value={result.sig} />
|
|
40
|
+
</>
|
|
41
|
+
) : null
|
|
42
|
+
}
|
|
43
|
+
/>
|
|
44
|
+
);
|
|
45
|
+
}
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import { useLocaleContext } from '@arcblock/ux/lib/Locale/context';
|
|
2
|
+
import { Box, Typography } from '@mui/material';
|
|
3
|
+
import { useState } from 'react';
|
|
4
|
+
|
|
5
|
+
import { useSessionContext } from '../../libs/session';
|
|
6
|
+
import ConnectItem from '../connect-item';
|
|
7
|
+
import InfoRow from '../info-row';
|
|
8
|
+
|
|
9
|
+
export default function RequestMultipleClaims() {
|
|
10
|
+
const [result, setResult] = useState(null);
|
|
11
|
+
const { locale, t } = useLocaleContext();
|
|
12
|
+
const { connectApi } = useSessionContext();
|
|
13
|
+
|
|
14
|
+
const requestFn = () => {
|
|
15
|
+
const action = 'request-multiple-claims';
|
|
16
|
+
setResult(null);
|
|
17
|
+
connectApi.open({
|
|
18
|
+
locale,
|
|
19
|
+
action,
|
|
20
|
+
onSuccess(res) {
|
|
21
|
+
setResult(res.result);
|
|
22
|
+
},
|
|
23
|
+
messages: {
|
|
24
|
+
title: t('claims.requestMultipleClaims.connect.title'),
|
|
25
|
+
scan: t('claims.requestMultipleClaims.connect.scan'),
|
|
26
|
+
},
|
|
27
|
+
});
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
return (
|
|
31
|
+
<ConnectItem
|
|
32
|
+
title={t('claims.requestMultipleClaims.title')}
|
|
33
|
+
description={t('claims.requestMultipleClaims.description')}
|
|
34
|
+
onClick={requestFn}
|
|
35
|
+
result={
|
|
36
|
+
result ? (
|
|
37
|
+
<>
|
|
38
|
+
<Typography variant="h6">{t('step1.title')}</Typography>
|
|
39
|
+
<Box sx={{ pl: 1 }}>
|
|
40
|
+
<InfoRow name={t('claims.requestMultipleClaims.result.origin')} value={result[0].origin} />
|
|
41
|
+
<InfoRow name={t('claims.requestMultipleClaims.result.signature')} value={result[0].sig} />
|
|
42
|
+
</Box>
|
|
43
|
+
|
|
44
|
+
<Typography variant="h6">{t('step2.title')}</Typography>
|
|
45
|
+
<Box sx={{ pl: 1 }}>
|
|
46
|
+
<InfoRow name={t('claims.requestMultipleClaims.result.origin')} value={result[1].origin} />
|
|
47
|
+
<InfoRow name={t('claims.requestMultipleClaims.result.digest')} value={result[1].digest} />
|
|
48
|
+
<InfoRow name={t('claims.requestMultipleClaims.result.signature')} value={result[1].sig} />
|
|
49
|
+
</Box>
|
|
50
|
+
</>
|
|
51
|
+
) : null
|
|
52
|
+
}
|
|
53
|
+
/>
|
|
54
|
+
);
|
|
55
|
+
}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import { useLocaleContext } from '@arcblock/ux/lib/Locale/context';
|
|
2
|
+
import { Box, Typography } from '@mui/material';
|
|
3
|
+
import { useState } from 'react';
|
|
4
|
+
|
|
5
|
+
import { useSessionContext } from '../../libs/session';
|
|
6
|
+
import ConnectItem from '../connect-item';
|
|
7
|
+
import InfoRow from '../info-row';
|
|
8
|
+
|
|
9
|
+
export default function RequestMultipleSteps() {
|
|
10
|
+
const [result, setResult] = useState(null);
|
|
11
|
+
const { locale, t } = useLocaleContext();
|
|
12
|
+
const { connectApi } = useSessionContext();
|
|
13
|
+
|
|
14
|
+
const requestFn = () => {
|
|
15
|
+
const action = 'request-multiple-steps';
|
|
16
|
+
setResult(null);
|
|
17
|
+
connectApi.open({
|
|
18
|
+
locale,
|
|
19
|
+
action,
|
|
20
|
+
onSuccess(res) {
|
|
21
|
+
setResult(res.result);
|
|
22
|
+
},
|
|
23
|
+
messages: {
|
|
24
|
+
title: t('claims.requestMultipleSteps.connect.title'),
|
|
25
|
+
scan: t('claims.requestMultipleSteps.connect.scan'),
|
|
26
|
+
},
|
|
27
|
+
});
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
return (
|
|
31
|
+
<ConnectItem
|
|
32
|
+
title={t('claims.requestMultipleSteps.title')}
|
|
33
|
+
description={t('claims.requestMultipleSteps.description')}
|
|
34
|
+
onClick={requestFn}
|
|
35
|
+
result={
|
|
36
|
+
result ? (
|
|
37
|
+
<>
|
|
38
|
+
<Typography variant="h6">Step 1</Typography>
|
|
39
|
+
<Box sx={{ pl: 1 }}>
|
|
40
|
+
<InfoRow name={t('claims.requestMultipleSteps.result.origin')} value={result[0].origin} />
|
|
41
|
+
<InfoRow name={t('claims.requestMultipleSteps.result.signature')} value={result[0].sig} />
|
|
42
|
+
</Box>
|
|
43
|
+
<Typography variant="h6">Step 2</Typography>
|
|
44
|
+
<Box sx={{ pl: 1 }}>
|
|
45
|
+
<InfoRow name={t('claims.requestMultipleSteps.result.origin')} value={result[1].origin} />
|
|
46
|
+
<InfoRow name={t('claims.requestMultipleSteps.result.digest')} value={result[1].digest} />
|
|
47
|
+
<InfoRow name={t('claims.requestMultipleSteps.result.signature')} value={result[1].sig} />
|
|
48
|
+
</Box>
|
|
49
|
+
</>
|
|
50
|
+
) : null
|
|
51
|
+
}
|
|
52
|
+
/>
|
|
53
|
+
);
|
|
54
|
+
}
|