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

Expose signMessage lib #94

Merged
merged 1 commit into from
Oct 28, 2024
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
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