Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
2cb093d
style: format existing codes
nimdeveloper Feb 19, 2026
a002bfa
feat: add full list of mutating wallet and protocol methods
nimdeveloper Feb 20, 2026
97e83f1
feat: add PolicyViolationError class for handling policy rejection er…
nimdeveloper Feb 20, 2026
2bbc7f7
feat: add runPolicies function for sequential policy evaluation
nimdeveloper Feb 20, 2026
6e990bf
feat: implement policy registration and enforcement in WDK class
nimdeveloper Feb 20, 2026
f24d987
feat: add registerPolicies function for policy management in WdkManag…
nimdeveloper Feb 20, 2026
a31968e
feat: update typescript types
nimdeveloper Feb 20, 2026
8a915e0
style: remove comments
nimdeveloper Feb 21, 2026
58207ce
refactor: remove MUTATING_METHODS constant and dynamically gather met…
nimdeveloper Feb 21, 2026
234e400
refactor: remove MUTATING_METHODS constant types
nimdeveloper Feb 25, 2026
7680380
fix: update PolicyViolationError import and usage in tests
nimdeveloper Feb 25, 2026
a56b2f9
refactor: improve Policy typedef documentation for clarity
nimdeveloper Feb 25, 2026
6c9c870
refactor: migrate runPolicies function to WDK class and update Policy…
nimdeveloper Feb 25, 2026
d53dd7a
refactor: update _withPolicyGate method signature to use generic type…
nimdeveloper Feb 25, 2026
1f65796
refactor: standardize string quotes and improve Policy typedef docume…
nimdeveloper Feb 25, 2026
d2ae357
refactor: update PolicyTarget to use blockchain identifier and adjust…
nimdeveloper Feb 25, 2026
a282f94
refactor: update PolicyViolationError to use PolicyTarget type for ta…
nimdeveloper Feb 25, 2026
69d0778
refactor: add registerPolicies document entries and revert format cha…
nimdeveloper Feb 25, 2026
de6bc00
refactor: remove unused runPolicies function from policies type defin…
nimdeveloper Feb 25, 2026
57b9aad
refactor: clean up whitespace and update class names for consistency …
nimdeveloper Feb 25, 2026
25ea83e
refactor: simplify policy evaluation by using mock functions in regis…
nimdeveloper Feb 25, 2026
83869f4
refactor: update wallet methods and policies for transaction handling…
nimdeveloper Feb 25, 2026
e37662a
refactor: enhance policy evaluation and testing in WdkManager
nimdeveloper Feb 25, 2026
d328212
refactor: rename runPolicies to _runPolicies and introduce PolicyEval…
nimdeveloper Feb 25, 2026
3c3651c
refactor: update return type of registerPolicies method to WdkManager
nimdeveloper Feb 25, 2026
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
90 changes: 89 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ constructor(seed: string | Uint8Array)
- `registerWallet<W>(blockchain: string, wallet: W, config: WalletConfig): WDK`
- `registerProtocol<P>(blockchain: string, label: string, protocol: P, config: ProtocolConfig): WDK`
- `registerMiddleware(blockchain: string, middleware: MiddlewareFunction): WDK`
- `registerPolicies(policies: Array<Policy>): WDK`

#### Get Accounts
- `getAccount(blockchain: string, index?: number): Promise<IWalletAccountWithProtocols>`
Expand Down Expand Up @@ -136,6 +137,93 @@ wdk.registerMiddleware('ethereum', async (account) => {
})
```

### Register Policies

```typescript
wdk.registerPolicies([
{
name: 'max-transfer-1eth',
method: 'sendTransaction',
evaluate({ method, params }) {
if (method !== 'sendTransaction') return true
return BigInt(params.value ?? 0) <= 10n ** 18n
}
}
])
```

### Wallet-Specific Policy

```typescript
wdk.registerPolicies([
{
name: 'ethereum-only-bridge',
target: { blockchain: 'ethereum' },
method: 'bridge',
evaluate: () => false
}
])
```

### Protocol-Targeted Policy

```typescript
wdk.registerPolicies([
{
name: 'swap-max-fee',
target: {
protocol: { blockchain: 'ethereum', label: 'paraswap' }
},
method: 'swap',
evaluate: () => false
}
])
```

### Multiple Methods

```typescript
wdk.registerPolicies([
{
name: 'disable-critical-ops',
target: { blockchain: 'ethereum' },
method: ['bridge', 'stake', 'unstake'],
evaluate: () => false
}
])
```

### Recipient Whitelist

```typescript
const allowed = new Set(['0xabc...', '0xdef...'])

wdk.registerPolicies([
{
name: 'recipient-whitelist',
method: 'sendTransaction',
evaluate({ params }) {
if (!params?.to) return true
return allowed.has(params.to.toLowerCase())
}
}
])
```

### Async Policy

```typescript
wdk.registerPolicies([
{
name: 'business-hours',
async evaluate() {
const hour = new Date().getUTCHours()
return hour >= 8 && hour < 18
}
}
])
```

## License

This project is licensed under the Apache License 2.0 - see the [LICENSE](LICENSE) file for details.
Expand All @@ -150,4 +238,4 @@ For support, please open an issue on the GitHub repository.

## Learn More

For full docs, visit [docs.wallet.tether.io](https://docs.wallet.tether.io)
For full docs, visit [docs.wallet.tether.io](https://docs.wallet.tether.io)
Comment thread
nimdeveloper marked this conversation as resolved.
1 change: 1 addition & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,4 @@
/** @typedef {import('./src/wallet-account-with-protocols.js').IWalletAccountWithProtocols} IWalletAccountWithProtocols */

export { default } from './src/wdk-manager.js'
export { PolicyViolationError } from './src/errors'
31 changes: 31 additions & 0 deletions src/errors/PolicyViolationError.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/** @typedef {import('../wdk-manager.js').PolicyTarget} PolicyTarget */

/**
* Error thrown when a registered policy rejects an operation.
*/
export class PolicyViolationError extends Error {
/**
* @param {string} policyName
* @param {string} method
* @param {PolicyTarget} target
*/
constructor (policyName, method, target = {}) {
const targetDesc = target.wallet
? `wallet: ${target.wallet}`
: target.protocol
? `protocol: ${JSON.stringify(target.protocol)}`
: 'global'

super(
`Policy "${policyName}" rejected method "${method}" for ${targetDesc}`
)

this.name = 'PolicyViolationError'
/** @type {string} */
this.policy = policyName
/** @type {string} */
this.method = method
/** @type {Object} */
this.target = target
}
}
1 change: 1 addition & 0 deletions src/errors/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { PolicyViolationError } from './PolicyViolationError.js'
Loading