Skip to content

Commit c3a9475

Browse files
committed
Include cashaddr prefix for ecash addresses
1 parent d20b52c commit c3a9475

File tree

5 files changed

+24
-7
lines changed

5 files changed

+24
-7
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
## Unreleased
44

5+
- changed: Added cashaddr prefixes to ecash.
56
- changed: Added ecash to bitcoincash forks.
67

78
## 3.8.0 (2025-05-19)

src/common/plugin/types.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,14 @@ export interface CoinInfo {
189189
*/
190190
coinType: number
191191

192+
/**
193+
* Whether the currency should include its cashaddr prefix in the formatted
194+
* addresses.
195+
*
196+
* Defaults to `false`.
197+
*/
198+
includeCashaddrPrefix?: boolean
199+
192200
/**
193201
* Optional sighash value to be passed to AltcoinJS as the sighashType field
194202
* on inputs. This is primarily used by currencies that leverage it as

src/common/utxobased/engine/UtxoWalletTools.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,8 @@ export function makeUtxoWalletTools(
190190
return scriptPubkeyToAddress({
191191
scriptPubkey: args.scriptPubkey,
192192
addressType,
193-
coin
193+
coin,
194+
includeCashaddrPrefix: pluginInfo.coinInfo.includeCashaddrPrefix
194195
})
195196
},
196197

src/common/utxobased/info/ecash.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,9 +65,10 @@ const engineInfo: EngineInfo = {
6565
},
6666
asBlockbookAddress: asCodec(
6767
raw => {
68-
return asString(raw).split(':')[1]
68+
const address = asString(raw)
69+
return address.startsWith('ecash:') ? address.split(':')[1] : address
6970
},
70-
address => `ecash:${address}`
71+
address => (address.startsWith('ecash:') ? address : `ecash:${address}`)
7172
)
7273
}
7374

@@ -76,6 +77,7 @@ export const coinInfo: CoinInfo = {
7677
segwit: false,
7778
sighash: Psbt.BCH_SIGHASH_ALL,
7879
coinType: 899,
80+
includeCashaddrPrefix: true,
7981

8082
prefixes: {
8183
messagePrefix: ['\x18Bitcoin Signed Message::\n'],

src/common/utxobased/keymanager/keymanager.ts

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,7 @@ export interface ScriptPubkeyToAddressArgs {
156156
addressType: AddressTypeEnum
157157
coin: string
158158
redeemScript?: string
159+
includeCashaddrPrefix?: boolean
159160
}
160161

161162
export interface ScriptPubkeyToAddressReturn {
@@ -612,7 +613,8 @@ export function scriptPubkeyToAddress(
612613
coin: args.coin
613614
}),
614615
CashaddrTypeEnum.pubkeyhash,
615-
standardPrefixes.cashaddr
616+
standardPrefixes.cashaddr,
617+
args.includeCashaddrPrefix
616618
)
617619
}
618620
if (legacyPrefixes.cashaddr != null) {
@@ -623,7 +625,8 @@ export function scriptPubkeyToAddress(
623625
coin: args.coin
624626
}),
625627
CashaddrTypeEnum.pubkeyhash,
626-
legacyPrefixes.cashaddr
628+
legacyPrefixes.cashaddr,
629+
args.includeCashaddrPrefix
627630
)
628631
}
629632
payment = payments.p2pkh
@@ -637,7 +640,8 @@ export function scriptPubkeyToAddress(
637640
coin: args.coin
638641
}),
639642
CashaddrTypeEnum.scripthash,
640-
standardPrefixes.cashaddr
643+
standardPrefixes.cashaddr,
644+
args.includeCashaddrPrefix
641645
)
642646
}
643647
if (legacyPrefixes.cashaddr != null) {
@@ -648,7 +652,8 @@ export function scriptPubkeyToAddress(
648652
coin: args.coin
649653
}),
650654
CashaddrTypeEnum.scripthash,
651-
legacyPrefixes.cashaddr
655+
legacyPrefixes.cashaddr,
656+
args.includeCashaddrPrefix
652657
)
653658
}
654659
payment = payments.p2sh

0 commit comments

Comments
 (0)