Skip to content

Commit

Permalink
Expose signMessage lib (#94)
Browse files Browse the repository at this point in the history
  • Loading branch information
bh2smith authored Oct 28, 2024
1 parent 354d21d commit 2aa2143
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 8 deletions.
2 changes: 2 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ export * from "./types";
export * from "./util";
export * from "./constants";
export * from "./decode";
export * from "./lib/safe-message";

export {
Network,
Expand All @@ -13,4 +14,5 @@ export {
signatureFromOutcome,
signatureFromTxHash,
requestRouter as mpcRequestRouter,
EthTransactionParams,
} from "near-ca";
16 changes: 8 additions & 8 deletions src/near-safe.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import {
EncodedSignRequest,
EthTransactionParams,
} from "near-ca";
import { Address, Hash, Hex, serializeSignature } from "viem";
import { Address, Hash, Hex, serializeSignature, zeroAddress } from "viem";

import { DEFAULT_SAFE_SALT_NONCE } from "./constants";
import { Erc4337Bundler } from "./lib/bundler";
Expand Down Expand Up @@ -479,15 +479,15 @@ export class NearSafe {
}

encodeForSafe(from: string): boolean {
const fromLower = from.toLowerCase();
if (
![this.address, this.mpcAddress]
.map((t) => t.toLowerCase())
.includes(fromLower)
) {
const lowerFrom = from.toLowerCase();
const lowerZero = zeroAddress.toLowerCase();
const lowerSafe = this.address.toLowerCase();
const lowerMpc = this.mpcAddress.toLowerCase();
// We allow zeroAddress (and and treat is as from = safe)
if (![lowerSafe, lowerMpc, lowerZero].includes(lowerFrom)) {
throw new Error(`Unexpected from address ${from}`);
}
return this.address.toLowerCase() === fromLower;
return [this.address.toLowerCase(), lowerZero].includes(lowerFrom);
}

async policyForChainId(chainId: number): Promise<SponsorshipPolicyData[]> {
Expand Down

0 comments on commit 2aa2143

Please sign in to comment.