-
Notifications
You must be signed in to change notification settings - Fork 9
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
1 parent
79e682c
commit 0608937
Showing
5 changed files
with
423 additions
and
0 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,26 @@ | ||
# @generated by Move, please check-in and do not edit manually. | ||
|
||
[move] | ||
version = 2 | ||
manifest_digest = "0BAC026A0C518E4F4E63B8A7BB1FA36291E16B8919911B03E105CDD71EA40B5E" | ||
deps_digest = "F8BBB0CCB2491CA29A3DF03D6F92277A4F3574266507ACD77214D37ECA3F3082" | ||
dependencies = [ | ||
{ name = "Sui" }, | ||
] | ||
|
||
[[move.package]] | ||
name = "MoveStdlib" | ||
source = { git = "https://github.com/MystenLabs/sui.git", rev = "framework/testnet", subdir = "crates/sui-framework/packages/move-stdlib" } | ||
|
||
[[move.package]] | ||
name = "Sui" | ||
source = { git = "https://github.com/MystenLabs/sui.git", rev = "framework/testnet", subdir = "crates/sui-framework/packages/sui-framework" } | ||
|
||
dependencies = [ | ||
{ name = "MoveStdlib" }, | ||
] | ||
|
||
[move.toolchain-version] | ||
compiler-version = "1.30.3" | ||
edition = "2024.beta" | ||
flavor = "sui" |
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,37 @@ | ||
[package] | ||
name = "multisig" | ||
edition = "2024.beta" # edition = "legacy" to use legacy (pre-2024) Move | ||
# license = "" # e.g., "MIT", "GPL", "Apache 2.0" | ||
# authors = ["..."] # e.g., ["Joe Smith ([email protected])", "John Snow ([email protected])"] | ||
|
||
[dependencies] | ||
Sui = { git = "https://github.com/MystenLabs/sui.git", subdir = "crates/sui-framework/packages/sui-framework", rev = "framework/testnet" } | ||
|
||
# For remote import, use the `{ git = "...", subdir = "...", rev = "..." }`. | ||
# Revision can be a branch, a tag, and a commit hash. | ||
# MyRemotePackage = { git = "https://some.remote/host.git", subdir = "remote/path", rev = "main" } | ||
|
||
# For local dependencies use `local = path`. Path is relative to the package root | ||
# Local = { local = "../path/to" } | ||
|
||
# To resolve a version conflict and force a specific version for dependency | ||
# override use `override = true` | ||
# Override = { local = "../conflicting/version", override = true } | ||
|
||
[addresses] | ||
multisig = "0x0" | ||
|
||
# Named addresses will be accessible in Move as `@name`. They're also exported: | ||
# for example, `std = "0x1"` is exported by the Standard Library. | ||
# alice = "0xA11CE" | ||
|
||
[dev-dependencies] | ||
# The dev-dependencies section allows overriding dependencies for `--test` and | ||
# `--dev` modes. You can introduce test-only dependencies here. | ||
# Local = { local = "../path/to/dev-build" } | ||
|
||
[dev-addresses] | ||
# The dev-addresses section allows overwriting named addresses for the `--test` | ||
# and `--dev` modes. | ||
# alice = "0xB0B" | ||
|
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,134 @@ | ||
module multisig::base64 { | ||
use std::vector::{Self}; | ||
use std::string::{Self,String}; | ||
use sui::vec_map::{Self, VecMap}; | ||
|
||
const BASE64_CHARS: vector<u8> = b"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"; | ||
const PADDING_CHAR: vector<u8> = b"="; | ||
|
||
|
||
public fun encode(input:&vector<u8>):String { | ||
|
||
let mut output:vector<u8> = vector::empty(); | ||
let mut i=0; | ||
while (i <input.length()){ | ||
let b1:u8= *input.borrow(i); | ||
let b2:u8= if(i+1 < input.length()){ | ||
*input.borrow(i+1) | ||
}else { | ||
0 | ||
}; | ||
|
||
let b3:u8= if((i+2)<input.length()){ | ||
*input.borrow(i+2) | ||
}else { | ||
0 | ||
}; | ||
|
||
let triple=((b1 as u32) << 16) | ((b2 as u32) << 8) | (b3 as u32); | ||
output.push_back(*BASE64_CHARS.borrow(((triple >> 18) & 0x3F) as u64)); | ||
output.push_back(*BASE64_CHARS.borrow(((triple >> 12) & 0x3F) as u64)); | ||
|
||
if (i + 1 < input.length()) { | ||
output.push_back(*BASE64_CHARS.borrow(((triple >> 6) & 0x3F) as u64)); | ||
} else { | ||
output.push_back(*PADDING_CHAR.borrow(0)); | ||
}; | ||
|
||
if (i + 2 < input.length()) { | ||
output.push_back(*BASE64_CHARS.borrow((triple & 0x3F) as u64)); | ||
} else { | ||
output.push_back(*PADDING_CHAR.borrow(0)); | ||
}; | ||
|
||
i =i+ 3; | ||
}; | ||
string::utf8(output) | ||
} | ||
|
||
public fun decode(input:&String):vector<u8>{ | ||
let char_index=get_char_map(); | ||
let mut output = vector::empty<u8>(); | ||
let input_bytes = input.as_bytes(); | ||
let mut i = 0; | ||
while( i < input_bytes.length()){ | ||
let b1 = *char_index.get(input_bytes.borrow(i)); | ||
let b2 = *char_index.get(input_bytes.borrow(i + 1)); | ||
let b3 = if (i + 2 < input_bytes.length()) { | ||
let key=input_bytes.borrow(i+2); | ||
let val:u32 = if (char_index.contains(key)) { | ||
*char_index.get(key) | ||
} else { | ||
64 | ||
}; | ||
val | ||
} else { | ||
64 | ||
}; | ||
let b4 = if (i + 3 < input_bytes.length()) { | ||
let key=input_bytes.borrow(i+3); | ||
let val:u32= if (char_index.contains(key)) { | ||
*char_index.get(key) | ||
} else { | ||
64 | ||
}; | ||
val | ||
} else { | ||
|
||
64 | ||
}; | ||
|
||
let triple = (b1 << 18) | (b2 << 12) | (b3 << 6) | b4; | ||
|
||
output.push_back(((triple >> 16) & 0xFF) as u8); | ||
|
||
if (b3 != 64) { | ||
output.push_back(((triple >> 8) & 0xFF) as u8); | ||
}; | ||
if (b4 != 64) { | ||
output.push_back((triple & 0xFF) as u8); | ||
}; | ||
|
||
i = i+4; | ||
|
||
}; | ||
output | ||
|
||
} | ||
|
||
|
||
|
||
fun get_char_map():VecMap<u8,u32>{ | ||
let mut char_map = vec_map::empty<u8,u32>(); | ||
let mut i:u64=0; | ||
while( i < BASE64_CHARS.length()){ | ||
let c=*BASE64_CHARS.borrow(i); | ||
char_map.insert(c,(i as u32)); | ||
i=i+1; | ||
}; | ||
char_map | ||
} | ||
} | ||
|
||
|
||
#[test_only] | ||
module multisig::base64_tests { | ||
use sui::hash::{Self}; | ||
use multisig::base64::{Self}; | ||
#[test] | ||
fun test_base64(){ | ||
let input = b"Hello, World!"; | ||
let encoded = base64::encode(&input); | ||
assert!(encoded.as_bytes()==b"SGVsbG8sIFdvcmxkIQ=="); | ||
|
||
let decoded = base64::decode(&encoded); | ||
std::debug::print(&encoded); | ||
assert!(decoded==input); | ||
|
||
} | ||
|
||
|
||
} | ||
|
||
|
||
|
Oops, something went wrong.