Skip to content
This repository has been archived by the owner on Dec 3, 2024. It is now read-only.

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
Lykhoyda committed Aug 22, 2024
1 parent 16ff072 commit 7d5ea57
Show file tree
Hide file tree
Showing 5 changed files with 160 additions and 324 deletions.
2 changes: 1 addition & 1 deletion packages/adapter/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"compilerOptions": {
"target": "ES2022",
"target": "ES2020",
"outDir": "build",
"rootDir": "src",
"moduleResolution": "node",
Expand Down
6 changes: 3 additions & 3 deletions packages/snap/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -84,9 +84,9 @@
"@metamask/snaps-sdk": "^6.2.1",
"@metamask/snaps-types": "^3.1.0",
"@metamask/snaps-ui": "^3.1.0",
"@polkadot/api": "^12.3.1",
"@polkadot/keyring": "^12.3.2",
"@polkadot/types": "^12.3.1",
"@polkadot/api": "^12.4.2",
"@polkadot/keyring": "^12.4.2",
"@polkadot/types": "^12.4.2",
"@polkadot/util": "^13.0.2",
"deepmerge": "^4.3.1",
"superstruct": "^2.0.2"
Expand Down
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": "git+https://github.com/chainsafe/metamask-snap-polkadot.git"
},
"source": {
"shasum": "hDSowyITf6l5v4gjBGLKAa4W/h9Y7KwPrDCk//vSrXg=",
"shasum": "uGMwiB7E6cOddomt0QHnmCJ7ORu9RDGrlO/pEUl0dGQ=",
"location": {
"npm": {
"filePath": "dist/bundle.js",
Expand Down
41 changes: 30 additions & 11 deletions packages/snap/src/util/validation.ts
Original file line number Diff line number Diff line change
@@ -1,21 +1,40 @@
import type { BlockId, TxPayload } from '@chainsafe/metamask-polkadot-types';
import type { SignerPayloadJSON, SignerPayloadRaw } from '@polkadot/types/types';
import {
array,
boolean,
define,
enums,
number,
object,
optional,
string,
union
} from 'superstruct';
import type { Describe } from 'superstruct';
import { array, enums, number, object, optional, string, type, union } from 'superstruct';

const SignaturePayloadJSONSchema = type({
const HexStringStruct = define<`0x${string}`>('HexString', (value) => {
return typeof value === 'string' && /^0x[0-9a-fA-F]+$/.test(value)
? true
: 'Expected a valid hex string';
});

const SignaturePayloadJSONSchema = object({
address: string(),
blockHash: string(),
blockNumber: string(),
era: string(),
genesisHash: string(),
blockHash: HexStringStruct, // HexString
blockNumber: HexStringStruct, // HexString
era: HexStringStruct, // HexString
genesisHash: HexStringStruct, // HexString
metadataHash: optional(HexStringStruct), // Optional HexString
method: string(),
nonce: string(),
mode: optional(number()), // mode is optional and can be a number
nonce: HexStringStruct, // HexString
specVersion: HexStringStruct, // HexString
tip: HexStringStruct, // HexString
transactionVersion: HexStringStruct, // HexString
signedExtensions: array(string()),
specVersion: string(),
tip: string(),
transactionVersion: string(),
version: number()
version: number(),
withSignedTransaction: optional(boolean()) // Optional boolean
});

// eslint-disable-next-line @typescript-eslint/ban-ts-comment
Expand Down
Loading

0 comments on commit 7d5ea57

Please sign in to comment.