$ npm install @projectsophon/serdeThis package contains serializers and deserializers for converting between various representations of Dark Forest data, for example between raw data received from blockchain calls to Dark Forest contracts and the typescript types used across the client.
You can install this package using npm or
yarn by running:
npm install --save @projectsophon/serde
yarn add @projectsophon/serde
When using this in a plugin, you might want to load it with skypack
import * as serde from 'http://cdn.skypack.dev/@projectsophon/serde'
▸ address(str): EthAddress
Converts a string to an EthAddress: a 0x-prefixed all lowercase hex string
of 40 hex characters. An object of the EthAddress type should only ever be
initialized through this constructor-like method. Throws if the provided
string cannot be parsed as an Ethereum address.
| Name | Type | Description |
|---|---|---|
str | string | An address-like string |
EthAddress
▸ hashToInt(hash): number
| Name | Type |
|---|---|
hash | string |
number
▸ isNetworkEvent(event): event is NetworkEvent
Returns whether or not the given event is an instance of NetworkEvent. Not super stringent but works for now.
| Name | Type |
|---|---|
event | any |
event is NetworkEvent
▸ isUnconfirmedActivateArtifact(txIntent): txIntent is UnconfirmedActivateArtifact
| Name | Type |
|---|---|
txIntent | TxIntent |
txIntent is UnconfirmedActivateArtifact
▸ isUnconfirmedActivateArtifactTx(tx): tx is Transaction<UnconfirmedActivateArtifact>
| Name | Type |
|---|---|
tx | Transaction<TxIntent> |
tx is Transaction<UnconfirmedActivateArtifact>
▸ isUnconfirmedBuyHat(txIntent): txIntent is UnconfirmedBuyHat
| Name | Type |
|---|---|
txIntent | TxIntent |
txIntent is UnconfirmedBuyHat
▸ isUnconfirmedBuyHatTx(tx): tx is Transaction<UnconfirmedBuyHat>
| Name | Type |
|---|---|
tx | Transaction<TxIntent> |
tx is Transaction<UnconfirmedBuyHat>
▸ isUnconfirmedCapturePlanet(txIntent): txIntent is UnconfirmedCapturePlanet
| Name | Type |
|---|---|
txIntent | TxIntent |
txIntent is UnconfirmedCapturePlanet
▸ isUnconfirmedCapturePlanetTx(tx): tx is Transaction<UnconfirmedCapturePlanet>
| Name | Type |
|---|---|
tx | Transaction<TxIntent> |
tx is Transaction<UnconfirmedCapturePlanet>
▸ isUnconfirmedDeactivateArtifact(txIntent): txIntent is UnconfirmedDeactivateArtifact
| Name | Type |
|---|---|
txIntent | TxIntent |
txIntent is UnconfirmedDeactivateArtifact
▸ isUnconfirmedDeactivateArtifactTx(tx): tx is Transaction<UnconfirmedDeactivateArtifact>
| Name | Type |
|---|---|
tx | Transaction<TxIntent> |
tx is Transaction<UnconfirmedDeactivateArtifact>
▸ isUnconfirmedDepositArtifact(txIntent): txIntent is UnconfirmedDepositArtifact
| Name | Type |
|---|---|
txIntent | TxIntent |
txIntent is UnconfirmedDepositArtifact
▸ isUnconfirmedDepositArtifactTx(tx): tx is Transaction<UnconfirmedDepositArtifact>
| Name | Type |
|---|---|
tx | Transaction<TxIntent> |
tx is Transaction<UnconfirmedDepositArtifact>
▸ isUnconfirmedFindArtifact(txIntent): txIntent is UnconfirmedFindArtifact
| Name | Type |
|---|---|
txIntent | TxIntent |
txIntent is UnconfirmedFindArtifact
▸ isUnconfirmedFindArtifactTx(tx): tx is Transaction<UnconfirmedFindArtifact>
| Name | Type |
|---|---|
tx | Transaction<TxIntent> |
tx is Transaction<UnconfirmedFindArtifact>
▸ isUnconfirmedGetShips(txIntent): txIntent is UnconfirmedGetShips
| Name | Type |
|---|---|
txIntent | TxIntent |
txIntent is UnconfirmedGetShips
▸ isUnconfirmedGetShipsTx(tx): tx is Transaction<UnconfirmedGetShips>
| Name | Type |
|---|---|
tx | Transaction<TxIntent> |
tx is Transaction<UnconfirmedGetShips>
▸ isUnconfirmedInit(txIntent): txIntent is UnconfirmedInit
| Name | Type |
|---|---|
txIntent | TxIntent |
txIntent is UnconfirmedInit
▸ isUnconfirmedInitTx(tx): tx is Transaction<UnconfirmedInit>
| Name | Type |
|---|---|
tx | Transaction<TxIntent> |
tx is Transaction<UnconfirmedInit>
▸ isUnconfirmedInvadePlanet(txIntent): txIntent is UnconfirmedInvadePlanet
| Name | Type |
|---|---|
txIntent | TxIntent |
txIntent is UnconfirmedInvadePlanet
▸ isUnconfirmedInvadePlanetTx(tx): tx is Transaction<UnconfirmedInvadePlanet>
| Name | Type |
|---|---|
tx | Transaction<TxIntent> |
tx is Transaction<UnconfirmedInvadePlanet>
▸ isUnconfirmedMove(txIntent): txIntent is UnconfirmedMove
| Name | Type |
|---|---|
txIntent | TxIntent |
txIntent is UnconfirmedMove
▸ isUnconfirmedMoveTx(tx): tx is Transaction<UnconfirmedMove>
| Name | Type |
|---|---|
tx | Transaction<TxIntent> |
tx is Transaction<UnconfirmedMove>
▸ isUnconfirmedProspectPlanet(txIntent): txIntent is UnconfirmedProspectPlanet
| Name | Type |
|---|---|
txIntent | TxIntent |
txIntent is UnconfirmedProspectPlanet
▸ isUnconfirmedProspectPlanetTx(tx): tx is Transaction<UnconfirmedProspectPlanet>
| Name | Type |
|---|---|
tx | Transaction<TxIntent> |
tx is Transaction<UnconfirmedProspectPlanet>
▸ isUnconfirmedRelease(txIntent): txIntent is UnconfirmedMove
| Name | Type |
|---|---|
txIntent | TxIntent |
txIntent is UnconfirmedMove
▸ isUnconfirmedReleaseTx(tx): tx is Transaction<UnconfirmedMove>
| Name | Type |
|---|---|
tx | Transaction<TxIntent> |
tx is Transaction<UnconfirmedMove>
▸ isUnconfirmedReveal(txIntent): txIntent is UnconfirmedReveal
| Name | Type |
|---|---|
txIntent | TxIntent |
txIntent is UnconfirmedReveal
▸ isUnconfirmedRevealTx(tx): tx is Transaction<UnconfirmedReveal>
| Name | Type |
|---|---|
tx | Transaction<TxIntent> |
tx is Transaction<UnconfirmedReveal>
▸ isUnconfirmedTransfer(txIntent): txIntent is UnconfirmedPlanetTransfer
| Name | Type |
|---|---|
txIntent | TxIntent |
txIntent is UnconfirmedPlanetTransfer
▸ isUnconfirmedTransferTx(tx): tx is Transaction<UnconfirmedPlanetTransfer>
| Name | Type |
|---|---|
tx | Transaction<TxIntent> |
tx is Transaction<UnconfirmedPlanetTransfer>
▸ isUnconfirmedUpgrade(txIntent): txIntent is UnconfirmedUpgrade
| Name | Type |
|---|---|
txIntent | TxIntent |
txIntent is UnconfirmedUpgrade
▸ isUnconfirmedUpgradeTx(tx): tx is Transaction<UnconfirmedUpgrade>
| Name | Type |
|---|---|
tx | Transaction<TxIntent> |
tx is Transaction<UnconfirmedUpgrade>
▸ isUnconfirmedWithdrawArtifact(txIntent): txIntent is UnconfirmedWithdrawArtifact
| Name | Type |
|---|---|
txIntent | TxIntent |
txIntent is UnconfirmedWithdrawArtifact
▸ isUnconfirmedWithdrawArtifactTx(tx): tx is Transaction<UnconfirmedWithdrawArtifact>
| Name | Type |
|---|---|
tx | Transaction<TxIntent> |
tx is Transaction<UnconfirmedWithdrawArtifact>
▸ isUnconfirmedWithdrawSilver(txIntent): txIntent is UnconfirmedWithdrawSilver
| Name | Type |
|---|---|
txIntent | TxIntent |
txIntent is UnconfirmedWithdrawSilver
▸ isUnconfirmedWithdrawSilverTx(tx): tx is Transaction<UnconfirmedWithdrawSilver>
| Name | Type |
|---|---|
tx | Transaction<TxIntent> |
tx is Transaction<UnconfirmedWithdrawSilver>
▸ locationIdFromBigInt(location): LocationId
Converts a BigInteger representation of location ID into a LocationID: a
non-0x-prefixed all lowercase hex string of exactly 64 hex characters
(0-padded). LocationIDs should only be instantiated through
locationIdFromHexStr, locationIdFromDecStr, locationIdFromBigInt, and
locationIdFromEthersBN.
| Name | Type | Description |
|---|---|---|
location | bigint | BigInteger representation of a location ID. |
LocationId
▸ locationIdFromDecStr(location): LocationId
Converts a string representing a decimal number into a LocationID: a
non-0x-prefixed all lowercase hex string of exactly 64 hex characters
(0-padded if necessary). LocationIDs should only be instantiated through
locationIdFromHexStr, locationIdFromDecStr, locationIdFromBigInt, and
locationIdFromEthersBN.
| Name | Type | Description |
|---|---|---|
location | string | string of decimal digits, the base 10 representation of a location ID. |
LocationId
▸ locationIdFromEthersBN(location): LocationId
Converts an ethers.js BigNumber (type aliased here as EthersBN)
representation of a location ID into a LocationID: a non-0x-prefixed all
lowercase hex string of exactly 64 hex characters (0-padded). LocationIDs
should only be instantiated through locationIdFromHexStr,
locationIdFromDecStr, locationIdFromBigInt, and locationIdFromEthersBN.
| Name | Type | Description |
|---|---|---|
location | BigNumber | ethers.js BigNumber representation of a locationID. |
LocationId
▸ locationIdFromHexStr(location): LocationId
Converts a possibly 0x-prefixed string of hex digits to a LocationId: a
non-0x-prefixed all lowercase hex string of exactly 64 hex characters
(0-padded if necessary). LocationIDs should only be instantiated through
locationIdFromHexStr, locationIdFromDecStr, locationIdFromBigInt, and
locationIdFromEthersBN.
| Name | Type | Description |
|---|---|---|
location | string | A possibly 0x-prefixed string of hex digits representing a location ID. |
LocationId
▸ locationIdToDecStr(locationId): string
Converts a LocationID to a decimal string with the same numerical value; can be used if you need to pass an artifact ID into a web3 call.
| Name | Type | Description |
|---|---|---|
locationId | LocationId | LocationID to convert into a string of decimal digits |
string