Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(core): partial support for legacy base58 addresses
- Loading branch information
1 parent
1316d4b
commit 0f4cb28
Showing
3 changed files
with
19 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,20 @@ | ||
import * as util from '../util'; | ||
import * as typesUtil from '../util'; | ||
import { InvalidStringError } from '../..'; | ||
import { util as addressUtil } from '../../Address'; | ||
|
||
/** | ||
* mainnet or testnet address as bech32 string, consisting of | ||
* network tag, payment credential and optional stake credential | ||
*/ | ||
export type Address = util.OpaqueString<'Address'>; | ||
export type Address = typesUtil.OpaqueString<'Address'>; | ||
|
||
/** | ||
* @param {string} value mainnet or testnet address as bech32 string | ||
* @param {string} value mainnet or testnet address | ||
* @throws InvalidStringError | ||
*/ | ||
export const Address = (value: string): Address => util.typedBech32(value, ['addr', 'addr_test'], [47, 92]); | ||
export const Address = (value: string): Address => { | ||
if (addressUtil.isAddress(value)) { | ||
return value as unknown as Address; | ||
} | ||
throw new InvalidStringError(`Invalid address: ${value}`); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters