Skip to content

Commit

Permalink
feature: add sign multiple transactions api
Browse files Browse the repository at this point in the history
  • Loading branch information
riverrun46 committed Sep 18, 2023
1 parent a04b133 commit 947e7d0
Show file tree
Hide file tree
Showing 7 changed files with 65 additions and 1 deletion.
2 changes: 1 addition & 1 deletion public/content.js

Large diffs are not rendered by default.

3 changes: 3 additions & 0 deletions src/content-script/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,9 @@ type SigningTransaction = {
export async function signTransaction(params: { transaction: SigningTransaction }) {
return await createAction('SignTransaction', 'authorize', params)
}
export async function signTransactions(params: { transactions: SigningTransaction[] }) {
return await createAction('SignTransactions', 'authorize', params)
}

type TransferTask = {
genesis?: string
Expand Down
3 changes: 3 additions & 0 deletions src/content-script/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import {
signMessage,
verifySignature,
signTransaction,
signTransactions,
} from './actions'

type Metalet = {
Expand All @@ -31,6 +32,7 @@ type Metalet = {
getBalance: any
merge: any
signTransaction: any
signTransactions: any
signMessage: any
verifySignature: any
getUtxos: any
Expand Down Expand Up @@ -77,6 +79,7 @@ const metalet: Metalet = {
transfer,
merge,
signTransaction,
signTransactions,
signMessage,
verifySignature,

Expand Down
10 changes: 10 additions & 0 deletions src/data/authorize-actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import * as SwitchNetwork from '../lib/actions/switch-network'
import * as EciesEncrypt from '../lib/actions/ecies-encrypt'
import * as EciesDecrypt from '../lib/actions/ecies-decrypt'
import * as SignTransaction from '../lib/actions/sign-transaction'
import * as SignTransactions from '../lib/actions/sign-transactions'
import * as SignMessage from '../lib/actions/sign-message'
import * as Merge from '../lib/actions/merge'

Expand Down Expand Up @@ -81,6 +82,15 @@ export default {
closeAfterProcess: true,
},

SignTransactions: {
name: 'Sign Transactions',
title: 'Sign Multiple Transactions',
description: ['Sign multiple transactions with my wallet as once'],
process: SignTransactions.process,
estimate: doNothing,
closeAfterProcess: true,
},

EciesEncrypt: {
name: 'ECIES Encrypt',
title: 'ECIES Encrypt',
Expand Down
17 changes: 17 additions & 0 deletions src/lib/actions/sign-transactions.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { getAddress, getCurrentAccount, privateKey } from '../account'
import connector from '../connector'
import { signTransaction } from '../crypto'

export async function process(params: any, host: string) {
const wif = await getCurrentAccount().then((account) => privateKey.value)

const signingTransactions = params.transactions

const signatures = signingTransactions.map((transaction: any) => {
const signature = signTransaction(wif, transaction)

return signature
})

return { signatures }
}
2 changes: 2 additions & 0 deletions src/pages/authorize/Index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import SwitchNetwork from './SwitchNetwork.vue'
import EciesEncrypt from './EciesEncrypt.vue'
import EciesDecrypt from './EciesDecrypt.vue'
import SignTransaction from './SignTransaction.vue'
import SignTransactions from './SignTransactions.vue'
import SignMessage from './SignMessage.vue'
import Merge from './Merge.vue'
import { getBrowserHost } from '@/lib/host'
Expand Down Expand Up @@ -178,6 +179,7 @@ const cancelAction = async () => {
<EciesEncrypt v-if="actionName === 'EciesEncrypt'" :params="params" />
<EciesDecrypt v-if="actionName === 'EciesDecrypt'" :params="params" />
<SignTransaction v-if="actionName === 'SignTransaction'" :params="params" />
<SignTransactions v-if="actionName === 'SignTransactions'" :params="params" />
<SignMessage v-if="actionName === 'SignMessage'" :params="params" />
</div>

Expand Down
29 changes: 29 additions & 0 deletions src/pages/authorize/SignTransactions.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<script lang="ts" setup>
import { CheckBadgeIcon } from '@heroicons/vue/24/solid'
import actions from '@/data/authorize-actions'
const action = actions.SignTransactions
const props = defineProps<{
params: {
transactions: any
}
}>()
</script>

<template>
<h3 class="text-base font-bold">{{ action.title }}</h3>

<ul class="mt-6 space-y-4">
<li v-for="access in action.description" class="flex items-start gap-x-2">
<CheckBadgeIcon class="h-6 w-6 text-primary-blue" />
<div class="text-sm text-gray-700">{{ access }}</div>
</li>
</ul>

<!-- transactions count -->
<div class="mt-6">
<div class="label">Transactions Count</div>
<div class="value text-sm">{{ params.transactions.length }}</div>
</div>
</template>

0 comments on commit 947e7d0

Please sign in to comment.