Skip to content

Commit

Permalink
Sig validation
Browse files Browse the repository at this point in the history
  • Loading branch information
bkolad committed Dec 6, 2023
1 parent efacba9 commit 7d57aaf
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 7 deletions.
2 changes: 1 addition & 1 deletion packages/snap/snap.manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"url": "https://github.com/Sovereign-Labs/sov-snap.git"
},
"source": {
"shasum": "0XMgGQk6lFYBBnHKXeBInIQ///I2Od1v0cSZzKa+G8Y=",
"shasum": "Qaqeb9YSd8IkSIeQJ7fHDg6lWWCUhsOSgDTGv+AfZR8=",
"location": {
"npm": {
"filePath": "dist/bundle.js",
Expand Down
15 changes: 12 additions & 3 deletions packages/snap/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,7 @@ import { add0x, assert, bytesToHex, remove0x } from '@metamask/utils';
import { sign } from '@noble/ed25519';
import { validate as superstructValidate } from 'superstruct';

import type { SignTransactionParams } from './types';
import { GetBip32PublicKeyParamsStruct } from './types';
import { GetBip32PublicKeyParamsStruct, SignTransactionStruct } from './types';
import { SovWasm } from './wasm';

const wasm = new SovWasm();
Expand All @@ -35,6 +34,7 @@ export const onRpcRequest: OnRpcRequestHandler = async ({
request.params,
GetBip32PublicKeyParamsStruct,
);

if (validationErr !== undefined) {
throw rpcErrors.invalidParams(validationErr.toString());
}
Expand Down Expand Up @@ -69,7 +69,16 @@ export const onRpcRequest: OnRpcRequestHandler = async ({
}

case 'signTransaction': {
const { transaction, path } = request.params as SignTransactionParams;
const [validationErr, params] = superstructValidate(
request.params,
SignTransactionStruct,
);

if (validationErr !== undefined) {
throw rpcErrors.invalidParams(validationErr.toString());
}

const { transaction, path } = params;

try {
const call = wasm.serializeCall(transaction.message, transaction.nonce);
Expand Down
3 changes: 0 additions & 3 deletions packages/snap/src/types.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { Bip32PathStruct } from '@metamask/snaps-utils';
import type { Infer } from 'superstruct';
import {
boolean,
object,
Expand Down Expand Up @@ -53,8 +52,6 @@ export const SignTransactionStruct = object({
path: array(string()),
});

export type SignTransactionParams = Infer<typeof SignTransactionStruct>;

/**
* The expected WASM interface from the imported module.
*/
Expand Down

0 comments on commit 7d57aaf

Please sign in to comment.