Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
79 commits
Select commit Hold shift + click to select a range
afb37b0
docs: typings for facade constructor
tuliomir Dec 12, 2025
30d3e57
docs: minor fix for example
tuliomir Dec 12, 2025
d52b832
fix: incompatibility between IUtxo and Utxo
tuliomir Dec 12, 2025
3f9c5bb
docs: types for core config and state
tuliomir Dec 12, 2025
3335fe4
docs: types for access and security methods
tuliomir Dec 12, 2025
0a545cb
docs: types for address management methods
tuliomir Dec 12, 2025
4f9c11b
docs: typing gap limit
tuliomir Dec 15, 2025
68b2625
docs: migration plan
tuliomir Dec 15, 2025
1bfa435
wip: groups 5 and 6 plus gettx fns
tuliomir Dec 15, 2025
66b4bb2
fix: interpreter conversions
tuliomir Dec 16, 2025
07eed87
docs: typings for utxo management
tuliomir Dec 16, 2025
784f105
docs: typings for tx signing
tuliomir Dec 16, 2025
5765a68
fix: Transaction input typings
tuliomir Dec 16, 2025
049ee35
wip: tx and token creation
tuliomir Dec 16, 2025
ce4c296
fix: OutputValueType uses
tuliomir Dec 16, 2025
7fcc5dc
docs: typings for authority management
tuliomir Dec 16, 2025
16de9ec
docs: typings for mint and melt
tuliomir Dec 16, 2025
6530e1a
docs: typings for auth delegation
tuliomir Dec 16, 2025
2195c7e
docs: typings for connection and sync
tuliomir Dec 16, 2025
11ed4d4
docs: typings for nanos
tuliomir Dec 16, 2025
f8f7f94
docs: instructions for interface docstrings
tuliomir Dec 16, 2025
0ccb8bf
docs: typings for tx templates
tuliomir Dec 16, 2025
aeec65c
docs: typings for deprecated methods
tuliomir Dec 16, 2025
c194978
docs: fix interface docstrings
tuliomir Dec 16, 2025
719df2a
docs: removes trivial `any` declarations
tuliomir Dec 17, 2025
0d2840f
docs: removes all `any` declarations
tuliomir Dec 17, 2025
cdd8c17
docs: typings for version
tuliomir Dec 17, 2025
03c06e8
fix: connection state getter
tuliomir Dec 17, 2025
bc7cddc
fix: WalletWebSocketData instances
tuliomir Dec 17, 2025
63a2519
fix: code assertions with ! operator
tuliomir Dec 17, 2025
825be3e
fix: ts-nocheck restored while in dev
tuliomir Dec 17, 2025
2b72ac3
fix: minor fixes
tuliomir Dec 17, 2025
3345380
fix: test with fixes
tuliomir Dec 17, 2025
d9e26f7
fix: transaction_acc_weight types
tuliomir Dec 17, 2025
3dfc414
fix: parameter types with null
tuliomir Dec 18, 2025
bf13cad
fix: nullability mismatches
tuliomir Dec 18, 2025
ca9154b
Merge branch 'master' into docs/typings-fullnode
tuliomir Dec 18, 2025
0790039
fix: null to string issues
tuliomir Dec 18, 2025
5e47fba
fix: mocked test connection object
tuliomir Dec 19, 2025
f66ab94
fix: argument mismatches 1
tuliomir Dec 19, 2025
3a3be41
fix: argument mismatches 1.1
tuliomir Dec 19, 2025
a0e1327
docs: list of remaining ts errors
tuliomir Dec 22, 2025
c5bcc4d
chore: minor code changes to fix types
tuliomir Dec 22, 2025
90b2c66
fix: connection types
tuliomir Dec 22, 2025
0fb5c0f
fix: more ts errors
tuliomir Dec 22, 2025
edd6ea5
fix: getTxById workarounds
tuliomir Dec 22, 2025
2a452be
fix: utxo response test
tuliomir Dec 22, 2025
8a135fc
fix: coverage reduction
tuliomir Dec 23, 2025
4f94755
fix: coverage reduction (statements)
tuliomir Dec 23, 2025
d2fd764
refactor: moves types to dedicated file
tuliomir Dec 26, 2025
e0862ec
Merge branch 'master' into docs/typings-fullnode
tuliomir Dec 28, 2025
1376e89
fix: merge fixes with master
tuliomir Dec 28, 2025
ae96171
docs: adds return types (1)
tuliomir Dec 29, 2025
ecc40f7
docs: adds return types (2)
tuliomir Dec 29, 2025
dbbee2b
fix: adaptations for new types
tuliomir Dec 29, 2025
09d0e80
docs: plan for creating shared tests
tuliomir Dec 26, 2025
1916e47
feat: draft for shared tests factory
tuliomir Dec 30, 2025
7845fe9
fix: debug fn on placeholder logger
tuliomir Dec 30, 2025
2a8d139
chore: typescript guards for empty txs
tuliomir Dec 30, 2025
883689c
chore: types, names and minor improvements
tuliomir Dec 31, 2025
d1322ab
refactor: moving files around
tuliomir Dec 31, 2025
52c1d3d
wip: first tests, genesis broken
tuliomir Dec 31, 2025
e448417
fix: genesis inject funds wallet service
tuliomir Dec 31, 2025
6c60793
fix: file references after refactoring
tuliomir Dec 31, 2025
4e15fb0
fix: melt tokens test on wallet service
tuliomir Jan 1, 2026
ecfdb6a
chore: removes unused "capabilities"
tuliomir Jan 1, 2026
920f326
fix: ocb awaits
tuliomir Jan 1, 2026
437463b
chore: trying to make mint tokens work
tuliomir Jan 1, 2026
693b895
chore: fixes to mint tokens
tuliomir Jan 2, 2026
32b39cd
chore: more fixes to mint tokens
tuliomir Jan 2, 2026
85e315f
fix: comments minting test code
tuliomir Jan 2, 2026
eee37a3
docs: comments on mint/melt
tuliomir Jan 2, 2026
d5688d1
docs: shared contract investigation start
tuliomir Jan 16, 2026
eca9191
docs: detailing differences between interfaces
tuliomir Jan 19, 2026
4ee2c31
Merge branch 'master' into docs/typings-fullnode
tuliomir Jan 20, 2026
219e460
fix: imports/types after merge
tuliomir Jan 20, 2026
87ac6d1
Merge branch 'docs/typings-fullnode' into test/shared-facades
tuliomir Jan 20, 2026
4d334e3
Merge master into test/shared-facades
tuliomir Feb 4, 2026
c750800
fix: post merge adjustment
tuliomir Feb 4, 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
388 changes: 388 additions & 0 deletions .claude/shared-contract-investigation.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,388 @@
# Shared Contract Investigation Report

## Executive Summary

This report analyzes the differences between `HathorWallet` (fullnode facade), `HathorWalletServiceWallet` (wallet service facade), and the `IHathorWallet` interface to identify contract misalignments that need resolution for unified testing.

**Key Findings:**
- 3 methods have inconsistent async/sync signatures (critical)
- 4 methods throw "Not implemented" in WalletServiceWallet
- ~20 methods exist only in HathorWallet
- Return types differ significantly for several shared methods
- The `IHathorWallet` interface has incomplete type annotations

---

## Part 1: Critical Contract Violations

### 1.1 Async/Sync Signature Mismatches

These methods have different async behaviors between facades:

| Method | HathorWallet | WalletServiceWallet | IHathorWallet | Impact |
|--------|-------------|---------------------|---------------|--------|
| `getCurrentAddress()` | `async` → `Promise<GetCurrentAddressFullnodeFacadeReturnType>` | `sync` → `AddressInfoObject` | `AddressInfoObject \| Promise<unknown>` (FIXME) | **CRITICAL** |
| `getNextAddress()` | `async` → `Promise<GetCurrentAddressFullnodeFacadeReturnType>` | `sync` → `AddressInfoObject` | `AddressInfoObject \| Promise<unknown>` (FIXME) | **CRITICAL** |
| `getFullHistory()` | `async` → `Promise<Record<string, IHistoryTx>>` | `sync` (throws "Not implemented") | `TransactionFullObject[] \| Promise<unknown>` (FIXME) | **CRITICAL** |
| `stop()` | `async` → `Promise<void>` | `async` → `Promise<void>` | `sync` → `void` | **MEDIUM** |

**Impact:** Tests cannot use a simple `await` pattern because the WalletServiceWallet returns sync values.

**Current Workaround (from shared tests):**
```typescript
// Wrapping with Promise.resolve() handles both cases
const address = await Promise.resolve(wallet.getCurrentAddress());
```

### 1.2 Return Type Mismatches

| Method | HathorWallet Return | WalletServiceWallet Return | Interface Declares |
|--------|--------------------|-----------------------------|-------------------|
| `getCurrentAddress()` | `{ address, index, addressPath }` | `{ address, index, addressPath, info? }` | Mixed |
| `getMintAuthority()` | `IUtxo[]` | `AuthorityTxOutput[]` | **NOT DEFINED** |
| `getMeltAuthority()` | `IUtxo[]` | `AuthorityTxOutput[]` | **NOT DEFINED** |
| `getAuthorityUtxo()` | `IUtxo[]` | `AuthorityTxOutput[]` | **NOT DEFINED** |
| `sendManyOutputsTransaction()` | `Transaction \| null` | `Transaction` | `Transaction` |
| `sendTransaction()` | `Transaction \| null` | `Transaction` | `Transaction` |
| `getFullHistory()` | `Record<string, IHistoryTx>` | N/A (throws) | `TransactionFullObject[]` |
| `getAddressPrivKey()` | `Promise<unknown>` | `Promise<bitcore.HDPrivateKey>` | `Promise<bitcore.PrivateKey>` |

#### 1.2.1 Detailed Type Property Comparison

**Address Return Types:**

| Property | `GetCurrentAddressFullnodeFacadeReturnType` (HathorWallet) | `AddressInfoObject` (WalletServiceWallet) |
|----------|-----------------------------------------------------------|-------------------------------------------|
| `address` | `string` | `string` |
| `index` | `number \| null` | `number` |
| `addressPath` | `string` | `string` |
| `info` | ❌ Not present | `string \| undefined` (optional) |

**Authority UTXO Return Types:**

| Property | `IUtxo` (HathorWallet) | `AuthorityTxOutput` (WalletServiceWallet) |
|----------|------------------------|-------------------------------------------|
| `txId` | ✅ `string` | ✅ `string` |
| `index` | ✅ `number` | ✅ `number` |
| `address` | ✅ `string` | ✅ `string` |
| `authorities` | ✅ `OutputValueType` | ✅ `OutputValueType` |
| `token` | ✅ `string` | ❌ Not present |
| `value` | ✅ `OutputValueType` | ❌ Not present |
| `timelock` | ✅ `number \| null` | ❌ Not present |
| `type` | ✅ `number` (tx version byte) | ❌ Not present |
| `height` | ✅ `number \| null` (block outputs) | ❌ Not present |

**History Return Types:**

| Property | `IHistoryTx` (HathorWallet) | `TransactionFullObject` (Interface declares) |
|----------|-----------------------------|--------------------------------------------|
| `tx_id` | ✅ `string` | ✅ `string` |
| `version` | ✅ `number` | ✅ `number` |
| `timestamp` | ✅ `number` | ✅ `number` |
| `is_voided` | ✅ `boolean` | ✅ `boolean` |
| `inputs` | ✅ `IHistoryInput[]` | ✅ `Input[]` |
| `outputs` | ✅ `IHistoryOutput[]` | ✅ `Output[]` |
| `parents` | ✅ `string[]` | ✅ `string[]` |
| `weight` | ✅ `number` | ❌ Not present |
| `signalBits` | ✅ `number` (optional) | ❌ Not present |
| `nonce` | ✅ `number` (optional) | ❌ Not present |
| `token_name` | ✅ `string` (optional, create token) | ❌ Not present |
| `token_symbol` | ✅ `string` (optional, create token) | ❌ Not present |
| `token_version` | ✅ `TokenVersion` (optional) | ❌ Not present |
| `tokens` | ✅ `string[]` (optional) | ❌ Not present |
| `height` | ✅ `number` (optional) | ❌ Not present |
| `processingStatus` | ✅ `TxHistoryProcessingStatus` (optional) | ❌ Not present |
| `nc_id` | ✅ `string` (optional, nano contract) | ❌ Not present |
| `nc_blueprint_id` | ✅ `string` (optional, nano contract) | ❌ Not present |
| `nc_method` | ✅ `string` (optional, nano contract) | ❌ Not present |
| `nc_args` | ✅ `string` (optional, nano contract) | ❌ Not present |

**Note:** HathorWallet's `getFullHistory()` returns `Record<string, IHistoryTx>` (keyed by tx_id), not an array. The interface declares `TransactionFullObject[]` which is neither format.

---

## Part 2: Methods Not Implemented

### 2.1 WalletServiceWallet "Not Implemented" Methods

These methods exist but throw `WalletError('Not implemented.')`:

| Method | Parameters | HathorWallet Has | Notes |
|--------|------------|------------------|-------|
| `getTx()` | `id: string` | ✅ Yes | Returns `IHistoryTx \| null` |
| `getAddressInfo()` | `address: string, options?: {}` | ✅ Yes | Returns address analytics |
| `consolidateUtxos()` | `destinationAddress: string, options?: {}` | ✅ Yes | UTXO consolidation |
| `getFullHistory()` | None | ✅ Yes | Full tx history |

### 2.2 Methods Missing from WalletServiceWallet

These methods exist in HathorWallet but not in WalletServiceWallet:

**Transaction Template Methods:**
- `buildTxTemplate()`
- `runTxTemplate()`

**On-Chain Blueprint Methods:**
- `createOnChainBlueprintTransaction()`
- `createAndSendOnChainBlueprintTransaction()`

**Nano Contract Token Methods:**
- `createNanoContractMintTokensTransaction()` (if exists)
- `createNanoContractMeltTokensTransaction()` (if exists)

**UTXO & Address Methods:**
- `getAvailableUtxos()` (generator)
- `prepareConsolidateUtxosData()`
- `consolidateUtxosSendTransaction()`
- `getAuthorityUtxos()`

**Multisig Methods:**
- `getAllSignatures()`
- `assemblePartialTransaction()`
- `getMultisigData()`

**Configuration Methods:**
- `setGapLimit()`
- `getGapLimit()`
- `indexLimitLoadMore()`
- `indexLimitSetEndIndex()`
- `setExternalTxSigningMethod()`
- `setHistorySyncMode()`

**Internal/Lifecycle Methods:**
- `syncHistory()`
- `reloadStorage()`
- `scanAddressesToLoad()`
- `processTxQueue()`
- `onEnterStateProcessing()`
- `handleWebsocketMsg()`
- `enqueueOnNewTx()`
- `onNewTx()`

---

## Part 3: Methods Missing from IHathorWallet Interface

The following methods exist in BOTH facades but are NOT in the interface:

| Method | HathorWallet | WalletServiceWallet | Should Add to Interface? |
|--------|-------------|---------------------|--------------------------|
| `getMintAuthority()` | ✅ | ✅ | **YES** |
| `getMeltAuthority()` | ✅ | ✅ | **YES** |
| `getAuthorityUtxo()` | ✅ | ✅ | **YES** |
| `markUtxoSelected()` | ✅ | ✅ (no-op) | Consider |
| `handleSendPreparedTransaction()` | ✅ | ✅ | Consider |
| `isReady()` | ✅ | ✅ | **YES** |
| `getTokenData()` | ✅ | ❌ | No |
| `clearSensitiveData()` | ✅ | ✅ | Consider |
| `isHardwareWallet()` | ✅ | ✅ | Consider |
| `setState()` | ✅ | ✅ | No (internal) |

---

## Part 4: Interface Type Issues

### 4.1 Missing Return Types in IHathorWallet

```typescript
// These methods lack proper return type annotations:
getNetworkObject(); // Return type missing
getPrivateKeyFromAddress(address: string, options: { pinCode?: string }); // Return type missing
```

### 4.2 Loose `any`/`options` Types

Many methods use untyped `options` parameter:
```typescript
prepareCreateNewToken(name: string, symbol: string, amount: OutputValueType, options): Promise<CreateTokenTransaction>;
createNewToken(name: string, symbol: string, amount: OutputValueType, options): Promise<Transaction>;
createNFT(name: string, symbol: string, amount: OutputValueType, data: string, options): Promise<Transaction>;
prepareMintTokensData(token: string, amount: OutputValueType, options): Promise<Transaction>;
mintTokens(token: string, amount: OutputValueType, options): Promise<Transaction>;
prepareMeltTokensData(token: string, amount: OutputValueType, options): Promise<Transaction>;
meltTokens(token: string, amount: OutputValueType, options): Promise<Transaction>;
getTxBalance(tx: IHistoryTx, optionsParams): Promise<{ [tokenId: string]: OutputValueType }>;
```

### 4.3 FIXME Comments in Interface

The interface has explicit FIXME comments acknowledging inconsistencies:
```typescript
getCurrentAddress(options?: { markAsUsed: boolean }): AddressInfoObject | Promise<unknown>; // FIXME: Should have a single return type
getNextAddress(): AddressInfoObject | Promise<unknown>; // FIXME: Should have a single return type;
getFullHistory(): TransactionFullObject[] | Promise<unknown>; // FIXME: Should have a single return type;
```

---

## Part 5: Options Parameter Differences

### 5.1 `sendTransaction()` Options

| Option | HathorWallet | WalletServiceWallet | Interface |
|--------|-------------|---------------------|-----------|
| `token` | ✅ | ✅ | ✅ |
| `changeAddress` | ✅ (`null` allowed) | ✅ | ✅ |
| `pinCode` | ✅ (`null` allowed) | ✅ | ❌ Missing |

### 5.2 `sendManyOutputsTransaction()` Options

| Option | HathorWallet | WalletServiceWallet | Interface |
|--------|-------------|---------------------|-----------|
| `inputs` | ✅ | ✅ | ✅ |
| `changeAddress` | ✅ (`null` allowed) | ✅ | ✅ |
| `pinCode` | ✅ (`null` allowed) | ✅ | ❌ Missing |
| `startMiningTx` | ✅ | ❌ | ❌ |

### 5.3 Token Creation Options

HathorWallet uses `CreateTokenOptions`:
- `address`, `changeAddress`, `startMiningTx`, `pinCode`
- `createMint`, `mintAuthorityAddress`, `allowExternalMintAuthorityAddress`
- `createMelt`, `meltAuthorityAddress`, `allowExternalMeltAuthorityAddress`
- `data`, `isCreateNFT`, `signTx`, `tokenVersion`

WalletServiceWallet uses inline options object with similar but not identical fields.

---

## Part 6: Authority Methods Deep Dive

Both facades have authority methods but with different return types:

### HathorWallet
```typescript
getMintAuthority(tokenUid: string, options?: GetAuthorityOptions): Promise<IUtxo[]>
getMeltAuthority(tokenUid: string, options?: GetAuthorityOptions): Promise<IUtxo[]>
getAuthorityUtxo(tokenUid: string, authority: 'mint' | 'melt', options?: GetAuthorityOptions): Promise<IUtxo[]>

// GetAuthorityOptions:
{
many?: boolean;
only_available_utxos?: boolean;
filter_address?: string;
}
```

### WalletServiceWallet
```typescript
getMintAuthority(tokenId: string, options?: { many?: boolean; skipSpent?: boolean }): Promise<AuthorityTxOutput[]>
getMeltAuthority(tokenId: string, options?: { many?: boolean; skipSpent?: boolean }): Promise<AuthorityTxOutput[]>
getAuthorityUtxo(tokenUid: string, authority: string, options?: {...}): Promise<AuthorityTxOutput[]>

// AuthorityTxOutput:
{
txId: string;
index: number;
address: string;
authorities: OutputValueType;
}
```

### IUtxo vs AuthorityTxOutput

| Field | IUtxo | AuthorityTxOutput |
|-------|-------|-------------------|
| txId | ✅ | ✅ |
| index | ✅ | ✅ |
| address | ✅ | ✅ |
| authorities | ✅ | ✅ |
| tokenId | ✅ | ❌ |
| value | ✅ | ❌ |
| timelock | ✅ | ❌ |
| heightlock | ✅ | ❌ |
| locked | ✅ | ❌ |
| addressPath | ✅ | ❌ |

---

## Part 7: Prioritized Recommendations

### Priority 1: Fix Critical Async/Sync Mismatches

1. **Make `getCurrentAddress()` async in both facades**
- WalletServiceWallet needs to return `Promise<AddressInfoObject>`
- Update interface to `Promise<AddressInfoObject>`

2. **Make `getNextAddress()` async in both facades**
- Same approach as above

3. **Update `stop()` in interface to be async**
- Change interface from `void` to `Promise<void>`
- Both facades already return Promise

### Priority 2: Unify Return Types

1. **Standardize authority method returns**
- Define a common `AuthorityUtxo` type
- Update both facades to return the same structure
- Add methods to interface

2. **Standardize `sendTransaction()` return type**
- Decide: `Transaction` or `Transaction | null`
- HathorWallet returns `null` on certain conditions

### Priority 3: Add Missing Interface Methods

```typescript
// Add to IHathorWallet:
getMintAuthority(tokenUid: string, options?: AuthorityOptions): Promise<AuthorityUtxo[]>;
getMeltAuthority(tokenUid: string, options?: AuthorityOptions): Promise<AuthorityUtxo[]>;
isReady(): boolean;
```

### Priority 4: Type the Options Parameters

Create explicit types for all options objects and use them in the interface.

### Priority 5: Implement Missing Methods in WalletServiceWallet

- `getTx()` - Consider implementing via API
- `getAddressInfo()` - Consider implementing via API
- `consolidateUtxos()` - May require backend support
- `getFullHistory()` - Consider implementing via API

---

## Part 8: Shared Test Compatibility Matrix

Based on the current state, here's what can be tested with the shared test factory:

| Test Category | Compatible | Notes |
|---------------|------------|-------|
| Lifecycle (`start`/`stop`/`isReady`) | ✅ | Need to handle async stop |
| Balance Operations | ✅ | Compatible |
| Address Operations | ⚠️ | Need Promise.resolve() wrapper |
| Simple Transactions | ✅ | Return type differs but compatible |
| Multi-output Transactions | ✅ | Return type differs but compatible |
| UTXO Operations | ✅ | Compatible |
| Token Creation | ✅ | Compatible |
| Token Details | ✅ | Compatible |
| Mint Tokens | ⚠️ | WalletService has sync issues |
| Melt Tokens | ⚠️ | WalletService has sync issues |
| Authority Operations | ⚠️ | Different return types |
| UTXO Consolidation | ❌ | Not implemented in WalletService |
| Full History | ❌ | Not implemented in WalletService |
| Address Info | ❌ | Not implemented in WalletService |
| Nano Contracts | ✅ | Both implement |

---

## Appendix A: Method Count Summary

| Category | HathorWallet | WalletServiceWallet | IHathorWallet |
|----------|-------------|---------------------|---------------|
| Total Methods | ~113 | ~75 | ~52 |
| Async Methods | ~97 | ~62 | ~45 |
| Sync Methods | ~16 | ~13 | ~4 |
| Not Implemented | 0 | 4 | N/A |

---

## Appendix B: Files Referenced

- `src/new/wallet.ts` - HathorWallet (Fullnode Facade) - ~3,372 lines
- `src/wallet/wallet.ts` - HathorWalletServiceWallet - ~3,002 lines
- `src/wallet/types.ts` - IHathorWallet interface and related types
- `src/new/types.ts` - HathorWallet-specific types
- `src/types.ts` - Shared types (IUtxo, OutputValueType, etc.)
Loading
Loading