-
Notifications
You must be signed in to change notification settings - Fork 2
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
Showing
12 changed files
with
378 additions
and
53 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
on: | ||
push: | ||
paths: | ||
- 'src/**' | ||
jobs: | ||
src: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v2 | ||
- uses: aviate-labs/[email protected] | ||
with: | ||
dfx-version: 0.8.0 | ||
install-moc: true | ||
vessel-version: 0.6.2 | ||
- run: for i in src/*.mo ; do moc $(vessel sources) --check $i ; done |
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 @@ | ||
.vessel/ |
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,17 @@ | ||
let upstream = https://github.com/dfinity/vessel-package-set/releases/download/mo-0.6.7-20210818/package-set.dhall sha256:c4bd3b9ffaf6b48d21841545306d9f69b57e79ce3b1ac5e1f63b068ca4f89957 | ||
let Package = { name : Text, version : Text, repo : Text, dependencies : List Text } | ||
|
||
let additions = [ | ||
{ name = "sha" | ||
, repo = "https://github.com/aviate-labs/sha.mo" | ||
, version = "v0.1.1" | ||
, dependencies = ["base", "encoding"] | ||
}, | ||
{ name = "encoding" | ||
, repo = "https://github.com/aviate-labs/encoding.mo" | ||
, version = "v0.2.1" | ||
, dependencies = ["base"] | ||
} | ||
] : List Package | ||
|
||
in upstream # additions |
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,33 @@ | ||
import Array "mo:base/Array"; | ||
import Binary "mo:encoding/Binary"; | ||
import Blob "mo:base/Blob"; | ||
import Hex "mo:encoding/Hex"; | ||
import Principal "mo:base/Principal"; | ||
import SHA256 "mo:sha/SHA256"; | ||
|
||
import CRC32 "CRC32"; | ||
|
||
module { | ||
public type AccountIdentifier = Text; | ||
public type SubAccount = [Nat8]; | ||
|
||
private let prefix : [Nat8] = [10, 97, 99, 99, 111, 117, 110, 116, 45, 105, 100]; | ||
|
||
public func fromPrincipal(p : Principal, subAccount : ?SubAccount) : AccountIdentifier { | ||
fromBlob(Principal.toBlob(p), subAccount); | ||
}; | ||
|
||
public func fromBlob(data : Blob, subAccount : ?SubAccount) : AccountIdentifier { | ||
fromArray(Blob.toArray(data), subAccount); | ||
}; | ||
|
||
public func fromArray(data : [Nat8], subAccount : ?SubAccount) : AccountIdentifier { | ||
let account : [Nat8] = switch (subAccount) { | ||
case (null) { Array.freeze(Array.init<Nat8>(32, 0)); }; | ||
case (?sa) { sa; }; | ||
}; | ||
let hash = SHA256.sum224(Array.flatten<Nat8>([prefix, data, account])); | ||
let crc = CRC32.checksum(hash); | ||
Hex.encode(Array.append<Nat8>(Binary.BigEndian.fromNat32(crc), hash)); | ||
}; | ||
}; |
Large diffs are not rendered by default.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
import Debug "mo:base/Debug"; | ||
import Principal "mo:base/Principal"; | ||
|
||
import AccountIdentifier "../src/AccountIdentifier"; | ||
|
||
let p = Principal.fromText("g42pg-k3n7u-4sals-ufza4-34yrp-mmvkt-psecp-7do7x-snvq4-llwrj-2ae"); | ||
assert(AccountIdentifier.fromPrincipal(p, null) == "A7218DB708C35689495871C3C6860504503AB2A545630809DD8609130331B0C2"); |
File renamed without changes.
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,9 @@ | ||
import Blob "mo:base/Blob"; | ||
import Text "mo:base/Text"; | ||
|
||
import CRC32 "../src/CRC32"; | ||
|
||
import Debug "mo:base/Debug"; | ||
|
||
assert(CRC32.checksum([171,205,1]) == 591393286); | ||
assert(CRC32.checksum(Blob.toArray(Text.encodeUtf8("The quick brown fox jumps over the lazy dog"))) == 1095738169); |
File renamed without changes.
This file was deleted.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
{ | ||
dependencies = [ "base", "sha", "encoding" ], | ||
compiler = None Text | ||
} |