Skip to content

NEP-641: Offchain Authorizations for Smart Contracts - #641

Merged
frol merged 16 commits into
masterfrom
nep-auth-resolve
Aug 12, 2026
Merged

NEP-641: Offchain Authorizations for Smart Contracts#641
frol merged 16 commits into
masterfrom
nep-auth-resolve

Conversation

@frol

@frol frol commented Jun 2, 2026

Copy link
Copy Markdown
Collaborator

Rendered NEP Markdown

It is open for discussion and we collaborate with DefuseLabs team on this.


For painting the picture of how this all fits together, you can go to https://trezu.app and use EVM wallets sign in flow (the implementation there is based on the older draft of the NEP, but I still find it helpful to paint the overall picture).

Sign in to Trezu requires "sign message" from the account owner, but EVM wallet is represented by a wallet contract on NEAR, so it cannot use NEAR's NEP-413 to sign message, as there are no access keys.

Trezu uses the signed message to issue JWT token to access the backend APIs (e.g. get the address book and history of confidential transactions).

@frol
frol requested a review from a team as a code owner June 2, 2026 07:39
Copilot AI review requested due to automatic review settings June 2, 2026 07:39
@github-project-automation github-project-automation Bot moved this to NEW in NEPs Jun 2, 2026
@github-project-automation github-project-automation Bot moved this to NEW❗ in DevRel Jun 2, 2026

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds a new standards-track NEP (NEP-641) specifying a w_auth_resolve view-function convention for on-chain verification of off-chain authorizations, including recursive resolution for composite wallets (e.g., multisigs) and a NEP-413 fallback for regular accounts.

Changes:

  • Introduces the NEP-641 specification for off-chain authorization resolution via w_auth_resolve.
  • Defines the wire types/JSON format, normative semantics (purpose/recipient binding, payload equality), and a caller-side recursive resolution algorithm.
  • Documents reference flows and security considerations for replay/downgrade/state-drift scenarios.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread neps/nep-0641.md Outdated
Comment thread neps/nep-0641.md Outdated
Comment thread neps/nep-0641.md Outdated
@frol
frol marked this pull request as draft June 2, 2026 08:31
Comment thread neps/nep-0641.md Outdated
Updated NEAR account ID format in protocol flows and diagrams to reflect the use of deterministic account IDs. Adjusted references to wallet contracts and authorization processes accordingly.
@frol

frol commented Jun 3, 2026

Copy link
Copy Markdown
Collaborator Author

The use-cases that this NEP would enable are:

  1. Sign in into a dApp with a proof of account ownership - e.g. Trezu allows to view the private address book (stored on Trezu backend) - PROVE_OWNERSHIP purpose
  2. Approve confidential swap intents with passkey/metamask/... - sign off-chain message and submit it to the confidential API - APPROVE_OFFCHAIN_ACTION purpose

frol added 2 commits June 3, 2026 21:59
There is no need to require using base64. Sometimes stringified JSON is enough.
Comment thread neps/nep-0641.md Outdated
@frol

frol commented Jun 5, 2026

Copy link
Copy Markdown
Collaborator Author

This NEP is already implemented in the v0 of wallet contract for EIP-712 (Ethereum signMessage): near/intents#256 and on the client side it is integrated into NEAR Connect: azbang/near-connect#96, and it is live on https://trezu.org

@frol

frol commented Jun 17, 2026

Copy link
Copy Markdown
Collaborator Author

One more consideration that I want to bring up - will w_resolve_auth be compatible with NEAR MPC? I need to model it before concluding this NEP.

…tivation for the NEP, explicitly mentioning MPC usecase
@frol
frol marked this pull request as ready for review July 24, 2026 12:26
@frol

frol commented Jul 24, 2026

Copy link
Copy Markdown
Collaborator Author

This NEP is already implemented for Wallet Contracts and they are live in production on Trezu:

Thus, this NEP is now ready for review.

@frol
frol requested a balanced review from Copilot August 10, 2026 16:33

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 1 out of 1 changed files in this pull request and generated no new comments.

Suppressed comments (3)

neps/nep-0641.md:116

  • The stale-state guarantee conflicts with the recommendation to backdate timestamps by about 60 seconds. A signature created now can still be resolved against a block from the preceding minute, so a key or member revoked during that window may remain valid. Either use the actual signing time and wait for a sufficiently recent block, or explicitly weaken the guarantee to “not before the declared timestamp” and document the exposure window.
Contracts reject messages whose `timestamp` is later than the current block timestamp. A freshly-signed authorization therefore cannot be resolved against chain state from *before* signing — where a revoked key, disabled extension, or removed member was still active — whether by a malicious caller pinning an old block or by a lagging RPC. Contracts MAY add a TTL. Clients set the timestamp ~60s early to absorb clock skew and block-time lag.

</details>

neps/nep-0641.md:384

  • The sentence is truncated; “replay protecti” should be “replay protection.”
### Caller-side resolution algorithm

neps/nep-0641.md:309

  • The cited near/intents reference implementation does not use this tagged representation: AccessKeySchema only has serde(rename_all = "snake_case"), so it serializes as {"nep413":{"callback_url":...}}, not the documented {"schema":"nep413","extra":...}. These formats are not interoperable; align the implementation or the normative wire format before presenting it as the reference.
    /// NEP-413 signing schema.
    Nep413 {

@mitinarseny mitinarseny left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Awesome! This NEP formalizes a unified and generic way for smart-contracts to resolve off-chain authorizations, paving a way for truly off-chain interactions, where keeping governance on-chain.

Comment thread neps/nep-0641.md Outdated
Comment thread neps/nep-0641.md Outdated
Comment thread neps/nep-0641.md
Comment thread neps/nep-0641.md Outdated
Comment thread neps/nep-0641.md Outdated
Comment thread neps/nep-0641.md Outdated
Comment thread neps/nep-0641.md Outdated
Comment thread neps/nep-0641.md Outdated
Comment thread neps/nep-0641.md Outdated
Comment thread neps/nep-0641.md Outdated
frol and others added 3 commits August 12, 2026 11:13
Co-authored-by: Arseny Mitin <mitinarseny@gmail.com>
Updated language for clarity and consistency regarding NEAR Protocol key types and payload structures.
I really appreciated all the inputs from Arseny and it helped to solidify and make the standard even more versatile. Also, he authored the final reference implementation for NEP-641 for Wallet Contracts
@frol
frol requested review from mitinarseny and a balanced review from Copilot August 12, 2026 09:54
@frol frol moved this from NEW❗ to In Progress 🏗️ in DevRel Aug 12, 2026
@frol frol moved this from NEW to DRAFT in NEPs Aug 12, 2026
Comment thread neps/nep-0641.md Outdated
Co-authored-by: Arseny Mitin <mitinarseny@gmail.com>
@frol

frol commented Aug 12, 2026

Copy link
Copy Markdown
Collaborator Author

As a Contract Standards working group member, I have a conflict of interest here, so I requested @mitinarseny to be the SME reviewer, and @graphite and @birchmd to act as working group approvers.

@graphite graphite left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for the great NEP! between @frol's original work and @mitinarseny's review I literally have nothing to add here.

@birchmd birchmd left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I approve this NEP. Thanks for the great work @frol and @mitinarseny !

Defining an interface for off-chain services to authenticate users via their existing on-chain account abstractions makes it easier to develop such flows. And I like the design choices that are made in this proposal (e.g. opaque blobs, but with specific instances for common cases such as signatures).

The only downside from my perspective is that users will simply need to trust the off-chain service is implementing the standard correctly because there will not be any on-chain record of the authorization. But that is the nature of off-chain services, not really a flaw in the proposal itself.

@frol frol changed the title NEP-641: Off-chain Authorization Resolution for Wallet Contracts NEP-641: Offchain Authorizations for Smart Contracts Aug 12, 2026
@frol
frol merged commit e5be32d into master Aug 12, 2026
3 checks passed
@frol
frol deleted the nep-auth-resolve branch August 12, 2026 18:51
@github-project-automation github-project-automation Bot moved this from In Progress 🏗️ to Shipped 🚀 in DevRel Aug 12, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Shipped 🚀
Status: DRAFT

Development

Successfully merging this pull request may close these issues.

6 participants