Skip to content

Commit

Permalink
feat: add support for f4 and 0x addresses
Browse files Browse the repository at this point in the history
  • Loading branch information
hugomrdias committed Jul 21, 2023
1 parent 8e42a61 commit c9be659
Show file tree
Hide file tree
Showing 5 changed files with 114 additions and 101 deletions.
4 changes: 2 additions & 2 deletions packages/snap/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,8 @@
"dependencies": {
"@metamask/key-tree": "^7.1.1",
"@metamask/snaps-ui": "^0.32.2",
"iso-base": "^1.0.0",
"iso-filecoin": "^1.0.0",
"iso-base": "^1.1.1",
"iso-filecoin": "^1.1.1",
"merge-options": "^3.0.4",
"zod": "^3.21.4"
},
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": "https://github.com/filecoin-project/filsnap.git"
},
"source": {
"shasum": "LRa+fTw4DGe6u9f0K7krG1CGRv+ZF3kkxcrmFqCHQa8=",
"shasum": "RriYw+JgEnFHF5rIVhWr2lNYVwxQ0GPaCsx5PA2aTck=",
"location": {
"npm": {
"filePath": "dist/snap.js",
Expand Down
9 changes: 6 additions & 3 deletions packages/snap/src/rpc/gas-for-message.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { Schemas } from 'iso-filecoin/message'
import { z } from 'zod'
import type { SnapContext, SnapResponse } from '../types'
import { serializeError } from '../utils'
import * as Address from 'iso-filecoin/address'

// Default max fee in attoFIL (0.1 FIL)
const DEFAULT_MAX_FEE = '100000000000000000'
Expand Down Expand Up @@ -49,7 +50,7 @@ export async function getGasForMessage(
ctx: SnapContext,
params: EstimateParams
): Promise<GasForMessageResponse> {
const { rpc, account: keypair } = ctx
const { rpc, account: keypair, config } = ctx
const _params = estimateParams.safeParse(params)
if (!_params.success) {
return serializeError(
Expand All @@ -59,17 +60,19 @@ export async function getGasForMessage(
}

const { message, maxFee } = _params.data

const msg = {
to: message.to,
to: Address.from(message.to, config.network).toString(),
from: keypair.address.toString(),
value: message.value,
}

const { error, result } = await rpc.gasEstimate(
msg,
maxFee == null ? DEFAULT_MAX_FEE : maxFee
)
if (error != null) {
return serializeError('RPC call to "GasEstimateMessageGas" failed', error)
return serializeError(`RPC call to "GasEstimateMessageGas" failed`, error)
}

return {
Expand Down
9 changes: 5 additions & 4 deletions packages/snap/src/rpc/sign-message.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
/* eslint-disable @typescript-eslint/restrict-template-expressions */
import { z } from 'zod'
import { copyable, divider, heading, panel, text } from '@metamask/snaps-ui'
import { base64pad } from 'iso-base/rfc4648'
import { Message, Schemas } from 'iso-filecoin/message'
import { Token } from 'iso-filecoin/token'
import * as Address from 'iso-filecoin/address'
import { signMessage as filSignMessage, sign } from 'iso-filecoin/wallet'
import { z } from 'zod'
import type { SignedMessage, SnapContext, SnapResponse } from '../types'
import { copyable, divider, heading, panel, text } from '@metamask/snaps-ui'
import { serializeError, snapDialog } from '../utils'
import { base64pad } from 'iso-base/rfc4648'

// Schemas
export const signMessageParams = Schemas.messagePartial.omit({
Expand Down Expand Up @@ -51,7 +52,7 @@ export async function signMessage(

// create Message
const message = await new Message({
to: _params.data.to,
to: Address.from(_params.data.to, ctx.config.network).toString(),
from: ctx.account.address.toString(),
value: _params.data.value,
nonce: _params.data.nonce,
Expand Down

0 comments on commit c9be659

Please sign in to comment.