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

[Ethereum plugin] SignMessage type: Bytes #1373

Merged
merged 3 commits into from
Nov 2, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
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
16 changes: 16 additions & 0 deletions packages/js/plugins/ethereum/src/__tests__/e2e.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1049,6 +1049,22 @@ describe("Ethereum Plugin", () => {
);
});

it("signMessageBytes", async () => {
const encoder = new TextEncoder();
const response = await client.invoke<string>({
uri,
method: "signMessageBytes",
args: {
bytes: encoder.encode("Hello World")
}
});

if (!response.ok) fail(response.error);
expect(response.value).toBe(
"0xa4708243bf782c6769ed04d83e7192dbcf4fc131aa54fde9d889d8633ae39dab03d7babd2392982dff6bc20177f7d887e27e50848c851320ee89c6c63d18ca761c"
);
});

it("sendRPC", async () => {
const res = await client.invoke<string | undefined>({
uri,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ import {
Args_sendTransaction,
Args_sendTransactionAndWait,
Args_signMessage,
Args_signMessageBytes,
Args_requestAccounts,
} from "./wrap";
import { BigInt } from "@polywrap/wasm-as";
Expand Down Expand Up @@ -294,6 +295,15 @@ export function signMessage(
}).unwrap();
}

export function signMessageBytes(
args: Args_signMessageBytes
): string {
return Ethereum_Module.signMessageBytes({
bytes: args.bytes,
connection: args.connection
}).unwrap();
}

export function sendRPC(
args: Args_sendRPC
): string | null {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,11 @@ type Module {
connection: Ethereum_Connection
): String!

signMessageBytes(
bytes: Bytes!
connection: Ethereum_Connection
): String!

sendRPC(
method: String!
params: [String!]!
Expand Down
9 changes: 9 additions & 0 deletions packages/js/plugins/ethereum/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import {
Args_sendTransaction,
Args_sendTransactionAndWait,
Args_signMessage,
Args_signMessageBytes,
TxResponse,
BigInt,
StaticTxResult,
Expand Down Expand Up @@ -397,6 +398,14 @@ export class EthereumPlugin extends Module<EthereumPluginConfig> {
return await connection.getSigner().signMessage(args.message);
}

public async signMessageBytes(
args: Args_signMessageBytes,
_client: CoreClient
): Promise<string> {
const connection = await this._getConnection(args.connection);
return await connection.getSigner().signMessage(args.bytes);
}

public async sendRPC(
args: Args_sendRPC,
_client: CoreClient
Expand Down
5 changes: 5 additions & 0 deletions packages/js/plugins/ethereum/src/schema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,11 @@ type Module {
connection: Connection
): String!

signMessageBytes(
bytes: Bytes!
connection: Connection
): String!

sendRPC(
method: String!
params: [String!]!
Expand Down