From 7a98194efba9b720947e7927478661d6c39d6127 Mon Sep 17 00:00:00 2001 From: danielailie Date: Mon, 3 Feb 2025 14:47:43 +0200 Subject: [PATCH 1/2] Add verifyMessage and verifyTransaction on account --- src/accounts/account.spec.ts | 38 ++++++++++++++++++++++ src/accounts/account.ts | 14 +++++++- src/accounts/interfaces.ts | 5 +++ src/core/message.spec.ts | 9 ++---- src/core/transaction.spec.ts | 25 +++----------- src/entrypoints/entrypoints.ts | 20 ++++-------- src/wallet/crypto/pubkeyDecryptor.ts | 23 ++++++------- src/wallet/crypto/pubkeyEncrypt.spec.ts | 43 +++++++++++++++++-------- src/wallet/userKeys.ts | 2 +- src/wallet/userVerifier.ts | 2 +- src/wallet/users.spec.ts | 17 +++++----- src/wallet/usersBenchmark.spec.ts | 4 +-- 12 files changed, 123 insertions(+), 79 deletions(-) diff --git a/src/accounts/account.spec.ts b/src/accounts/account.spec.ts index b216f5eaa..17459e667 100644 --- a/src/accounts/account.spec.ts +++ b/src/accounts/account.spec.ts @@ -91,4 +91,42 @@ describe("test account methods", function () { "561bc58f1dc6b10de208b2d2c22c9a474ea5e8cabb59c3d3ce06bbda21cc46454aa71a85d5a60442bd7784effa2e062fcb8fb421c521f898abf7f5ec165e5d0f", ); }); + + it("should verify message", async function () { + const message = new Message({ + data: new Uint8Array(Buffer.from("hello")), + }); + + const account = Account.newFromMnemonic(DUMMY_MNEMONIC); + message.signature = await account.signMessage(message); + const isVerified = await account.verifyMessage(message, message.signature); + + assert.isTrue(isVerified); + }); + + it("should sign and verify transaction", async function () { + const transaction = new Transaction({ + nonce: 89n, + value: 0n, + receiver: Address.newFromBech32("erd1spyavw0956vq68xj8y4tenjpq2wd5a9p2c6j8gsz7ztyrnpxrruqzu66jx"), + sender: Address.newFromBech32("erd1qyu5wthldzr8wx5c9ucg8kjagg0jfs53s8nr3zpz3hypefsdd8ssycr6th"), + gasPrice: 1000000000n, + gasLimit: 50000n, + data: new Uint8Array(), + chainID: "local-testnet", + version: 1, + options: 0, + }); + + const account = Account.newFromMnemonic(DUMMY_MNEMONIC); + transaction.signature = await account.signTransaction(transaction); + + assert.equal( + Buffer.from(transaction.signature).toString("hex"), + "b56769014f2bdc5cf9fc4a05356807d71fcf8775c819b0f1b0964625b679c918ffa64862313bfef86f99b38cb84fcdb16fa33ad6eb565276616723405cd8f109", + ); + + const isVerified = await account.verifyTransaction(transaction, transaction.signature); + assert.isTrue(isVerified); + }); }); diff --git a/src/accounts/account.ts b/src/accounts/account.ts index 2a8941534..8d2fc8b1d 100644 --- a/src/accounts/account.ts +++ b/src/accounts/account.ts @@ -96,7 +96,7 @@ export class Account implements IAccount { return this.secretKey.sign(data); } - verify(data: Uint8Array, signature: Uint8Array): boolean { + async verify(data: Uint8Array, signature: Uint8Array): Promise { return this.publicKey.verify(data, signature); } @@ -106,12 +106,24 @@ export class Account implements IAccount { return this.secretKey.sign(serializedTransaction); } + async verifyTransaction(transaction: Transaction, signature: Uint8Array): Promise { + const transactionComputer = new TransactionComputer(); + const serializedTransaction = transactionComputer.computeBytesForVerifying(transaction); + return this.publicKey.verify(serializedTransaction, signature); + } + async signMessage(message: Message): Promise { const messageComputer = new MessageComputer(); const serializedMessage = messageComputer.computeBytesForSigning(message); return this.secretKey.sign(serializedMessage); } + async verifyMessage(message: Message, signature: Uint8Array): Promise { + const messageComputer = new MessageComputer(); + const serializedMessage = messageComputer.computeBytesForVerifying(message); + return this.publicKey.verify(serializedMessage, signature); + } + getNonceThenIncrement(): bigint { let nonce = this.nonce; this.nonce = this.nonce + 1n; diff --git a/src/accounts/interfaces.ts b/src/accounts/interfaces.ts index f4bb10c53..5c7b3ba8c 100644 --- a/src/accounts/interfaces.ts +++ b/src/accounts/interfaces.ts @@ -1,7 +1,12 @@ +import { Message, Transaction } from "../core"; import { Address } from "../core/address"; export interface IAccount { readonly address: Address; sign(data: Uint8Array): Promise; + signTransaction(transaction: Transaction): Promise; + verifyTransaction(transaction: Transaction, signature: Uint8Array): Promise; + signMessage(message: Message): Promise; + verifyMessage(message: Message, signature: Uint8Array): Promise; } diff --git a/src/core/message.spec.ts b/src/core/message.spec.ts index 85642ac80..d6f71addf 100644 --- a/src/core/message.spec.ts +++ b/src/core/message.spec.ts @@ -1,7 +1,6 @@ import { assert } from "chai"; import { Account } from "../accounts"; import { getTestWalletsPath } from "../testutils/utils"; -import { UserVerifier } from "../wallet"; import { DEFAULT_MESSAGE_VERSION, SDK_JS_SIGNER, UNKNOWN_SIGNER } from "./constants"; import { Message, MessageComputer } from "./message"; @@ -60,12 +59,8 @@ describe("test message", () => { assert.deepEqual(unpackedMessage.version, message.version); assert.deepEqual(unpackedMessage.signer, message.signer); - const verifier = UserVerifier.fromAddress(alice.address); - const isValid = verifier.verify( - Buffer.from(messageComputer.computeBytesForVerifying(unpackedMessage)), - Buffer.from(unpackedMessage.signature!), - ); - assert.equal(isValid, true); + const isValid = await alice.verifyMessage(unpackedMessage, Buffer.from(unpackedMessage.signature!)); + assert.isTrue(isValid); }); it("should unpack legacy message", async () => { diff --git a/src/core/transaction.spec.ts b/src/core/transaction.spec.ts index 438498377..c607de45c 100644 --- a/src/core/transaction.spec.ts +++ b/src/core/transaction.spec.ts @@ -3,7 +3,6 @@ import { assert } from "chai"; import { Account } from "../accounts"; import { ProtoSerializer } from "../proto"; import { getTestWalletsPath } from "../testutils/utils"; -import { UserPublicKey, UserVerifier } from "../wallet"; import { Address } from "./address"; import { MIN_TRANSACTION_VERSION_THAT_SUPPORTS_OPTIONS, TRANSACTION_OPTIONS_DEFAULT } from "./constants"; import { INetworkConfig } from "./interface"; @@ -692,17 +691,9 @@ describe("test transaction", async () => { transaction.signature = await alice.signTransaction(transaction); - const userVerifier = new UserVerifier(new UserPublicKey(alice.address.getPublicKey())); - const isSignedByAlice = userVerifier.verify( - transactionComputer.computeBytesForVerifying(transaction), - transaction.signature, - ); + const isSignedByAlice = await alice.verifyTransaction(transaction, transaction.signature); - const wrongVerifier = new UserVerifier(new UserPublicKey(bob.address.getPublicKey())); - const isSignedByBob = wrongVerifier.verify( - transactionComputer.computeBytesForVerifying(transaction), - transaction.signature, - ); + const isSignedByBob = await bob.verifyTransaction(transaction, transaction.signature); assert.equal(isSignedByAlice, true); assert.equal(isSignedByBob, false); @@ -721,17 +712,9 @@ describe("test transaction", async () => { transaction.signature = await alice.sign(transactionComputer.computeHashForSigning(transaction)); - const userVerifier = new UserVerifier(alice.publicKey); - const isSignedByAlice = userVerifier.verify( - transactionComputer.computeBytesForVerifying(transaction), - transaction.signature, - ); + const isSignedByAlice = await alice.verifyTransaction(transaction, transaction.signature); - const wrongVerifier = new UserVerifier(new UserPublicKey(bob.address.getPublicKey())); - const isSignedByBob = wrongVerifier.verify( - transactionComputer.computeBytesForVerifying(transaction), - transaction.signature, - ); + const isSignedByBob = await bob.verifyTransaction(transaction, transaction.signature); assert.equal(isSignedByAlice, true); assert.equal(isSignedByBob, false); }); diff --git a/src/entrypoints/entrypoints.ts b/src/entrypoints/entrypoints.ts index 141546b1a..dee790bac 100644 --- a/src/entrypoints/entrypoints.ts +++ b/src/entrypoints/entrypoints.ts @@ -4,9 +4,8 @@ import { Account } from "../accounts"; import { IAccount } from "../accounts/interfaces"; import { Address } from "../core/address"; import { ErrInvalidNetworkProviderKind } from "../core/errors"; -import { Message, MessageComputer } from "../core/message"; +import { Message } from "../core/message"; import { Transaction } from "../core/transaction"; -import { TransactionComputer } from "../core/transactionComputer"; import { TransactionOnNetwork } from "../core/transactionOnNetwork"; import { TransactionsFactoryConfig } from "../core/transactionsFactoryConfig"; import { TransactionWatcher } from "../core/transactionWatcher"; @@ -20,7 +19,7 @@ import { SmartContractController } from "../smartContracts/smartContractControll import { TokenManagementController, TokenManagementTransactionsFactory } from "../tokenManagement"; import { TransferTransactionsFactory } from "../transfers"; import { TransfersController } from "../transfers/transfersControllers"; -import { UserSecretKey, UserVerifier } from "../wallet"; +import { UserSecretKey } from "../wallet"; import { DevnetEntrypointConfig, MainnetEntrypointConfig, TestnetEntrypointConfig } from "./config"; class NetworkEntrypoint { @@ -49,17 +48,14 @@ class NetworkEntrypoint { } async signTransaction(transaction: Transaction, account: IAccount): Promise { - const txComputer = new TransactionComputer(); - transaction.signature = await account.sign(txComputer.computeBytesForSigning(transaction)); + transaction.signature = await account.signTransaction(transaction); } - verifyTransactionSignature(transaction: Transaction): boolean { - const verifier = UserVerifier.fromAddress(transaction.sender); - const txComputer = new TransactionComputer(); - return verifier.verify(txComputer.computeBytesForVerifying(transaction), transaction.signature); + async verifyTransactionSignature(transaction: Transaction, account: IAccount): Promise { + return await account.verifyTransaction(transaction, transaction.signature); } - verifyMessageSignature(message: Message): boolean { + async verifyMessageSignature(message: Message, account: IAccount): Promise { if (!message.address) { throw new Error("`address` property of Message is not set"); } @@ -68,9 +64,7 @@ class NetworkEntrypoint { throw new Error("`signature` property of Message is not set"); } - const verifier = UserVerifier.fromAddress(message.address); - const messageComputer = new MessageComputer(); - return verifier.verify(messageComputer.computeBytesForVerifying(message), message.signature); + return await account.verifyMessage(message, message.signature); } async recallAccountNonce(address: Address): Promise { diff --git a/src/wallet/crypto/pubkeyDecryptor.ts b/src/wallet/crypto/pubkeyDecryptor.ts index e9b6d7a00..b70a58915 100644 --- a/src/wallet/crypto/pubkeyDecryptor.ts +++ b/src/wallet/crypto/pubkeyDecryptor.ts @@ -1,25 +1,26 @@ import crypto from "crypto"; -import nacl from "tweetnacl"; import ed2curve from "ed2curve"; -import { X25519EncryptedData } from "./x25519EncryptedData"; +import nacl from "tweetnacl"; import { UserPublicKey, UserSecretKey } from "../userKeys"; +import { X25519EncryptedData } from "./x25519EncryptedData"; export class PubkeyDecryptor { - static decrypt(data: X25519EncryptedData, decryptorSecretKey: UserSecretKey): Buffer { - const ciphertext = Buffer.from(data.ciphertext, 'hex'); - const edhPubKey = Buffer.from(data.identities.ephemeralPubKey, 'hex'); - const originatorPubKeyBuffer = Buffer.from(data.identities.originatorPubKey, 'hex'); + static async decrypt(data: X25519EncryptedData, decryptorSecretKey: UserSecretKey): Promise { + const ciphertext = Buffer.from(data.ciphertext, "hex"); + const edhPubKey = Buffer.from(data.identities.ephemeralPubKey, "hex"); + const originatorPubKeyBuffer = Buffer.from(data.identities.originatorPubKey, "hex"); const originatorPubKey = new UserPublicKey(originatorPubKeyBuffer); - const authMessage = crypto.createHash('sha256').update( - Buffer.concat([ciphertext, edhPubKey]) - ).digest(); + const authMessage = crypto + .createHash("sha256") + .update(Buffer.concat([ciphertext, edhPubKey])) + .digest(); - if (!originatorPubKey.verify(authMessage, Buffer.from(data.mac, 'hex'))) { + if (!(await originatorPubKey.verify(authMessage, Buffer.from(data.mac, "hex")))) { throw new Error("Invalid authentication for encrypted message originator"); } - const nonce = Buffer.from(data.nonce, 'hex'); + const nonce = Buffer.from(data.nonce, "hex"); const x25519Secret = ed2curve.convertSecretKey(decryptorSecretKey.valueOf()); const x25519EdhPubKey = ed2curve.convertPublicKey(edhPubKey); if (x25519EdhPubKey === null) { diff --git a/src/wallet/crypto/pubkeyEncrypt.spec.ts b/src/wallet/crypto/pubkeyEncrypt.spec.ts index 804a35f5b..f550cd2f2 100644 --- a/src/wallet/crypto/pubkeyEncrypt.spec.ts +++ b/src/wallet/crypto/pubkeyEncrypt.spec.ts @@ -22,24 +22,39 @@ describe("test address", () => { ); }); - it("encrypts/decrypts", () => { - const decryptedData = PubkeyDecryptor.decrypt(encryptedDataOfAliceForBob, new UserSecretKey(bob.secretKey)); + it("encrypts/decrypts", async function () { + const decryptedData = await PubkeyDecryptor.decrypt( + encryptedDataOfAliceForBob, + new UserSecretKey(bob.secretKey), + ); assert.equal(sensitiveData.toString("hex"), decryptedData.toString("hex")); }); - it("fails for different originator", () => { - encryptedDataOfAliceForBob.identities.originatorPubKey = carol.address.hex(); - assert.throws( - () => PubkeyDecryptor.decrypt(encryptedDataOfAliceForBob, new UserSecretKey(bob.secretKey)), - "Invalid authentication for encrypted message originator", - ); + it("fails for different originator", async function () { + encryptedDataOfAliceForBob.identities.originatorPubKey = carol.address.toHex(); + + try { + await PubkeyDecryptor.decrypt(encryptedDataOfAliceForBob, new UserSecretKey(bob.secretKey)); + assert.fail("Invalid authentication for encrypted message originator"); + } catch (error) { + assert( + error.message.includes("Invalid authentication for encrypted message originator"), + `Unexpected error message: ${error.message}`, + ); + } }); - it("fails for different DH public key", () => { - encryptedDataOfAliceForBob.identities.ephemeralPubKey = carol.address.hex(); - assert.throws( - () => PubkeyDecryptor.decrypt(encryptedDataOfAliceForBob, new UserSecretKey(bob.secretKey)), - "Invalid authentication for encrypted message originator", - ); + it("fails for different DH public key", async function () { + encryptedDataOfAliceForBob.identities.ephemeralPubKey = carol.address.toHex(); + + try { + await PubkeyDecryptor.decrypt(encryptedDataOfAliceForBob, new UserSecretKey(bob.secretKey)); + assert.fail("Expected an error but none was thrown"); + } catch (error) { + assert( + error.message.includes("Invalid authentication for encrypted message originator"), + `Unexpected error message: ${error.message}`, + ); + } }); }); diff --git a/src/wallet/userKeys.ts b/src/wallet/userKeys.ts index 801e58bfc..0a0259cec 100644 --- a/src/wallet/userKeys.ts +++ b/src/wallet/userKeys.ts @@ -68,7 +68,7 @@ export class UserPublicKey { this.buffer = Buffer.from(buffer); } - verify(data: Buffer | Uint8Array, signature: Buffer | Uint8Array): boolean { + async verify(data: Buffer | Uint8Array, signature: Buffer | Uint8Array): Promise { try { const ok = ed.sync.verify(new Uint8Array(signature), new Uint8Array(data), new Uint8Array(this.buffer)); return ok; diff --git a/src/wallet/userVerifier.ts b/src/wallet/userVerifier.ts index c13035ce3..00426ca47 100644 --- a/src/wallet/userVerifier.ts +++ b/src/wallet/userVerifier.ts @@ -22,7 +22,7 @@ export class UserVerifier { * @param signature the signature to be verified * @returns true if the signature is valid, false otherwise */ - verify(data: Buffer | Uint8Array, signature: Buffer | Uint8Array): boolean { + async verify(data: Buffer | Uint8Array, signature: Buffer | Uint8Array): Promise { return this.publicKey.verify(data, signature); } } diff --git a/src/wallet/users.spec.ts b/src/wallet/users.spec.ts index c4578b03d..b24138326 100644 --- a/src/wallet/users.spec.ts +++ b/src/wallet/users.spec.ts @@ -1,5 +1,6 @@ import { assert } from "chai"; import path from "path"; +import { Account } from "../accounts"; import { Address, ErrBadMnemonicEntropy, ErrInvariantFailed, Message, Transaction } from "../core"; import { DummyMnemonicOf12Words, @@ -290,7 +291,7 @@ describe("test user wallets", () => { }); it("should sign transactions", async () => { - let signer = new UserSigner( + let signer = new Account( UserSecretKey.fromString("1a927e2af5306a9bb2ea777f73e06ecc0ac9aaa72fb4ea3fecf659451394cccf"), ); let verifier = new UserVerifier( @@ -323,7 +324,7 @@ describe("test user wallets", () => { Buffer.from(signature).toString("hex"), "a5db62c6186612d44094f83576aa6a664299315fb6e42d0c17a40e9cd33efa9a9df8b76943aeac7dceaff3d78a16a7414c914f03f7a88e786c2cf939eb111c06", ); - assert.isTrue(verifier.verify(serialized, signature)); + assert.isTrue(await verifier.verify(serialized, signature)); // Without data field transaction = new Transaction({ @@ -393,7 +394,7 @@ describe("test user wallets", () => { Buffer.from(guardianSignature).toString("hex"), "5695fde5d9c77a94bb320438fbebe3bbd60b7cc4d633fb38e42bb65f83d253cbb82cc5ae40d701a7f0b839a5231320ca356018ced949885baae473e469ec770e", ); - assert.isTrue(verifier.verify(serialized, signature)); + assert.isTrue(await verifier.verify(serialized, signature)); // Without data field transaction = new Transaction({ @@ -425,7 +426,7 @@ describe("test user wallets", () => { Buffer.from(guardianSignature).toString("hex"), "ea3b83adcc468b0c7d3613fca5f429a9764d5710137c34c27e15d06e625326724ccfa758968507acadb14345d19389ba6004a4f0a6c527799c01713e10cf650b", ); - assert.isTrue(verifier.verify(serialized, signature)); + assert.isTrue(await verifier.verify(serialized, signature)); }); it("should sign transactions using PEM files", async () => { @@ -469,10 +470,10 @@ describe("test user wallets", () => { const signature = await signer.sign(message.data); assert.deepEqual(await signer.sign(message.data), await signer.sign(Uint8Array.from(message.data))); - assert.isTrue(verifier.verify(message.data, signature)); - assert.isTrue(verifier.verify(Uint8Array.from(message.data), Uint8Array.from(signature))); - assert.isFalse(verifier.verify(Buffer.from("hello"), signature)); - assert.isFalse(verifier.verify(new TextEncoder().encode("hello"), signature)); + assert.isTrue(await verifier.verify(message.data, signature)); + assert.isTrue(await verifier.verify(Uint8Array.from(message.data), Uint8Array.from(signature))); + assert.isFalse(await verifier.verify(Buffer.from("hello"), signature)); + assert.isFalse(await verifier.verify(new TextEncoder().encode("hello"), signature)); }); it("should create UserSigner from wallet", async function () { diff --git a/src/wallet/usersBenchmark.spec.ts b/src/wallet/usersBenchmark.spec.ts index 5eafc86f1..5d053ef90 100644 --- a/src/wallet/usersBenchmark.spec.ts +++ b/src/wallet/usersBenchmark.spec.ts @@ -36,7 +36,7 @@ describe("behchmark sign and verify", () => { console.time("verify (good)"); for (let i = 0; i < n; i++) { - const ok = publicKeys[i].verify(messages[i], goodSignatures[i]); + const ok = await publicKeys[i].verify(messages[i], goodSignatures[i]); assert.isTrue(ok); } @@ -45,7 +45,7 @@ describe("behchmark sign and verify", () => { console.time("verify (bad)"); for (let i = 0; i < n; i++) { - const ok = publicKeys[i].verify(messages[messages.length - i - 1], goodSignatures[i]); + const ok = await publicKeys[i].verify(messages[messages.length - i - 1], goodSignatures[i]); assert.isFalse(ok); } From 4f315d6e2dc1b43ec377f3237504620070494942 Mon Sep 17 00:00:00 2001 From: danielailie Date: Mon, 3 Feb 2025 15:44:59 +0200 Subject: [PATCH 2/2] Update methods to follow specs --- src/accounts/account.spec.ts | 4 ++-- src/accounts/account.ts | 4 ++-- src/accounts/interfaces.ts | 4 ++-- src/core/message.spec.ts | 2 +- src/core/transaction.spec.ts | 8 ++++---- src/entrypoints/entrypoints.ts | 4 ++-- 6 files changed, 13 insertions(+), 13 deletions(-) diff --git a/src/accounts/account.spec.ts b/src/accounts/account.spec.ts index 17459e667..cf4e1cfd2 100644 --- a/src/accounts/account.spec.ts +++ b/src/accounts/account.spec.ts @@ -99,7 +99,7 @@ describe("test account methods", function () { const account = Account.newFromMnemonic(DUMMY_MNEMONIC); message.signature = await account.signMessage(message); - const isVerified = await account.verifyMessage(message, message.signature); + const isVerified = await account.verifyMessageSignature(message, message.signature); assert.isTrue(isVerified); }); @@ -126,7 +126,7 @@ describe("test account methods", function () { "b56769014f2bdc5cf9fc4a05356807d71fcf8775c819b0f1b0964625b679c918ffa64862313bfef86f99b38cb84fcdb16fa33ad6eb565276616723405cd8f109", ); - const isVerified = await account.verifyTransaction(transaction, transaction.signature); + const isVerified = await account.verifyTransactionSignature(transaction, transaction.signature); assert.isTrue(isVerified); }); }); diff --git a/src/accounts/account.ts b/src/accounts/account.ts index 8d2fc8b1d..0c1716fa4 100644 --- a/src/accounts/account.ts +++ b/src/accounts/account.ts @@ -106,7 +106,7 @@ export class Account implements IAccount { return this.secretKey.sign(serializedTransaction); } - async verifyTransaction(transaction: Transaction, signature: Uint8Array): Promise { + async verifyTransactionSignature(transaction: Transaction, signature: Uint8Array): Promise { const transactionComputer = new TransactionComputer(); const serializedTransaction = transactionComputer.computeBytesForVerifying(transaction); return this.publicKey.verify(serializedTransaction, signature); @@ -118,7 +118,7 @@ export class Account implements IAccount { return this.secretKey.sign(serializedMessage); } - async verifyMessage(message: Message, signature: Uint8Array): Promise { + async verifyMessageSignature(message: Message, signature: Uint8Array): Promise { const messageComputer = new MessageComputer(); const serializedMessage = messageComputer.computeBytesForVerifying(message); return this.publicKey.verify(serializedMessage, signature); diff --git a/src/accounts/interfaces.ts b/src/accounts/interfaces.ts index 5c7b3ba8c..a10b9e943 100644 --- a/src/accounts/interfaces.ts +++ b/src/accounts/interfaces.ts @@ -6,7 +6,7 @@ export interface IAccount { sign(data: Uint8Array): Promise; signTransaction(transaction: Transaction): Promise; - verifyTransaction(transaction: Transaction, signature: Uint8Array): Promise; + verifyTransactionSignature(transaction: Transaction, signature: Uint8Array): Promise; signMessage(message: Message): Promise; - verifyMessage(message: Message, signature: Uint8Array): Promise; + verifyMessageSignature(message: Message, signature: Uint8Array): Promise; } diff --git a/src/core/message.spec.ts b/src/core/message.spec.ts index d6f71addf..8f81c3466 100644 --- a/src/core/message.spec.ts +++ b/src/core/message.spec.ts @@ -59,7 +59,7 @@ describe("test message", () => { assert.deepEqual(unpackedMessage.version, message.version); assert.deepEqual(unpackedMessage.signer, message.signer); - const isValid = await alice.verifyMessage(unpackedMessage, Buffer.from(unpackedMessage.signature!)); + const isValid = await alice.verifyMessageSignature(unpackedMessage, Buffer.from(unpackedMessage.signature!)); assert.isTrue(isValid); }); diff --git a/src/core/transaction.spec.ts b/src/core/transaction.spec.ts index c607de45c..d6d8ffcd2 100644 --- a/src/core/transaction.spec.ts +++ b/src/core/transaction.spec.ts @@ -691,9 +691,9 @@ describe("test transaction", async () => { transaction.signature = await alice.signTransaction(transaction); - const isSignedByAlice = await alice.verifyTransaction(transaction, transaction.signature); + const isSignedByAlice = await alice.verifyTransactionSignature(transaction, transaction.signature); - const isSignedByBob = await bob.verifyTransaction(transaction, transaction.signature); + const isSignedByBob = await bob.verifyTransactionSignature(transaction, transaction.signature); assert.equal(isSignedByAlice, true); assert.equal(isSignedByBob, false); @@ -712,9 +712,9 @@ describe("test transaction", async () => { transaction.signature = await alice.sign(transactionComputer.computeHashForSigning(transaction)); - const isSignedByAlice = await alice.verifyTransaction(transaction, transaction.signature); + const isSignedByAlice = await alice.verifyTransactionSignature(transaction, transaction.signature); - const isSignedByBob = await bob.verifyTransaction(transaction, transaction.signature); + const isSignedByBob = await bob.verifyTransactionSignature(transaction, transaction.signature); assert.equal(isSignedByAlice, true); assert.equal(isSignedByBob, false); }); diff --git a/src/entrypoints/entrypoints.ts b/src/entrypoints/entrypoints.ts index dee790bac..d15f3302e 100644 --- a/src/entrypoints/entrypoints.ts +++ b/src/entrypoints/entrypoints.ts @@ -52,7 +52,7 @@ class NetworkEntrypoint { } async verifyTransactionSignature(transaction: Transaction, account: IAccount): Promise { - return await account.verifyTransaction(transaction, transaction.signature); + return await account.verifyTransactionSignature(transaction, transaction.signature); } async verifyMessageSignature(message: Message, account: IAccount): Promise { @@ -64,7 +64,7 @@ class NetworkEntrypoint { throw new Error("`signature` property of Message is not set"); } - return await account.verifyMessage(message, message.signature); + return await account.verifyMessageSignature(message, message.signature); } async recallAccountNonce(address: Address): Promise {