Skip to content

feat: NEP-641 reference impl - #335

Merged
mitinarseny merged 93 commits into
mainfrom
feat/nep641
Aug 7, 2026
Merged

feat: NEP-641 reference impl#335
mitinarseny merged 93 commits into
mainfrom
feat/nep641

Conversation

@mitinarseny

@mitinarseny mitinarseny commented Aug 5, 2026

Copy link
Copy Markdown
Collaborator

Summary by CodeRabbit

  • New Features
    • Added NEP-641 off-chain authorization with nested paths, access-key and contract resolution, and RPC support.
    • Added off-chain message signing and verification, including Ed25519, WebAuthn, and secp256k1 support.
    • Added wallet SDK support for signing off-chain payloads and wrapping them as extensions.
    • Added wallet operations for managing signature authentication and extensions.
  • Bug Fixes
    • Strengthened validation for timestamps, paths, signers, chains, permissions, and payloads.
  • API Updates
    • Split request and off-chain signature APIs and updated authorization resolution methods.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In @.cargo/audit.toml:
- Around line 5-8: Remove the global RUSTSEC-2026-0222 entry from the shared
audit configuration and scope the suppression to the test-only audit command or
configuration that covers near-sdk/unit-testing dev-dependency graphs. Preserve
the ignore only for those test audits, and document its test-only rationale
there.
🪄 Autofix

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: 4ec6cfe0-d942-4f8c-8d3a-f2c8c635b988

📥 Commits

Reviewing files that changed from the base of the PR and between be82feb and 30caa76.

⛔ Files ignored due to path filters (1)
  • Cargo.lock is excluded by !**/*.lock
📒 Files selected for processing (11)
  • .cargo/audit.toml
  • contracts/wallet/src/error.rs
  • contracts/wallet/src/nonces.rs
  • contracts/wallet/src/request/ops.rs
  • crates/signatures/nep641/Cargo.toml
  • crates/signatures/nep641/src/lib.rs
  • crates/signatures/nep641/src/message.rs
  • crates/signatures/nep641/src/resolver/error.rs
  • crates/wallet/sdk/Cargo.toml
  • crates/wallet/sdk/src/relayer/near_kit.rs
  • crates/wallet/sdk/tests/test.rs
🚧 Files skipped from review as they are similar to previous changes (8)
  • crates/signatures/nep641/src/resolver/error.rs
  • crates/wallet/sdk/tests/test.rs
  • crates/signatures/nep641/Cargo.toml
  • crates/wallet/sdk/Cargo.toml
  • crates/wallet/sdk/src/relayer/near_kit.rs
  • contracts/wallet/src/error.rs
  • crates/signatures/nep641/src/lib.rs
  • crates/signatures/nep641/src/message.rs

Comment thread .cargo/audit.toml
Comment on lines +5 to +8
ignore = [
# transitive wasmtime dependency is only currently used for `near-sdk/unit-testing` feature
"RUSTSEC-2026-0222", # TODO: remove
]

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🔒 Security & Privacy | 🟡 Minor | ⚡ Quick win

🧩 Analysis chain

🏁 Script executed:

#!/usr/bin/env bash
set -euo pipefail

echo "Dependency and audit references:"
fd -a -t f -e toml -e lock -e yml -e yaml -e sh . \
  | xargs -r rg -n -C 5 \
      'near-sdk|unit-testing|wasmtime|cargo audit|RUSTSEC-2026-0222'

echo
echo "Wasmtime versions in lockfiles:"
while IFS= read -r lockfile; do
  echo "== $lockfile =="
  rg -n -A3 -B1 '^name = "wasmtime"$' "$lockfile"
done < <(fd -a -t f -g 'Cargo.lock' .)

Repository: near/intents

Length of output: 50368


🏁 Script executed:

#!/usr/bin/env bash
set -euo pipefail

echo "Cargo.lock wasmtime package entries:"
python3 - <<'PY'
from pathlib import Path
p = Path('Cargo.lock')
text = p.read_text()
# Extract package blocks with name = "wasmtime" including metadata/dependencies if present.
start_indices = [i for i in range(len(text)) if text.startswith('[[package]]', i)]
blocks = []
for idx in start_indices:
    nxt = min(start_indices[start_indices.index(idx)+1:]) if idx != start_indices[-1] else len(text)
    blocks.append((idx,nxt))
for idx,nxt in blocks:
    block = text[idx:nxt].splitlines()
    name = None
    for line in block:
        if line.startswith('name = ') and '"' in line:
            name = line.split('"',2)[1]
            break
    if name == 'wasmtime':
        print('\n'.join(block[:80]))
PY

echo
echo "Dependencies on wasmtime in lockfile package blocks:"
python3 - <<'PY'
from pathlib import Path
import re
p = Path('Cargo.lock')
text = p.read_text()
blocks = re.findall(r'^{(?P<body>.*?)^}$', text, re.S | re.M)
for body in blocks:
    name = re.search(r'^name = "(.*?)"', body, re.M)
    deps = re.findall(r'^\s{1,4}"(wasmtime[^"]*)"', body, re.M)
    if name and (name.group(1) == 'wasmtime' or deps):
        print(name.group(1), deps[:10])
PY

echo
echo "Workspace/package references to unit-testing or wasmtime in dependency sections:"
python3 - <<'PY'
from pathlib import Path
files = list(Path('.').glob('**/Cargo.toml'))
for f in files:
    if any(part in {'.git','target'} for part in f.parts):
        continue
    s = f.read_text()
    if 'unit-testing' in s or 'wasmtime' in s:
        print(f)
        for sec in ['[dependencies]','[dev-dependencies]','[build-dependencies]']:
            if sec in s:
                i=s.index(sec); ss=s.find('\n[',i+1); end=len(s) if ss==-1 else ss
                print(s[i:end].splitlines()[:25])
PY

echo
echo "Audit configuration and CI audit references:"
rg -n -C 4 'audit|cargo-audit|RUSTSEC-2026-0222|features\s*=|\[.*\]' ./.cargo audit -g 'Cargo.toml' .github workflows .github/workflows 2>/dev/null || true

Repository: near/intents

Length of output: 16434


🌐 Web query:

RUSTSEC-2026-0222 wasmtime vulnerability fixed version

💡 Result:

The vulnerability RUSTSEC-2026-0222, which involves type index confusion between Wasmtime engines, was patched in the following versions [1][2]: - 24.0.12 - 36.0.13 - 46.0.2 - 47.0.3 Users are advised to update to these versions or higher to remediate the vulnerability [3].

Citations:


🏁 Script executed:

#!/usr/bin/env bash
set -euo pipefail

echo "Cargo.lock wasmtime resolution and reverse dependencies:"
python3 - <<'PY'
from pathlib import Path
import re
lock = Path('Cargo.lock').read_text()
blocks = re.findall(r'(?m)^\[\[package\]\].*?^(?=\[\[package\]\]|$)', lock, re.S)
pkgs = {}
for block in blocks:
    m = re.search(r'^name = "(.*?)"\n', block, re.M)
    if not m: continue
    name = m.group(1)
    version = re.search(r'^version = "(.*?)"\n', block, re.M)
    deps = re.findall(r'^\n{0,1} {4}"(.*?)"\n', block, re.M)
    pkgs[name] = {"version": version.group(1) if version else None, "dependencies": deps}
print("wasmtime =", pkgs.get("wasmtime", {}))
for name, info in pkgs.items():
    if info.get("version") == "wasmtime" or info.get("dependencies") and "wasmtime" in info["dependencies"]:
        print(name, "version=", pkgs[name]["version"], "depends on wasmtime")

print("\nLock references to unit-testing:")
for f in list(Path('.').glob('**/Cargo.toml')):
    text = f.read_text()
    if 'unit-testing' in text or 'wasmtime' in text:
        print(f)
        for sec in ('[dependencies]', '[dev-dependencies]', '[build-dependencies]'):
            if sec in text:
                print(text[sec:sec.text(text.find(sec)).text])
PY

Repository: near/intents

Length of output: 474


🏁 Script executed:

#!/usr/bin/env bash
set -euo pipefail

echo "Lockfile reverse dependencies on wasmtime:"
python3 - <<'PY'
from pathlib import Path
import re
lock = Path('Cargo.lock').read_text()
blocks = re.findall(r'(?ms)^\[\[package\]\].*?^(?=\[\[package\]\]|$)', lock)
pkgs = {}
for block in blocks:
    m = re.search(r'^name = "(.*?)"\n', block, re.M)
    if not m: continue
    version_match = re.search(r'^version = "(.*?)"\n', block, re.M)
    deps = re.findall(r'^\n{0,1} {4}"(.*?)"\n', block, re.M)
    pkgs[m.group(1)] = {"version": version_match.group(1) if version_match else None, "dependencies": deps}
print("wasmtime in lock:", pkgs.get("wasmtime"))
for name, info in pkgs.items():
    if info["dependencies"] and "wasmtime" in info["dependencies"]:
        print(name, "version=", info["version"], "depends on wasmtime")
PY

echo
echo "Manifest direct dependency references:"
python3 - <<'PY'
from pathlib import Path
for f in Path('.').glob('**/Cargo.toml'):
    if any(part in {'.git','target'} for part in f.parts):
        continue
    text = f.read_text()
    if 'unit-testing' in text or 'wasmtime' in text:
        print(f)
        for sec in ('[dependencies]', '[dev-dependencies]', '[build-dependencies]'):
            if sec in text:
                print(text[text.index(sec):])
PY

echo
echo "Audit configuration contents:"
cat -n .cargo/audit.toml 2>/dev/null || true

Repository: near/intents

Length of output: 33036


Security Misconfiguration (CWE-693)

Reachability: Internal

Scope this global advisory suppression to the test-only graph.

The shared .cargo/audit.toml suppresses RUSTSEC-2026-0222 for every cargo-audit invocation. The affected wasmtime 45.0.3 package is only reachable through manifests that enable near-sdk/unit-testing in dev-dependencies/target.'cfg(near)'.dev-dependencies, so document or move this ignore to the test-only audit command to avoid suppressing future non-test release dependency paths.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In @.cargo/audit.toml around lines 5 - 8, Remove the global RUSTSEC-2026-0222
entry from the shared audit configuration and scope the suppression to the
test-only audit command or configuration that covers near-sdk/unit-testing
dev-dependency graphs. Preserve the ignore only for those test audits, and
document its test-only rationale there.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 2

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@crates/signatures/nep641/src/message.rs`:
- Line 246: Run cargo fmt to normalize the formatting of the changed
documentation example near the timestamp in message.rs, then include the
formatter’s output in the commit without making unrelated changes.
- Around line 242-255: Update the example message around into_nep413_payload so
its expected nonce matches the complete path being hashed: either regenerate the
nonce for the two-hop path and keep its corresponding recipient, or change the
path to the one-hop form used by the existing expected hash and adjust the
recipient accordingly.
🪄 Autofix

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: e78418e7-1e4b-4df7-a45c-8b0102799766

📥 Commits

Reviewing files that changed from the base of the PR and between 30caa76 and dbfc5c6.

📒 Files selected for processing (3)
  • crates/signatures/nep641/Cargo.toml
  • crates/signatures/nep641/src/access_keys.rs
  • crates/signatures/nep641/src/message.rs
🚧 Files skipped from review as they are similar to previous changes (1)
  • crates/signatures/nep641/Cargo.toml

Comment thread crates/signatures/nep641/src/message.rs
Comment thread crates/signatures/nep641/src/message.rs
Comment thread contracts/wallet/src/error.rs
Comment thread crates/signatures/nep641/src/resolver/error.rs
Comment thread contracts/wallet/src/contract.rs Outdated
@mitinarseny
mitinarseny merged commit dbe0810 into main Aug 7, 2026
8 checks passed
@mitinarseny
mitinarseny deleted the feat/nep641 branch August 7, 2026 09:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants