forked from toncenter/tonweb
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
tolya-yanot
committed
Dec 29, 2022
1 parent
a821484
commit 253cb5c
Showing
10 changed files
with
115 additions
and
14 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
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
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
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 |
---|---|---|
@@ -0,0 +1,50 @@ | ||
const {hexToBytes, bytesToHex} = require("./Utils"); | ||
|
||
class StorageBagId { | ||
/** | ||
* @param anyForm {string | Uint8Array | StorageBagId} | ||
*/ | ||
static isValid(anyForm) { | ||
try { | ||
new StorageBagId(anyForm); | ||
return true; | ||
} catch (e) { | ||
return false; | ||
} | ||
} | ||
|
||
/** | ||
* @param anyForm {string | Uint8Array | StorageBagId} | ||
*/ | ||
constructor(anyForm) { | ||
if (anyForm == null) { | ||
throw "Invalid address"; | ||
} | ||
|
||
if (anyForm instanceof StorageBagId) { | ||
this.bytes = anyForm.bytes; | ||
} else if (anyForm instanceof Uint8Array) { | ||
if (anyForm.length !== 32) { | ||
throw new Error('invalid bag id bytes length'); | ||
} | ||
this.bytes = anyForm; | ||
} else if (typeof anyForm === 'string') { | ||
if (anyForm.length !== 64) { | ||
throw new Error('invalid bag id hex length'); | ||
} | ||
this.bytes = hexToBytes(anyForm); | ||
} else { | ||
throw new Error('unsupported type') | ||
} | ||
} | ||
|
||
toHex() { | ||
let hex = bytesToHex(this.bytes); | ||
while (hex.length < 64) { | ||
hex = '0' + hex; | ||
} | ||
return hex; | ||
} | ||
} | ||
|
||
module.exports.default = StorageBagId; |
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