Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/aviate-labs/principal.mo
Package that allows you to create a Principal from a Blob.
https://github.com/aviate-labs/principal.mo
Last synced: 3 months ago
JSON representation
Package that allows you to create a Principal from a Blob.
- Host: GitHub
- URL: https://github.com/aviate-labs/principal.mo
- Owner: aviate-labs
- License: apache-2.0
- Created: 2021-08-14T13:22:46.000Z (about 3 years ago)
- Default Branch: main
- Last Pushed: 2022-12-16T17:24:08.000Z (almost 2 years ago)
- Last Synced: 2024-04-19T01:33:31.266Z (7 months ago)
- Language: Motoko
- Homepage:
- Size: 42 KB
- Stars: 13
- Watchers: 1
- Forks: 2
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
- awesome-motoko - Principal - Provides a wrapper around the [base principal module](https://github.com/dfinity/motoko-base/blob/master/src/Principal.mo). (Libraries / Data structures)
README
# Principal
Provides a wrapper around the [base principal module](https://github.com/dfinity/motoko-base/blob/master/src/Principal.mo).
## Usage
You can add the package with [vessel](https://github.com/dfinity/vessel).
## Principals
### Functions
- `fromText`: creates a principal from its textual representation.
- `toText`: converts a principal to its textual representation.- `fromBlob` (**NEW**): creates a principal from its binary representation.
- `toBlob`: converts a principal to its binary representation.## Account Identifiers
It is recommended to use the `blob` subpackage if you do not need random access or mutation.
### Example
```motoko
let accountId = AccountIdentifier.fromPrincipal(p, null);
let aIdText = AccountIdentifier.toText(ab);
assert(Hex.equal(aIdText, "a7218db708c35689495871c3c6860504503ab2a545630809dd8609130331b0c2"));
```### `Text` vs. `[Nat8]` vs. `Blob`
1. `Text` is case-sensitive, if you choose to use it, make use to use `Hex.equal`.
2. `[Nat8]` has the same memory layout as other array, so is less compact as `Blob`.
3. `Blob` is the best choice if you do not need to access the underlying bytes.