diff --git a/src/core/home/sign-txn/SignTxn.tsx b/src/core/home/sign-txn/SignTxn.tsx index d33288c..2c3cb3f 100644 --- a/src/core/home/sign-txn/SignTxn.tsx +++ b/src/core/home/sign-txn/SignTxn.tsx @@ -1,7 +1,7 @@ import {useState} from "react"; import {Button, List, ListItem} from "@hipo/react-ui-toolkit"; import {PeraWalletConnect} from "@perawallet/connect"; -import {SignerTransaction} from "@perawallet/connect/dist/util/model/peraWalletModels"; +import {PeraWalletArbitraryData, SignerTransaction} from "@perawallet/connect/dist/util/model/peraWalletModels"; import algosdk from "algosdk"; import {mainnetScenarios, Scenario, scenarios} from "./util/signTxnUtils"; @@ -77,36 +77,62 @@ function SignTxn({ )} - +
+ + + +
); - async function signArbitraryData() { + async function signSingleArbitraryData() { + const unsignedData = [ + { + data: new Uint8Array(Buffer.from(`timestamp//${Date.now()}`)), + message: "Timestamp confirmation" + }]; + + await signArbitraryData(unsignedData); + } + + async function signMultipleArbitraryData() { + const unsignedData = [ + { + data: new Uint8Array(Buffer.from(`timestamp//${Date.now()}`)), + message: "Timestamp confirmation" + }, + { + data: new Uint8Array(Buffer.from(`agent//${navigator.userAgent}`)), + message: "User agent confirmation" + } + ]; + + await signArbitraryData(unsignedData); + } + + async function signArbitraryData(arbitraryData: PeraWalletArbitraryData[]) { try { - const unsignedData = [ - { - data: new Uint8Array(Buffer.from(`timestamp//${Date.now()}`)), - message: "Timestamp confirmation" - }, - { - data: new Uint8Array(Buffer.from(`agent//${navigator.userAgent}`)), - message: "User agent confirmation" - } - ]; const signedData: Uint8Array[] = await peraWallet.signData( - unsignedData, + arbitraryData, accountAddress ); - unsignedData.forEach((data, index) => { + arbitraryData.forEach((data, index) => { const isVerified = algosdk.verifyBytes(data.data, signedData[index], accountAddress) console.log({data, signedData: signedData[index], isVerified});