Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(create-blocklet): use onConnect in did-connect-dapp #366

Merged
merged 2 commits into from
Sep 29, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,15 @@ const action = 'request-digest-signature';

module.exports = {
action,
claims: {
signature: () => {
return {
description: 'Please sign the digest',
digest: toBase58(hasher(data, 1)),
};
},
onConnect() {
return {
signature: () => {
return {
description: 'Please sign the digest',
digest: toBase58(hasher(data, 1)),
};
},
};
},

onAuth: ({ userDid, userPk, claims, updateSession }) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,26 +11,28 @@ const action = 'request-multiple-claims';

module.exports = {
action,
claims: {
signText: [
'signature',
() => {
return {
type: 'mime:text/plain',
data: getRandomMessage(),
description: 'Please sign the text',
};
},
],
signDigest: [
'signature',
() => {
return {
description: 'Please sign the digest',
digest: toBase58(hasher(data, 1)),
};
},
],
onConnect() {
return {
signText: [
'signature',
() => {
return {
type: 'mime:text/plain',
data: getRandomMessage(),
description: 'Please sign the text',
};
},
],
signDigest: [
'signature',
() => {
return {
description: 'Please sign the digest',
digest: toBase58(hasher(data, 1)),
};
},
],
};
},

onAuth: ({ userDid, userPk, claims, updateSession }) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,25 +11,27 @@ const action = 'request-multiple-steps';

module.exports = {
action,
claims: [
{
signature: () => {
return {
type: 'mime:text/plain',
data: getRandomMessage(),
description: 'Please sign the text',
};
onConnect() {
return [
{
signature: () => {
return {
type: 'mime:text/plain',
data: getRandomMessage(),
description: 'Please sign the text',
};
},
},
},
{
signature: () => {
return {
description: 'Please sign the digest',
digest: toBase58(hasher(data, 1)),
};
{
signature: () => {
return {
description: 'Please sign the digest',
digest: toBase58(hasher(data, 1)),
};
},
},
},
],
];
},

onAuth: ({ userDid, userPk, claims, step, req, updateSession }) => {
logger.info(`${action}.onAuth`, { step, userPk, userDid, claims });
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,21 +46,23 @@ const action = 'request-nft';

module.exports = {
action,
claims: {
assetOrVC: () => {
return {
description: 'Please provide NFT or VC to continue',
filters: [
{
type: ['NFTBadge', 'NFTCertificate'],
trustedIssuers: [
// wallet.address,
'zNKXAEjKYXEnf2hf18NjTQsa1JajA9gJ3haY',
],
},
],
};
},
onConnect() {
return {
assetOrVC: () => {
return {
description: 'Please provide NFT or VC to continue',
filters: [
{
type: ['NFTBadge', 'NFTCertificate'],
trustedIssuers: [
// wallet.address,
'zNKXAEjKYXEnf2hf18NjTQsa1JajA9gJ3haY',
],
},
],
};
},
};
},
onAuth: async ({ claims, challenge, updateSession }) => {
const asset = claims.find((x) => x.type === 'asset');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,29 +10,31 @@ const logger = require('../../libs/logger');
const action = 'request-payment';
module.exports = {
action,
claims: {
signature: async ({ userDid, userPk }) => {
const amount = 1;
const token = await getTokenInfo();
onConnect() {
return {
signature: async ({ userDid, userPk }) => {
const amount = 1;
const token = await getTokenInfo();

return {
type: 'TransferV2Tx',
data: {
from: userDid,
pk: userPk,
itx: {
to: wallet.address,
tokens: [
{
address: env.localTokenId,
value: fromTokenToUnit(amount, token.decimal).toString(),
},
],
return {
type: 'TransferV2Tx',
data: {
from: userDid,
pk: userPk,
itx: {
to: wallet.address,
tokens: [
{
address: env.localTokenId,
value: fromTokenToUnit(amount, token.decimal).toString(),
},
],
},
},
},
description: `Please pay ${amount} ${token.symbol} to application`,
};
},
description: `Please pay ${amount} ${token.symbol} to application`,
};
},
};
},
onAuth: async ({ req, claims, userDid, updateSession }) => {
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,13 @@ const logger = require('../../libs/logger');
const action = 'request-profile';
module.exports = {
action,
claims: {
profile: () => ({
description: 'Please provide your full profile',
fields: ['fullName', 'email', 'phone', 'signature', 'avatar', 'birthday'],
}),
onConnect() {
return {
profile: () => ({
description: 'Please provide your full profile',
fields: ['fullName', 'email', 'phone', 'signature', 'avatar', 'birthday'],
}),
};
},

onAuth: ({ userDid, userPk, claims, updateSession }) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,18 @@ const { getRandomMessage } = require('../../libs/utils');
const action = 'request-text-signature';
module.exports = {
action,
claims: {
signature: () => {
const data = getRandomMessage();
onConnect() {
return {
signature: () => {
const data = getRandomMessage();

return {
description: 'Please sign the text',
type: 'mime:text/plain',
data,
};
},
return {
description: 'Please sign the text',
type: 'mime:text/plain',
data,
};
},
};
},

onAuth: ({ userDid, userPk, claims, updateSession }) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,34 +12,36 @@ const action = 'request-transaction-signature';

module.exports = {
action,
claims: {
signature: async ({ userPk, userDid }) => {
const value = await client.fromTokenToUnit(1);
const type = toTypeInfo(userDid);

const encoded = await client.encodeTransferV2Tx({
tx: {
itx: {
to: wallet.address,
tokens: [
{
address: env.localTokenId,
value: value.toString(),
},
],
onConnect() {
return {
signature: async ({ userPk, userDid }) => {
const value = await client.fromTokenToUnit(1);
const type = toTypeInfo(userDid);

const encoded = await client.encodeTransferV2Tx({
tx: {
itx: {
to: wallet.address,
tokens: [
{
address: env.localTokenId,
value: value.toString(),
},
],
},
},
},
wallet: fromPublicKey(userPk, type),
});

const origin = toBase58(encoded.buffer);

return {
description: 'Please sign the transaction',
type: 'fg:t:transaction',
data: origin,
};
},
wallet: fromPublicKey(userPk, type),
});

const origin = toBase58(encoded.buffer);

return {
description: 'Please sign the transaction',
type: 'fg:t:transaction',
data: origin,
};
},
};
},

onAuth: ({ userDid, userPk, claims, updateSession }) => {
Expand Down
Loading