@burnt-labs/account-management 0.0.1 → 1.0.0-alpha.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (80) hide show
  1. package/.eslintrc.js +7 -0
  2. package/.turbo/turbo-build.log +21 -0
  3. package/CHANGELOG.md +13 -0
  4. package/README.md +137 -0
  5. package/dist/index.d.ts +1308 -0
  6. package/dist/index.js +2252 -0
  7. package/dist/index.js.map +1 -0
  8. package/dist/index.mjs +2186 -0
  9. package/dist/index.mjs.map +1 -0
  10. package/package.json +47 -13
  11. package/src/accounts/__tests__/discovery.test.ts +533 -0
  12. package/src/accounts/discovery.ts +77 -0
  13. package/src/accounts/index.ts +23 -0
  14. package/src/accounts/strategies/__tests__/account-composite-strategy.test.ts +245 -0
  15. package/src/accounts/strategies/__tests__/account-empty-strategy.test.ts +90 -0
  16. package/src/accounts/strategies/__tests__/account-numia-strategy.test.ts +309 -0
  17. package/src/accounts/strategies/__tests__/account-rpc-strategy.test.ts +296 -0
  18. package/src/accounts/strategies/__tests__/account-subquery-strategy.test.ts +124 -0
  19. package/src/accounts/strategies/__tests__/factory.test.ts +183 -0
  20. package/src/accounts/strategies/account-composite-strategy.ts +72 -0
  21. package/src/accounts/strategies/account-empty-strategy.ts +32 -0
  22. package/src/accounts/strategies/account-numia-strategy.ts +96 -0
  23. package/src/accounts/strategies/account-rpc-strategy.ts +212 -0
  24. package/src/accounts/strategies/account-subquery-strategy.ts +117 -0
  25. package/src/accounts/strategies/factory.ts +85 -0
  26. package/src/accounts/strategies/indexerConfigUtils.ts +75 -0
  27. package/src/authenticators/__tests__/utils.test.ts +281 -0
  28. package/src/authenticators/index.ts +6 -0
  29. package/src/authenticators/interfaces.ts +113 -0
  30. package/src/authenticators/jwt.ts +13 -0
  31. package/src/authenticators/utils.ts +86 -0
  32. package/src/grants/__tests__/construction.test.ts +1554 -0
  33. package/src/grants/__tests__/discovery.test.ts +384 -0
  34. package/src/grants/construction.ts +401 -0
  35. package/src/grants/discovery.ts +104 -0
  36. package/src/grants/index.ts +22 -0
  37. package/src/grants/strategies/__tests__/createCompositeTreasuryStrategy.test.ts +165 -0
  38. package/src/grants/strategies/__tests__/treasury-composite-strategy.test.ts +240 -0
  39. package/src/grants/strategies/__tests__/treasury-daodao-strategy.test.ts +226 -0
  40. package/src/grants/strategies/__tests__/treasury-direct-query-strategy.test.ts +281 -0
  41. package/src/grants/strategies/createCompositeTreasuryStrategy.ts +63 -0
  42. package/src/grants/strategies/index.ts +15 -0
  43. package/src/grants/strategies/treasury-composite-strategy.ts +72 -0
  44. package/src/grants/strategies/treasury-daodao-strategy.ts +242 -0
  45. package/src/grants/strategies/treasury-direct-query-strategy.ts +120 -0
  46. package/src/grants/utils/__tests__/authz.test.ts +354 -0
  47. package/src/grants/utils/__tests__/contract-validation.test.ts +441 -0
  48. package/src/grants/utils/__tests__/feegrant.test.ts +932 -0
  49. package/src/grants/utils/__tests__/format-permissions.test.ts +999 -0
  50. package/src/grants/utils/authz.ts +147 -0
  51. package/src/grants/utils/contract-validation.ts +247 -0
  52. package/src/grants/utils/feegrant.ts +321 -0
  53. package/src/grants/utils/format-permissions.ts +318 -0
  54. package/src/grants/utils/index.ts +8 -0
  55. package/src/index.ts +33 -0
  56. package/src/orchestrator/__tests__/orchestrator.test.ts +422 -0
  57. package/src/orchestrator/flow/__tests__/README.md +82 -0
  58. package/src/orchestrator/flow/__tests__/accountConnection.test.ts +458 -0
  59. package/src/orchestrator/flow/__tests__/grantCreation.test.ts +595 -0
  60. package/src/orchestrator/flow/__tests__/redirectFlow.test.ts +229 -0
  61. package/src/orchestrator/flow/__tests__/sessionRestoration.test.ts +493 -0
  62. package/src/orchestrator/flow/accountConnection.ts +189 -0
  63. package/src/orchestrator/flow/grantCreation.ts +338 -0
  64. package/src/orchestrator/flow/redirectFlow.ts +77 -0
  65. package/src/orchestrator/flow/sessionRestoration.ts +102 -0
  66. package/src/orchestrator/index.ts +10 -0
  67. package/src/orchestrator/orchestrator.ts +263 -0
  68. package/src/orchestrator/types.ts +128 -0
  69. package/src/state/__tests__/accountState.test.ts +978 -0
  70. package/src/state/accountState.ts +204 -0
  71. package/src/types/authenticator.ts +42 -0
  72. package/src/types/grants.ts +74 -0
  73. package/src/types/index.ts +39 -0
  74. package/src/types/indexer.ts +37 -0
  75. package/src/types/treasury.ts +70 -0
  76. package/tsconfig.json +15 -0
  77. package/tsup.config.ts +11 -0
  78. package/vitest.config.integration.ts +28 -0
  79. package/vitest.config.ts +24 -0
  80. package/vitest.setup.ts +16 -0
package/.eslintrc.js ADDED
@@ -0,0 +1,7 @@
1
+ module.exports = {
2
+ extends: ["@burnt-labs/eslint-config-custom/library.js"],
3
+ parser: "@typescript-eslint/parser",
4
+ parserOptions: {
5
+ project: true,
6
+ },
7
+ };
@@ -0,0 +1,21 @@
1
+
2
+ > @burnt-labs/account-management@1.0.0-alpha.2 build /home/runner/work/xion.js/xion.js/packages/account-management
3
+ > tsup
4
+
5
+ CLI Building entry: src/index.ts
6
+ CLI Using tsconfig: tsconfig.json
7
+ CLI tsup v6.7.0
8
+ CLI Using tsup config: /home/runner/work/xion.js/xion.js/packages/account-management/tsup.config.ts
9
+ CLI Target: es2020
10
+ CLI Cleaning output folder
11
+ CJS Build start
12
+ ESM Build start
13
+ DTS Build start
14
+ CJS dist/index.js 72.93 KB
15
+ CJS dist/index.js.map 170.42 KB
16
+ CJS ⚡️ Build success in 645ms
17
+ ESM dist/index.mjs 70.74 KB
18
+ ESM dist/index.mjs.map 170.42 KB
19
+ ESM ⚡️ Build success in 646ms
20
+ DTS ⚡️ Build success in 2856ms
21
+ DTS dist/index.d.ts 47.79 KB
package/CHANGELOG.md ADDED
@@ -0,0 +1,13 @@
1
+ # @burnt-labs/account-management
2
+
3
+ ## 1.0.0-alpha.2
4
+
5
+ ### Minor Changes
6
+
7
+ - [#314](https://github.com/burnt-labs/xion.js/pull/314) [`f7359df`](https://github.com/burnt-labs/xion.js/commit/f7359dfdb0d3de55f51b7d8abcfa2e3c7baeb8e9) Thanks [@ertemann](https://github.com/ertemann)! - This release introduces **Signer Mode**, allowing users to connect with external wallets (MetaMask, Keplr, OKX, Turnkey, etc.) without requiring dashboard redirects. We've also refactored Abstraxion with a new connector-based architecture for better flexibility and extensibility. The release includes automatic configuration defaults (rpcUrl, restUrl, gasPrice are now inferred from chainId), migration to AA API V2, and two new packages: `@burnt-labs/account-management` and `@burnt-labs/signers`. Indexer support has been added for fast account discovery using Numia, Subquery, and DaoDao indexers. The Direct Signer Mode has been removed in favor of the new Signer Mode. Existing redirect mode users require no changes, while signer mode users need to add an `authentication` config with `type: "signer"`, `aaApiUrl`, `getSignerConfig()`, and `smartAccountContract` settings.
8
+
9
+ ### Patch Changes
10
+
11
+ - Updated dependencies [[`f7359df`](https://github.com/burnt-labs/xion.js/commit/f7359dfdb0d3de55f51b7d8abcfa2e3c7baeb8e9)]:
12
+ - @burnt-labs/abstraxion-core@1.0.0-alpha.62
13
+ - @burnt-labs/signers@1.0.0-alpha.2
package/README.md ADDED
@@ -0,0 +1,137 @@
1
+ # @burnt-labs/account-management
2
+
3
+ Smart account management utilities for XION blockchain.
4
+
5
+ ## Overview
6
+
7
+ This package provides comprehensive account and grant management for XION's smart accounts, supporting multiple discovery strategies and treasury integrations.
8
+
9
+ ## Features
10
+
11
+ - **Account Discovery**: Multiple strategies for finding smart accounts
12
+ - Numia indexer integration
13
+ - Subquery indexer integration
14
+ - Direct RPC queries
15
+ - Composite fallback chains
16
+
17
+ - **Treasury Management**: Flexible treasury configuration retrieval
18
+ - Direct contract queries
19
+ - DAO DAO indexer integration
20
+ - Composite strategy support
21
+
22
+ - **Connection Orchestration**: High-level API for managing account connections, grants, and redirects
23
+
24
+ ## Testing
25
+
26
+ ### Test Structure
27
+
28
+ The package uses a comprehensive unit testing approach with Vitest:
29
+
30
+ - **Unit Tests**: Located in `src/**/__tests__/` directories alongside source code
31
+ - **Integration Tests**: Located in `tests/integration/` (requires live RPC endpoints)
32
+
33
+ ### Running Tests
34
+
35
+ ```bash
36
+ # Run all tests in watch mode
37
+ pnpm test
38
+
39
+ # Run unit tests once
40
+ pnpm test:unit
41
+
42
+ # Run unit tests with coverage report
43
+ pnpm test:coverage
44
+
45
+ # Run integration tests (requires .env.test configuration)
46
+ pnpm test:integration
47
+
48
+ # Run integration tests in watch mode
49
+ pnpm test:integration:watch
50
+ ```
51
+
52
+ ### Coverage Requirements
53
+
54
+ The unit tests target 70%+ coverage for core modules:
55
+
56
+ - **Account Strategies**: 86.56% coverage
57
+ - EmptyAccountStrategy: 100%
58
+ - CompositeAccountStrategy: 100%
59
+ - NumiaAccountStrategy: 100%
60
+ - RpcAccountStrategy: 93.75%
61
+ - SubqueryAccountStrategy: 96.58%
62
+ - Factory: 100%
63
+
64
+ - **Treasury Strategies**: 93% coverage
65
+ - CompositeTreasuryStrategy: 100%
66
+ - DirectQueryTreasuryStrategy: 100%
67
+ - DaoDaoTreasuryStrategy: 91.32%
68
+ - createCompositeTreasuryStrategy: 100%
69
+
70
+ - **Orchestrator**: 66.17% coverage
71
+ - orchestrator.ts: 100%
72
+ - redirectFlow.ts: 100%
73
+
74
+ ### Test Organization
75
+
76
+ Tests are organized by module:
77
+
78
+ ```
79
+ src/
80
+ ├── accounts/
81
+ │ └── strategies/
82
+ │ └── __tests__/
83
+ │ ├── account-empty-strategy.test.ts
84
+ │ ├── account-composite-strategy.test.ts
85
+ │ ├── account-numia-strategy.test.ts
86
+ │ ├── account-rpc-strategy.test.ts
87
+ │ ├── account-subquery-strategy.test.ts
88
+ │ └── factory.test.ts
89
+ ├── grants/
90
+ │ └── strategies/
91
+ │ └── __tests__/
92
+ │ ├── treasury-composite-strategy.test.ts
93
+ │ ├── treasury-daodao-strategy.test.ts
94
+ │ ├── treasury-direct-query-strategy.test.ts
95
+ │ └── createCompositeTreasuryStrategy.test.ts
96
+ └── orchestrator/
97
+ ├── __tests__/
98
+ │ └── orchestrator.test.ts
99
+ └── flow/
100
+ └── __tests__/
101
+ └── redirectFlow.test.ts
102
+ ```
103
+
104
+ ### Integration Testing
105
+
106
+ Integration tests require a live XION RPC endpoint. Configure by creating [.env.test](.env.test):
107
+
108
+ ```env
109
+ XION_RPC_URL=https://rpc.xion-testnet-1.burnt.com:443
110
+ XION_CHAIN_ID=xion-testnet-1
111
+ ```
112
+
113
+ See [vitest.config.integration.ts](vitest.config.integration.ts) for integration test configuration.
114
+
115
+ ### Mocking Strategy
116
+
117
+ The tests use Vitest's mocking capabilities:
118
+
119
+ - **External APIs**: Mocked with `vi.fn()` and `global.fetch`
120
+ - **CosmJS**: Mocked CosmWasmClient for RPC interactions
121
+ - **WebAuthn**: Globally mocked in the signers package to avoid Node.js compatibility issues
122
+
123
+ ## Development
124
+
125
+ ```bash
126
+ # Build the package
127
+ pnpm build
128
+
129
+ # Run in development mode (watch)
130
+ pnpm dev
131
+
132
+ # Type checking
133
+ pnpm check-types
134
+
135
+ # Linting
136
+ pnpm lint
137
+ ```