parent
e1513cca51
commit
4545d3b5b9
File diff suppressed because it is too large
Load Diff
@ -0,0 +1,3 @@ |
||||
.DS_Store |
||||
tests/generated_security_image.jpg |
||||
tests/wallet.ngw |
@ -0,0 +1,27 @@ |
||||
[package] |
||||
name = "ng-wallet" |
||||
version = "0.1.0" |
||||
edition = "2021" |
||||
license = "MIT/Apache-2.0" |
||||
authors = ["Niko PLP <niko@nextgraph.org>"] |
||||
description = "keeps the secret keys of all identities of the user in a safe wallet" |
||||
repository = "https://git.nextgraph.org/NextGraph/nextgraph-rs" |
||||
|
||||
[dependencies] |
||||
debug_print = "1.0.0" |
||||
serde = { version = "1.0.142", features = ["derive"] } |
||||
serde_bare = "0.5.0" |
||||
serde_bytes = "0.11.7" |
||||
serde-big-array = "0.5.1" |
||||
p2p-repo = { path = "../p2p-repo" } |
||||
p2p-net = { path = "../p2p-net" } |
||||
image = "0.24.6" |
||||
getrandom = { version = "0.1.1", features = ["wasm-bindgen"] } |
||||
rand = { version = "0.7", features = ["getrandom"] } |
||||
chacha20poly1305 = "0.10.1" |
||||
#{version = "0.10.1", features = ["heapless","getrandom"] } |
||||
# slice_as_array = "1.1.0" |
||||
argon2 = "0.5.0" |
||||
safe-transmute = "0.11.2" |
||||
aes-gcm-siv = {version = "0.11.1", features = ["aes","heapless","getrandom","std"] } |
||||
base64-url = "2.0.0" |
@ -0,0 +1,213 @@ |
||||
pub const bip39_wordlist: [&str; 2048] = [ |
||||
"abandon", "ability", "able", "about", "above", "absent", "absorb", "abstract", "absurd", |
||||
"abuse", "access", "accident", "account", "accuse", "achieve", "acid", "acoustic", "acquire", |
||||
"across", "act", "action", "actor", "actress", "actual", "adapt", "add", "addict", "address", |
||||
"adjust", "admit", "adult", "advance", "advice", "aerobic", "affair", "afford", "afraid", |
||||
"again", "age", "agent", "agree", "ahead", "aim", "air", "airport", "aisle", "alarm", "album", |
||||
"alcohol", "alert", "alien", "all", "alley", "allow", "almost", "alone", "alpha", "already", |
||||
"also", "alter", "always", "amateur", "amazing", "among", "amount", "amused", "analyst", |
||||
"anchor", "ancient", "anger", "angle", "angry", "animal", "ankle", "announce", "annual", |
||||
"another", "answer", "antenna", "antique", "anxiety", "any", "apart", "apology", "appear", |
||||
"apple", "approve", "april", "arch", "arctic", "area", "arena", "argue", "arm", "armed", |
||||
"armor", "army", "around", "arrange", "arrest", "arrive", "arrow", "art", "artefact", "artist", |
||||
"artwork", "ask", "aspect", "assault", "asset", "assist", "assume", "asthma", "athlete", |
||||
"atom", "attack", "attend", "attitude", "attract", "auction", "audit", "august", "aunt", |
||||
"author", "auto", "autumn", "average", "avocado", "avoid", "awake", "aware", "away", "awesome", |
||||
"awful", "awkward", "axis", "baby", "bachelor", "bacon", "badge", "bag", "balance", "balcony", |
||||
"ball", "bamboo", "banana", "banner", "bar", "barely", "bargain", "barrel", "base", "basic", |
||||
"basket", "battle", "beach", "bean", "beauty", "because", "become", "beef", "before", "begin", |
||||
"behave", "behind", "believe", "below", "belt", "bench", "benefit", "best", "betray", "better", |
||||
"between", "beyond", "bicycle", "bid", "bike", "bind", "biology", "bird", "birth", "bitter", |
||||
"black", "blade", "blame", "blanket", "blast", "bleak", "bless", "blind", "blood", "blossom", |
||||
"blouse", "blue", "blur", "blush", "board", "boat", "body", "boil", "bomb", "bone", "bonus", |
||||
"book", "boost", "border", "boring", "borrow", "boss", "bottom", "bounce", "box", "boy", |
||||
"bracket", "brain", "brand", "brass", "brave", "bread", "breeze", "brick", "bridge", "brief", |
||||
"bright", "bring", "brisk", "broccoli", "broken", "bronze", "broom", "brother", "brown", |
||||
"brush", "bubble", "buddy", "budget", "buffalo", "build", "bulb", "bulk", "bullet", "bundle", |
||||
"bunker", "burden", "burger", "burst", "bus", "business", "busy", "butter", "buyer", "buzz", |
||||
"cabbage", "cabin", "cable", "cactus", "cage", "cake", "call", "calm", "camera", "camp", "can", |
||||
"canal", "cancel", "candy", "cannon", "canoe", "canvas", "canyon", "capable", "capital", |
||||
"captain", "car", "carbon", "card", "cargo", "carpet", "carry", "cart", "case", "cash", |
||||
"casino", "castle", "casual", "cat", "catalog", "catch", "category", "cattle", "caught", |
||||
"cause", "caution", "cave", "ceiling", "celery", "cement", "census", "century", "cereal", |
||||
"certain", "chair", "chalk", "champion", "change", "chaos", "chapter", "charge", "chase", |
||||
"chat", "cheap", "check", "cheese", "chef", "cherry", "chest", "chicken", "chief", "child", |
||||
"chimney", "choice", "choose", "chronic", "chuckle", "chunk", "churn", "cigar", "cinnamon", |
||||
"circle", "citizen", "city", "civil", "claim", "clap", "clarify", "claw", "clay", "clean", |
||||
"clerk", "clever", "click", "client", "cliff", "climb", "clinic", "clip", "clock", "clog", |
||||
"close", "cloth", "cloud", "clown", "club", "clump", "cluster", "clutch", "coach", "coast", |
||||
"coconut", "code", "coffee", "coil", "coin", "collect", "color", "column", "combine", "come", |
||||
"comfort", "comic", "common", "company", "concert", "conduct", "confirm", "congress", |
||||
"connect", "consider", "control", "convince", "cook", "cool", "copper", "copy", "coral", |
||||
"core", "corn", "correct", "cost", "cotton", "couch", "country", "couple", "course", "cousin", |
||||
"cover", "coyote", "crack", "cradle", "craft", "cram", "crane", "crash", "crater", "crawl", |
||||
"crazy", "cream", "credit", "creek", "crew", "cricket", "crime", "crisp", "critic", "crop", |
||||
"cross", "crouch", "crowd", "crucial", "cruel", "cruise", "crumble", "crunch", "crush", "cry", |
||||
"crystal", "cube", "culture", "cup", "cupboard", "curious", "current", "curtain", "curve", |
||||
"cushion", "custom", "cute", "cycle", "dad", "damage", "damp", "dance", "danger", "daring", |
||||
"dash", "daughter", "dawn", "day", "deal", "debate", "debris", "decade", "december", "decide", |
||||
"decline", "decorate", "decrease", "deer", "defense", "define", "defy", "degree", "delay", |
||||
"deliver", "demand", "demise", "denial", "dentist", "deny", "depart", "depend", "deposit", |
||||
"depth", "deputy", "derive", "describe", "desert", "design", "desk", "despair", "destroy", |
||||
"detail", "detect", "develop", "device", "devote", "diagram", "dial", "diamond", "diary", |
||||
"dice", "diesel", "diet", "differ", "digital", "dignity", "dilemma", "dinner", "dinosaur", |
||||
"direct", "dirt", "disagree", "discover", "disease", "dish", "dismiss", "disorder", "display", |
||||
"distance", "divert", "divide", "divorce", "dizzy", "doctor", "document", "dog", "doll", |
||||
"dolphin", "domain", "donate", "donkey", "donor", "door", "dose", "double", "dove", "draft", |
||||
"dragon", "drama", "drastic", "draw", "dream", "dress", "drift", "drill", "drink", "drip", |
||||
"drive", "drop", "drum", "dry", "duck", "dumb", "dune", "during", "dust", "dutch", "duty", |
||||
"dwarf", "dynamic", "eager", "eagle", "early", "earn", "earth", "easily", "east", "easy", |
||||
"echo", "ecology", "economy", "edge", "edit", "educate", "effort", "egg", "eight", "either", |
||||
"elbow", "elder", "electric", "elegant", "element", "elephant", "elevator", "elite", "else", |
||||
"embark", "embody", "embrace", "emerge", "emotion", "employ", "empower", "empty", "enable", |
||||
"enact", "end", "endless", "endorse", "enemy", "energy", "enforce", "engage", "engine", |
||||
"enhance", "enjoy", "enlist", "enough", "enrich", "enroll", "ensure", "enter", "entire", |
||||
"entry", "envelope", "episode", "equal", "equip", "era", "erase", "erode", "erosion", "error", |
||||
"erupt", "escape", "essay", "essence", "estate", "eternal", "ethics", "evidence", "evil", |
||||
"evoke", "evolve", "exact", "example", "excess", "exchange", "excite", "exclude", "excuse", |
||||
"execute", "exercise", "exhaust", "exhibit", "exile", "exist", "exit", "exotic", "expand", |
||||
"expect", "expire", "explain", "expose", "express", "extend", "extra", "eye", "eyebrow", |
||||
"fabric", "face", "faculty", "fade", "faint", "faith", "fall", "false", "fame", "family", |
||||
"famous", "fan", "fancy", "fantasy", "farm", "fashion", "fat", "fatal", "father", "fatigue", |
||||
"fault", "favorite", "feature", "february", "federal", "fee", "feed", "feel", "female", |
||||
"fence", "festival", "fetch", "fever", "few", "fiber", "fiction", "field", "figure", "file", |
||||
"film", "filter", "final", "find", "fine", "finger", "finish", "fire", "firm", "first", |
||||
"fiscal", "fish", "fit", "fitness", "fix", "flag", "flame", "flash", "flat", "flavor", "flee", |
||||
"flight", "flip", "float", "flock", "floor", "flower", "fluid", "flush", "fly", "foam", |
||||
"focus", "fog", "foil", "fold", "follow", "food", "foot", "force", "forest", "forget", "fork", |
||||
"fortune", "forum", "forward", "fossil", "foster", "found", "fox", "fragile", "frame", |
||||
"frequent", "fresh", "friend", "fringe", "frog", "front", "frost", "frown", "frozen", "fruit", |
||||
"fuel", "fun", "funny", "furnace", "fury", "future", "gadget", "gain", "galaxy", "gallery", |
||||
"game", "gap", "garage", "garbage", "garden", "garlic", "garment", "gas", "gasp", "gate", |
||||
"gather", "gauge", "gaze", "general", "genius", "genre", "gentle", "genuine", "gesture", |
||||
"ghost", "giant", "gift", "giggle", "ginger", "giraffe", "girl", "give", "glad", "glance", |
||||
"glare", "glass", "glide", "glimpse", "globe", "gloom", "glory", "glove", "glow", "glue", |
||||
"goat", "goddess", "gold", "good", "goose", "gorilla", "gospel", "gossip", "govern", "gown", |
||||
"grab", "grace", "grain", "grant", "grape", "grass", "gravity", "great", "green", "grid", |
||||
"grief", "grit", "grocery", "group", "grow", "grunt", "guard", "guess", "guide", "guilt", |
||||
"guitar", "gun", "gym", "habit", "hair", "half", "hammer", "hamster", "hand", "happy", |
||||
"harbor", "hard", "harsh", "harvest", "hat", "have", "hawk", "hazard", "head", "health", |
||||
"heart", "heavy", "hedgehog", "height", "hello", "helmet", "help", "hen", "hero", "hidden", |
||||
"high", "hill", "hint", "hip", "hire", "history", "hobby", "hockey", "hold", "hole", "holiday", |
||||
"hollow", "home", "honey", "hood", "hope", "horn", "horror", "horse", "hospital", "host", |
||||
"hotel", "hour", "hover", "hub", "huge", "human", "humble", "humor", "hundred", "hungry", |
||||
"hunt", "hurdle", "hurry", "hurt", "husband", "hybrid", "ice", "icon", "idea", "identify", |
||||
"idle", "ignore", "ill", "illegal", "illness", "image", "imitate", "immense", "immune", |
||||
"impact", "impose", "improve", "impulse", "inch", "include", "income", "increase", "index", |
||||
"indicate", "indoor", "industry", "infant", "inflict", "inform", "inhale", "inherit", |
||||
"initial", "inject", "injury", "inmate", "inner", "innocent", "input", "inquiry", "insane", |
||||
"insect", "inside", "inspire", "install", "intact", "interest", "into", "invest", "invite", |
||||
"involve", "iron", "island", "isolate", "issue", "item", "ivory", "jacket", "jaguar", "jar", |
||||
"jazz", "jealous", "jeans", "jelly", "jewel", "job", "join", "joke", "journey", "joy", "judge", |
||||
"juice", "jump", "jungle", "junior", "junk", "just", "kangaroo", "keen", "keep", "ketchup", |
||||
"key", "kick", "kid", "kidney", "kind", "kingdom", "kiss", "kit", "kitchen", "kite", "kitten", |
||||
"kiwi", "knee", "knife", "knock", "know", "lab", "label", "labor", "ladder", "lady", "lake", |
||||
"lamp", "language", "laptop", "large", "later", "latin", "laugh", "laundry", "lava", "law", |
||||
"lawn", "lawsuit", "layer", "lazy", "leader", "leaf", "learn", "leave", "lecture", "left", |
||||
"leg", "legal", "legend", "leisure", "lemon", "lend", "length", "lens", "leopard", "lesson", |
||||
"letter", "level", "liar", "liberty", "library", "license", "life", "lift", "light", "like", |
||||
"limb", "limit", "link", "lion", "liquid", "list", "little", "live", "lizard", "load", "loan", |
||||
"lobster", "local", "lock", "logic", "lonely", "long", "loop", "lottery", "loud", "lounge", |
||||
"love", "loyal", "lucky", "luggage", "lumber", "lunar", "lunch", "luxury", "lyrics", "machine", |
||||
"mad", "magic", "magnet", "maid", "mail", "main", "major", "make", "mammal", "man", "manage", |
||||
"mandate", "mango", "mansion", "manual", "maple", "marble", "march", "margin", "marine", |
||||
"market", "marriage", "mask", "mass", "master", "match", "material", "math", "matrix", |
||||
"matter", "maximum", "maze", "meadow", "mean", "measure", "meat", "mechanic", "medal", "media", |
||||
"melody", "melt", "member", "memory", "mention", "menu", "mercy", "merge", "merit", "merry", |
||||
"mesh", "message", "metal", "method", "middle", "midnight", "milk", "million", "mimic", "mind", |
||||
"minimum", "minor", "minute", "miracle", "mirror", "misery", "miss", "mistake", "mix", "mixed", |
||||
"mixture", "mobile", "model", "modify", "mom", "moment", "monitor", "monkey", "monster", |
||||
"month", "moon", "moral", "more", "morning", "mosquito", "mother", "motion", "motor", |
||||
"mountain", "mouse", "move", "movie", "much", "muffin", "mule", "multiply", "muscle", "museum", |
||||
"mushroom", "music", "must", "mutual", "myself", "mystery", "myth", "naive", "name", "napkin", |
||||
"narrow", "nasty", "nation", "nature", "near", "neck", "need", "negative", "neglect", |
||||
"neither", "nephew", "nerve", "nest", "net", "network", "neutral", "never", "news", "next", |
||||
"nice", "night", "noble", "noise", "nominee", "noodle", "normal", "north", "nose", "notable", |
||||
"note", "nothing", "notice", "novel", "now", "nuclear", "number", "nurse", "nut", "oak", |
||||
"obey", "object", "oblige", "obscure", "observe", "obtain", "obvious", "occur", "ocean", |
||||
"october", "odor", "off", "offer", "office", "often", "oil", "okay", "old", "olive", "olympic", |
||||
"omit", "once", "one", "onion", "online", "only", "open", "opera", "opinion", "oppose", |
||||
"option", "orange", "orbit", "orchard", "order", "ordinary", "organ", "orient", "original", |
||||
"orphan", "ostrich", "other", "outdoor", "outer", "output", "outside", "oval", "oven", "over", |
||||
"own", "owner", "oxygen", "oyster", "ozone", "pact", "paddle", "page", "pair", "palace", |
||||
"palm", "panda", "panel", "panic", "panther", "paper", "parade", "parent", "park", "parrot", |
||||
"party", "pass", "patch", "path", "patient", "patrol", "pattern", "pause", "pave", "payment", |
||||
"peace", "peanut", "pear", "peasant", "pelican", "pen", "penalty", "pencil", "people", |
||||
"pepper", "perfect", "permit", "person", "pet", "phone", "photo", "phrase", "physical", |
||||
"piano", "picnic", "picture", "piece", "pig", "pigeon", "pill", "pilot", "pink", "pioneer", |
||||
"pipe", "pistol", "pitch", "pizza", "place", "planet", "plastic", "plate", "play", "please", |
||||
"pledge", "pluck", "plug", "plunge", "poem", "poet", "point", "polar", "pole", "police", |
||||
"pond", "pony", "pool", "popular", "portion", "position", "possible", "post", "potato", |
||||
"pottery", "poverty", "powder", "power", "practice", "praise", "predict", "prefer", "prepare", |
||||
"present", "pretty", "prevent", "price", "pride", "primary", "print", "priority", "prison", |
||||
"private", "prize", "problem", "process", "produce", "profit", "program", "project", "promote", |
||||
"proof", "property", "prosper", "protect", "proud", "provide", "public", "pudding", "pull", |
||||
"pulp", "pulse", "pumpkin", "punch", "pupil", "puppy", "purchase", "purity", "purpose", |
||||
"purse", "push", "put", "puzzle", "pyramid", "quality", "quantum", "quarter", "question", |
||||
"quick", "quit", "quiz", "quote", "rabbit", "raccoon", "race", "rack", "radar", "radio", |
||||
"rail", "rain", "raise", "rally", "ramp", "ranch", "random", "range", "rapid", "rare", "rate", |
||||
"rather", "raven", "raw", "razor", "ready", "real", "reason", "rebel", "rebuild", "recall", |
||||
"receive", "recipe", "record", "recycle", "reduce", "reflect", "reform", "refuse", "region", |
||||
"regret", "regular", "reject", "relax", "release", "relief", "rely", "remain", "remember", |
||||
"remind", "remove", "render", "renew", "rent", "reopen", "repair", "repeat", "replace", |
||||
"report", "require", "rescue", "resemble", "resist", "resource", "response", "result", |
||||
"retire", "retreat", "return", "reunion", "reveal", "review", "reward", "rhythm", "rib", |
||||
"ribbon", "rice", "rich", "ride", "ridge", "rifle", "right", "rigid", "ring", "riot", "ripple", |
||||
"risk", "ritual", "rival", "river", "road", "roast", "robot", "robust", "rocket", "romance", |
||||
"roof", "rookie", "room", "rose", "rotate", "rough", "round", "route", "royal", "rubber", |
||||
"rude", "rug", "rule", "run", "runway", "rural", "sad", "saddle", "sadness", "safe", "sail", |
||||
"salad", "salmon", "salon", "salt", "salute", "same", "sample", "sand", "satisfy", "satoshi", |
||||
"sauce", "sausage", "save", "say", "scale", "scan", "scare", "scatter", "scene", "scheme", |
||||
"school", "science", "scissors", "scorpion", "scout", "scrap", "screen", "script", "scrub", |
||||
"sea", "search", "season", "seat", "second", "secret", "section", "security", "seed", "seek", |
||||
"segment", "select", "sell", "seminar", "senior", "sense", "sentence", "series", "service", |
||||
"session", "settle", "setup", "seven", "shadow", "shaft", "shallow", "share", "shed", "shell", |
||||
"sheriff", "shield", "shift", "shine", "ship", "shiver", "shock", "shoe", "shoot", "shop", |
||||
"short", "shoulder", "shove", "shrimp", "shrug", "shuffle", "shy", "sibling", "sick", "side", |
||||
"siege", "sight", "sign", "silent", "silk", "silly", "silver", "similar", "simple", "since", |
||||
"sing", "siren", "sister", "situate", "six", "size", "skate", "sketch", "ski", "skill", "skin", |
||||
"skirt", "skull", "slab", "slam", "sleep", "slender", "slice", "slide", "slight", "slim", |
||||
"slogan", "slot", "slow", "slush", "small", "smart", "smile", "smoke", "smooth", "snack", |
||||
"snake", "snap", "sniff", "snow", "soap", "soccer", "social", "sock", "soda", "soft", "solar", |
||||
"soldier", "solid", "solution", "solve", "someone", "song", "soon", "sorry", "sort", "soul", |
||||
"sound", "soup", "source", "south", "space", "spare", "spatial", "spawn", "speak", "special", |
||||
"speed", "spell", "spend", "sphere", "spice", "spider", "spike", "spin", "spirit", "split", |
||||
"spoil", "sponsor", "spoon", "sport", "spot", "spray", "spread", "spring", "spy", "square", |
||||
"squeeze", "squirrel", "stable", "stadium", "staff", "stage", "stairs", "stamp", "stand", |
||||
"start", "state", "stay", "steak", "steel", "stem", "step", "stereo", "stick", "still", |
||||
"sting", "stock", "stomach", "stone", "stool", "story", "stove", "strategy", "street", |
||||
"strike", "strong", "struggle", "student", "stuff", "stumble", "style", "subject", "submit", |
||||
"subway", "success", "such", "sudden", "suffer", "sugar", "suggest", "suit", "summer", "sun", |
||||
"sunny", "sunset", "super", "supply", "supreme", "sure", "surface", "surge", "surprise", |
||||
"surround", "survey", "suspect", "sustain", "swallow", "swamp", "swap", "swarm", "swear", |
||||
"sweet", "swift", "swim", "swing", "switch", "sword", "symbol", "symptom", "syrup", "system", |
||||
"table", "tackle", "tag", "tail", "talent", "talk", "tank", "tape", "target", "task", "taste", |
||||
"tattoo", "taxi", "teach", "team", "tell", "ten", "tenant", "tennis", "tent", "term", "test", |
||||
"text", "thank", "that", "theme", "then", "theory", "there", "they", "thing", "this", |
||||
"thought", "three", "thrive", "throw", "thumb", "thunder", "ticket", "tide", "tiger", "tilt", |
||||
"timber", "time", "tiny", "tip", "tired", "tissue", "title", "toast", "tobacco", "today", |
||||
"toddler", "toe", "together", "toilet", "token", "tomato", "tomorrow", "tone", "tongue", |
||||
"tonight", "tool", "tooth", "top", "topic", "topple", "torch", "tornado", "tortoise", "toss", |
||||
"total", "tourist", "toward", "tower", "town", "toy", "track", "trade", "traffic", "tragic", |
||||
"train", "transfer", "trap", "trash", "travel", "tray", "treat", "tree", "trend", "trial", |
||||
"tribe", "trick", "trigger", "trim", "trip", "trophy", "trouble", "truck", "true", "truly", |
||||
"trumpet", "trust", "truth", "try", "tube", "tuition", "tumble", "tuna", "tunnel", "turkey", |
||||
"turn", "turtle", "twelve", "twenty", "twice", "twin", "twist", "two", "type", "typical", |
||||
"ugly", "umbrella", "unable", "unaware", "uncle", "uncover", "under", "undo", "unfair", |
||||
"unfold", "unhappy", "uniform", "unique", "unit", "universe", "unknown", "unlock", "until", |
||||
"unusual", "unveil", "update", "upgrade", "uphold", "upon", "upper", "upset", "urban", "urge", |
||||
"usage", "use", "used", "useful", "useless", "usual", "utility", "vacant", "vacuum", "vague", |
||||
"valid", "valley", "valve", "van", "vanish", "vapor", "various", "vast", "vault", "vehicle", |
||||
"velvet", "vendor", "venture", "venue", "verb", "verify", "version", "very", "vessel", |
||||
"veteran", "viable", "vibrant", "vicious", "victory", "video", "view", "village", "vintage", |
||||
"violin", "virtual", "virus", "visa", "visit", "visual", "vital", "vivid", "vocal", "voice", |
||||
"void", "volcano", "volume", "vote", "voyage", "wage", "wagon", "wait", "walk", "wall", |
||||
"walnut", "want", "warfare", "warm", "warrior", "wash", "wasp", "waste", "water", "wave", |
||||
"way", "wealth", "weapon", "wear", "weasel", "weather", "web", "wedding", "weekend", "weird", |
||||
"welcome", "west", "wet", "whale", "what", "wheat", "wheel", "when", "where", "whip", |
||||
"whisper", "wide", "width", "wife", "wild", "will", "win", "window", "wine", "wing", "wink", |
||||
"winner", "winter", "wire", "wisdom", "wise", "wish", "witness", "wolf", "woman", "wonder", |
||||
"wood", "wool", "word", "work", "world", "worry", "worth", "wrap", "wreck", "wrestle", "wrist", |
||||
"write", "wrong", "yard", "year", "yellow", "you", "young", "youth", "zebra", "zero", "zone", |
||||
"zoo", |
||||
]; |
@ -0,0 +1,546 @@ |
||||
// Copyright (c) 2022-2023 Niko Bonnieure, Par le Peuple, NextGraph.org developers
|
||||
// All rights reserved.
|
||||
// Licensed under the Apache License, Version 2.0
|
||||
// <LICENSE-APACHE2 or http://www.apache.org/licenses/LICENSE-2.0>
|
||||
// or the MIT license <LICENSE-MIT or http://opensource.org/licenses/MIT>,
|
||||
// at your option. All files in the project carrying such
|
||||
// notice may not be copied, modified, or distributed except
|
||||
// according to those terms.
|
||||
|
||||
// #[macro_use]
|
||||
// extern crate slice_as_array;
|
||||
#[macro_use] |
||||
extern crate p2p_net; |
||||
|
||||
pub mod types; |
||||
|
||||
pub mod bip39; |
||||
|
||||
use std::io::Cursor; |
||||
|
||||
use crate::bip39::bip39_wordlist; |
||||
use crate::types::*; |
||||
use aes_gcm_siv::{ |
||||
aead::{heapless::Vec as HeaplessVec, AeadInPlace, KeyInit}, |
||||
Aes256GcmSiv, Nonce, |
||||
}; |
||||
use argon2::{Algorithm, Argon2, AssociatedData, ParamsBuilder, Version}; |
||||
use chacha20poly1305::XChaCha20Poly1305; |
||||
|
||||
use image::{imageops::FilterType, io::Reader as ImageReader, ImageOutputFormat}; |
||||
use safe_transmute::transmute_to_bytes; |
||||
|
||||
use p2p_repo::types::{PubKey, Site, SiteType, Timestamp}; |
||||
use p2p_repo::utils::{generate_keypair, now_timestamp, sign, verify}; |
||||
use rand::{thread_rng, Rng}; |
||||
use serde_bare::{from_slice, to_vec}; |
||||
|
||||
pub fn enc_master_key( |
||||
master_key: [u8; 32], |
||||
key: [u8; 32], |
||||
nonce: u8, |
||||
wallet_id: WalletId, |
||||
) -> Result<[u8; 48], NgWalletError> { |
||||
let cipher = Aes256GcmSiv::new(&key.into()); |
||||
let mut nonce_buffer = [0u8; 12]; |
||||
nonce_buffer[0] = nonce; |
||||
let nonce = Nonce::from_slice(&nonce_buffer); |
||||
|
||||
let mut buffer: HeaplessVec<u8, 48> = HeaplessVec::new(); // Note: buffer needs 16-bytes overhead for auth tag
|
||||
buffer.extend_from_slice(&master_key); |
||||
|
||||
// Encrypt `buffer` in-place, replacing the plaintext contents with ciphertext
|
||||
cipher |
||||
.encrypt_in_place(nonce, &to_vec(&wallet_id).unwrap(), &mut buffer) |
||||
.map_err(|e| NgWalletError::EncryptionError)?; |
||||
|
||||
// `buffer` now contains the encrypted master key
|
||||
// println!("cipher {:?}", buffer);
|
||||
Ok(buffer.into_array::<48>().unwrap()) |
||||
} |
||||
|
||||
pub fn dec_master_key( |
||||
ciphertext: [u8; 48], |
||||
key: [u8; 32], |
||||
nonce: u8, |
||||
wallet_id: WalletId, |
||||
) -> Result<[u8; 32], NgWalletError> { |
||||
let cipher = Aes256GcmSiv::new(&key.into()); |
||||
let mut nonce_buffer = [0u8; 12]; |
||||
nonce_buffer[0] = nonce; |
||||
let nonce = Nonce::from_slice(&nonce_buffer); |
||||
|
||||
let mut buffer: HeaplessVec<u8, 48> = HeaplessVec::from_slice(&ciphertext).unwrap(); // Note: buffer needs 16-bytes overhead for auth tag
|
||||
|
||||
// Decrypt `buffer` in-place, replacing its ciphertext context with the original plaintext
|
||||
cipher |
||||
.decrypt_in_place(nonce, &to_vec(&wallet_id).unwrap(), &mut buffer) |
||||
.map_err(|e| NgWalletError::DecryptionError)?; |
||||
Ok(buffer.into_array::<32>().unwrap()) |
||||
} |
||||
|
||||
fn gen_nonce(peer_id: PubKey, nonce: u64) -> [u8; 24] { |
||||
let mut buffer = Vec::with_capacity(24); |
||||
buffer.extend_from_slice(&peer_id.slice()[0..16]); |
||||
buffer.extend_from_slice(&nonce.to_be_bytes()); |
||||
buffer.try_into().unwrap() |
||||
} |
||||
|
||||
fn gen_associated_data(timestamp: Timestamp, wallet_id: WalletId) -> Vec<u8> { |
||||
let ser_wallet = to_vec(&wallet_id).unwrap(); |
||||
[ser_wallet, timestamp.to_be_bytes().to_vec()].concat() |
||||
} |
||||
|
||||
pub fn enc_encrypted_block( |
||||
block: &EncryptedWalletV0, |
||||
master_key: [u8; 32], |
||||
peer_id: PubKey, |
||||
nonce: u64, |
||||
timestamp: Timestamp, |
||||
wallet_id: WalletId, |
||||
) -> Result<Vec<u8>, NgWalletError> { |
||||
let ser_encrypted_block = to_vec(block).map_err(|e| NgWalletError::InternalError)?; |
||||
|
||||
let nonce_buffer: [u8; 24] = gen_nonce(peer_id, nonce); |
||||
|
||||
let cipher = XChaCha20Poly1305::new(&master_key.into()); |
||||
|
||||
let mut buffer: Vec<u8> = Vec::with_capacity(ser_encrypted_block.len() + 16); // Note: buffer needs 16-bytes overhead for auth tag
|
||||
buffer.extend_from_slice(&ser_encrypted_block); |
||||
|
||||
// Encrypt `buffer` in-place, replacing the plaintext contents with ciphertext
|
||||
cipher |
||||
.encrypt_in_place( |
||||
&nonce_buffer.into(), |
||||
&gen_associated_data(timestamp, wallet_id), |
||||
&mut buffer, |
||||
) |
||||
.map_err(|e| NgWalletError::EncryptionError)?; |
||||
|
||||
// `buffer` now contains the message ciphertext
|
||||
// println!("encrypted_block ciphertext {:?}", buffer);
|
||||
|
||||
Ok(buffer) |
||||
} |
||||
|
||||
pub fn dec_encrypted_block( |
||||
mut ciphertext: Vec<u8>, |
||||
master_key: [u8; 32], |
||||
peer_id: PubKey, |
||||
nonce: u64, |
||||
timestamp: Timestamp, |
||||
wallet_id: WalletId, |
||||
) -> Result<EncryptedWalletV0, NgWalletError> { |
||||
let nonce_buffer: [u8; 24] = gen_nonce(peer_id, nonce); |
||||
|
||||
let cipher = XChaCha20Poly1305::new(&master_key.into()); |
||||
|
||||
// Decrypt `ciphertext` in-place, replacing its ciphertext context with the original plaintext
|
||||
cipher |
||||
.decrypt_in_place( |
||||
&nonce_buffer.into(), |
||||
&gen_associated_data(timestamp, wallet_id), |
||||
&mut ciphertext, |
||||
) |
||||
.map_err(|e| NgWalletError::DecryptionError)?; |
||||
|
||||
// `ciphertext` now contains the decrypted block
|
||||
//println!("decrypted_block {:?}", ciphertext);
|
||||
|
||||
let decrypted_block = |
||||
from_slice::<EncryptedWalletV0>(&ciphertext).map_err(|e| NgWalletError::DecryptionError)?; |
||||
|
||||
Ok(decrypted_block) |
||||
} |
||||
|
||||
pub fn derive_key_from_pass(pass: Vec<u8>, salt: [u8; 16], wallet_id: WalletId) -> [u8; 32] { |
||||
let params = ParamsBuilder::new() |
||||
.m_cost(50 * 1024) |
||||
.t_cost(2) |
||||
.p_cost(1) |
||||
.data(AssociatedData::new(wallet_id.slice()).unwrap()) |
||||
.output_len(32) |
||||
.build() |
||||
.unwrap(); |
||||
let argon = Argon2::new(Algorithm::Argon2id, Version::V0x13, params); |
||||
let mut out = [0u8; 32]; |
||||
argon.hash_password_into(&pass, &salt, &mut out).unwrap(); |
||||
out |
||||
} |
||||
|
||||
pub fn open_wallet_with_pazzle( |
||||
wallet: Wallet, |
||||
pazzle: Vec<u8>, |
||||
pin: [u8; 4], |
||||
) -> Result<EncryptedWallet, NgWalletError> { |
||||
verify(&wallet.content_as_bytes(), wallet.sig(), wallet.id()) |
||||
.map_err(|e| NgWalletError::InvalidSignature)?; |
||||
|
||||
match wallet { |
||||
Wallet::V0(v0) => { |
||||
let pazzle_key = derive_key_from_pass( |
||||
[pazzle, pin.to_vec()].concat(), |
||||
v0.content.salt_pazzle, |
||||
v0.id, |
||||
); |
||||
|
||||
let master_key = dec_master_key( |
||||
v0.content.enc_master_key_pazzle, |
||||
pazzle_key, |
||||
v0.content.master_nonce, |
||||
v0.id, |
||||
)?; |
||||
|
||||
Ok(EncryptedWallet::V0(dec_encrypted_block( |
||||
v0.content.encrypted, |
||||
master_key, |
||||
v0.content.peer_id, |
||||
v0.content.nonce, |
||||
v0.content.timestamp, |
||||
v0.id, |
||||
)?)) |
||||
} |
||||
} |
||||
} |
||||
|
||||
pub fn open_wallet_with_mnemonic( |
||||
wallet: Wallet, |
||||
mnemonic: [u16; 12], |
||||
pin: [u8; 4], |
||||
) -> Result<EncryptedWallet, NgWalletError> { |
||||
verify(&wallet.content_as_bytes(), wallet.sig(), wallet.id()) |
||||
.map_err(|e| NgWalletError::InvalidSignature)?; |
||||
|
||||
match wallet { |
||||
Wallet::V0(v0) => { |
||||
let mnemonic_key = derive_key_from_pass( |
||||
[transmute_to_bytes(&mnemonic), &pin].concat(), |
||||
v0.content.salt_mnemonic, |
||||
v0.id, |
||||
); |
||||
|
||||
let master_key = dec_master_key( |
||||
v0.content.enc_master_key_mnemonic, |
||||
mnemonic_key, |
||||
v0.content.master_nonce, |
||||
v0.id, |
||||
)?; |
||||
|
||||
Ok(EncryptedWallet::V0(dec_encrypted_block( |
||||
v0.content.encrypted, |
||||
master_key, |
||||
v0.content.peer_id, |
||||
v0.content.nonce, |
||||
v0.content.timestamp, |
||||
v0.id, |
||||
)?)) |
||||
} |
||||
} |
||||
} |
||||
|
||||
pub fn display_mnemonic(mnemonic: &[u16; 12]) -> Vec<String> { |
||||
let res: Vec<String> = mnemonic |
||||
.into_iter() |
||||
.map(|i| String::from(bip39_wordlist[*i as usize])) |
||||
.collect(); |
||||
res |
||||
} |
||||
|
||||
/// creates a Wallet from a pin, a security text and image (with option to send the bootstrap and wallet to nextgraph.one)
|
||||
/// and returns the Wallet, the pazzle and the mnemonic
|
||||
pub fn create_wallet_v0( |
||||
security_img: Vec<u8>, |
||||
security_txt: String, |
||||
pin: [u8; 4], |
||||
pazzle_length: u8, |
||||
send_bootstrap: Option<&Bootstrap>, |
||||
send_wallet: bool, |
||||
peer_id: PubKey, |
||||
nonce: u64, |
||||
) -> Result<(Wallet, Vec<u8>, [u16; 12]), NgWalletError> { |
||||
// TODO : use some automatically zeroed variable for the 2 first arguments, and for the returned values
|
||||
|
||||
// pazzle_length can only be 9, 12, or 15
|
||||
if (pazzle_length != 9 && pazzle_length != 12 && pazzle_length != 15) { |
||||
return Err(NgWalletError::InvalidPazzleLength); |
||||
} |
||||
|
||||
// cannot submit wallet if we don't submit also the bootstrap
|
||||
if send_bootstrap.is_none() && send_wallet { |
||||
return Err(NgWalletError::SubmissionError); |
||||
} |
||||
|
||||
// check validity of PIN
|
||||
|
||||
// shouldn't start with 0
|
||||
if pin[0] == 0 { |
||||
return Err(NgWalletError::InvalidPin); |
||||
} |
||||
|
||||
// each digit shouldnt be greater than 9
|
||||
if pin[0] > 9 || pin[1] > 9 || pin[2] > 9 || pin[3] > 9 { |
||||
return Err(NgWalletError::InvalidPin); |
||||
} |
||||
|
||||
// check for uniqueness of each digit
|
||||
if pin[1] == pin[0] |
||||
|| pin[1] == pin[2] |
||||
|| pin[1] == pin[3] |
||||
|| pin[2] == pin[0] |
||||
|| pin[2] == pin[3] |
||||
|| pin[3] == pin[0] |
||||
{ |
||||
return Err(NgWalletError::InvalidPin); |
||||
} |
||||
|
||||
// check for ascending series
|
||||
if pin[1] == pin[0] + 1 && pin[2] == pin[1] + 1 && pin[3] == pin[2] + 1 { |
||||
return Err(NgWalletError::InvalidPin); |
||||
} |
||||
|
||||
// check for descending series
|
||||
if pin[3] >= 3 && pin[2] == pin[3] - 1 && pin[1] == pin[2] - 1 && pin[0] == pin[1] - 1 { |
||||
return Err(NgWalletError::InvalidPin); |
||||
} |
||||
|
||||
// check validity of security text
|
||||
let words: Vec<_> = security_txt.split_whitespace().collect(); |
||||
let new_string = words.join(" "); |
||||
let count = new_string.chars().count(); |
||||
if count < 10 || count > 100 { |
||||
return Err(NgWalletError::InvalidSecurityText); |
||||
} |
||||
|
||||
// check validity of image
|
||||
let decoded_img = ImageReader::new(Cursor::new(security_img)) |
||||
.with_guessed_format() |
||||
.map_err(|e| NgWalletError::InvalidSecurityImage)? |
||||
.decode() |
||||
.map_err(|e| NgWalletError::InvalidSecurityImage)?; |
||||
|
||||
if decoded_img.height() < 150 || decoded_img.width() < 150 { |
||||
return Err(NgWalletError::InvalidSecurityImage); |
||||
} |
||||
|
||||
let resized_img = decoded_img.resize_to_fill(400, 400, FilterType::Triangle); |
||||
|
||||
let buffer: Vec<u8> = Vec::with_capacity(100000); |
||||
let mut cursor = Cursor::new(buffer); |
||||
resized_img |
||||
.write_to(&mut cursor, ImageOutputFormat::Jpeg(72)) |
||||
.map_err(|e| NgWalletError::InvalidSecurityImage)?; |
||||
|
||||
// creating the wallet keys
|
||||
|
||||
let (wallet_key, wallet_id) = generate_keypair(); |
||||
|
||||
let site = Site::create(SiteType::Individual).map_err(|e| NgWalletError::InternalError)?; |
||||
|
||||
// let mut pazzle_random = vec![0u8; pazzle_length.into()];
|
||||
// getrandom::getrandom(&mut pazzle_random).map_err(|e| NgWalletError::InternalError)?;
|
||||
|
||||
let mut pazzle = vec![0u8; pazzle_length.into()]; |
||||
let mut ran = thread_rng(); |
||||
for i in &mut pazzle { |
||||
*i = ran.gen_range(0, 16); |
||||
} |
||||
|
||||
//println!("pazzle {:?}", pazzle);
|
||||
|
||||
let mut mnemonic = [0u16; 12]; |
||||
for i in &mut mnemonic { |
||||
*i = ran.gen_range(0, 2048); |
||||
} |
||||
|
||||
//println!("mnemonic {:?}", display_mnemonic(&mnemonic));
|
||||
|
||||
//slice_as_array!(&mnemonic, [String; 12])
|
||||
//.ok_or(NgWalletError::InternalError)?
|
||||
//.clone(),
|
||||
|
||||
let encrypted_block = EncryptedWalletV0 { |
||||
pazzle: pazzle.clone(), |
||||
mnemonic, |
||||
pin, |
||||
sites: vec![site], |
||||
}; |
||||
|
||||
let mut salt_pazzle = [0u8; 16]; |
||||
getrandom::getrandom(&mut salt_pazzle).map_err(|e| NgWalletError::InternalError)?; |
||||
|
||||
let mut salt_mnemonic = [0u8; 16]; |
||||
getrandom::getrandom(&mut salt_mnemonic).map_err(|e| NgWalletError::InternalError)?; |
||||
|
||||
//println!("salt_pazzle {:?}", salt_pazzle);
|
||||
//println!("salt_mnemonic {:?}", salt_mnemonic);
|
||||
|
||||
let pazzle_key = derive_key_from_pass( |
||||
[pazzle.clone(), pin.to_vec()].concat(), |
||||
salt_pazzle, |
||||
wallet_id, |
||||
); |
||||
|
||||
let mnemonic_key = derive_key_from_pass( |
||||
[transmute_to_bytes(&mnemonic), &pin].concat(), |
||||
salt_mnemonic, |
||||
wallet_id, |
||||
); |
||||
|
||||
let mut master_key = [0u8; 32]; |
||||
getrandom::getrandom(&mut master_key).map_err(|e| NgWalletError::InternalError)?; |
||||
|
||||
let enc_master_key_pazzle = enc_master_key(master_key, pazzle_key, 0, wallet_id)?; |
||||
|
||||
let enc_master_key_mnemonic = enc_master_key(master_key, mnemonic_key, 0, wallet_id)?; |
||||
|
||||
let timestamp = now_timestamp(); |
||||
let encrypted = enc_encrypted_block( |
||||
&encrypted_block, |
||||
master_key, |
||||
peer_id, |
||||
nonce, |
||||
timestamp, |
||||
wallet_id, |
||||
)?; |
||||
|
||||
let wallet_content = WalletContentV0 { |
||||
security_img: cursor.into_inner(), |
||||
security_txt: new_string, |
||||
salt_pazzle, |
||||
salt_mnemonic, |
||||
enc_master_key_pazzle, |
||||
enc_master_key_mnemonic, |
||||
master_nonce: 0, |
||||
timestamp, |
||||
peer_id, |
||||
nonce, |
||||
encrypted, |
||||
}; |
||||
|
||||
let ser_wallet = serde_bare::to_vec(&wallet_content).unwrap(); |
||||
let sig = sign(wallet_key, wallet_id, &ser_wallet).unwrap(); |
||||
|
||||
let wallet_v0 = WalletV0 { |
||||
/// ID
|
||||
id: wallet_id, |
||||
/// Content
|
||||
content: wallet_content, |
||||
/// Signature over content by wallet's private key
|
||||
sig, |
||||
}; |
||||
|
||||
// let content = BootstrapContentV0 { servers: vec![] };
|
||||
// let ser = serde_bare::to_vec(&content).unwrap();
|
||||
// let sig = sign(wallet_key, wallet_id, &ser).unwrap();
|
||||
|
||||
// let bootstrap = Bootstrap::V0(BootstrapV0 {
|
||||
// id: wallet_id,
|
||||
// content,
|
||||
// sig,
|
||||
// });
|
||||
|
||||
// TODO send bootstrap (if)
|
||||
// TODO send wallet (if)
|
||||
|
||||
Ok((Wallet::V0(wallet_v0), pazzle, mnemonic)) |
||||
} |
||||
|
||||
#[cfg(test)] |
||||
mod tests { |
||||
use super::*; |
||||
use p2p_repo::utils::generate_keypair; |
||||
use std::fs::File; |
||||
use std::io::BufReader; |
||||
use std::io::Read; |
||||
use std::io::Write; |
||||
use std::time::Instant; |
||||
|
||||
#[test] |
||||
fn create_wallet() { |
||||
// loading an image file from disk
|
||||
let f = File::open("tests/valid_security_image.jpg") |
||||
.expect("open of tests/valid_security_image.jpg"); |
||||
let mut reader = BufReader::new(f); |
||||
let mut img_buffer = Vec::new(); |
||||
// Read file into vector.
|
||||
reader |
||||
.read_to_end(&mut img_buffer) |
||||
.expect("read of valid_security_image.jpg"); |
||||
|
||||
let pin = [5, 2, 9, 1]; |
||||
|
||||
let creation = Instant::now(); |
||||
|
||||
let res = create_wallet_v0( |
||||
img_buffer, |
||||
" know yourself ".to_string(), |
||||
pin, |
||||
9, |
||||
None, |
||||
false, |
||||
PubKey::Ed25519PubKey([ |
||||
119, 251, 253, 29, 135, 199, 254, 50, 134, 67, 1, 208, 117, 196, 167, 107, 2, 113, |
||||
98, 243, 49, 90, 7, 0, 157, 58, 14, 187, 14, 3, 116, 86, |
||||
]), |
||||
0, |
||||
) |
||||
.expect("create_wallet_v0"); |
||||
|
||||
log!( |
||||
"creation of wallet took: {} ms", |
||||
creation.elapsed().as_millis() |
||||
); |
||||
log!("-----------------------------"); |
||||
|
||||
let (wallet, pazzle, mnemonic) = res; |
||||
|
||||
let mut file = File::create("tests/wallet.ngw").expect("open wallet write file"); |
||||
let ser_wallet = to_vec(&NgFile::V0(NgFileV0::Wallet(wallet.clone()))).unwrap(); |
||||
file.write_all(&ser_wallet); |
||||
|
||||
log!("wallet id: {:?}", base64_url::encode(&wallet.id().slice())); |
||||
log!("pazzle {:?}", pazzle); |
||||
log!("mnemonic {:?}", display_mnemonic(&mnemonic)); |
||||
log!("pin {:?}", pin); |
||||
|
||||
if let Wallet::V0(v0) = wallet { |
||||
log!("security text: {:?}", v0.content.security_txt); |
||||
|
||||
let mut file = |
||||
File::create("tests/generated_security_image.jpg").expect("open write file"); |
||||
file.write_all(&v0.content.security_img); |
||||
|
||||
let f = File::open("tests/generated_security_image.jpg.compare") |
||||
.expect("open of generated_security_image.jpg.compare"); |
||||
let mut reader = BufReader::new(f); |
||||
let mut generated_security_image_compare = Vec::new(); |
||||
// Read file into vector.
|
||||
reader |
||||
.read_to_end(&mut generated_security_image_compare) |
||||
.expect("read of generated_security_image.jpg.compare"); |
||||
|
||||
assert_eq!(v0.content.security_img, generated_security_image_compare); |
||||
|
||||
let opening_mnemonic = Instant::now(); |
||||
|
||||
let w = open_wallet_with_mnemonic(Wallet::V0(v0.clone()), mnemonic, pin) |
||||
.expect("open with mnemonic"); |
||||
//println!("encrypted part {:?}", w);
|
||||
|
||||
log!( |
||||
"opening of wallet with mnemonic took: {} ms", |
||||
opening_mnemonic.elapsed().as_millis() |
||||
); |
||||
let opening_pazzle = Instant::now(); |
||||
|
||||
let w = open_wallet_with_pazzle(Wallet::V0(v0.clone()), pazzle, pin) |
||||
.expect("open with pazzle"); |
||||
//println!("encrypted part {:?}", w);
|
||||
|
||||
log!( |
||||
"opening of wallet with pazzle took: {} ms", |
||||
opening_pazzle.elapsed().as_millis() |
||||
); |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,233 @@ |
||||
// Copyright (c) 2022-2023 Niko Bonnieure, Par le Peuple, NextGraph.org developers
|
||||
// All rights reserved.
|
||||
// Licensed under the Apache License, Version 2.0
|
||||
// <LICENSE-APACHE2 or http://www.apache.org/licenses/LICENSE-2.0>
|
||||
// or the MIT license <LICENSE-MIT or http://opensource.org/licenses/MIT>,
|
||||
// at your option. All files in the project carrying such
|
||||
// notice may not be copied, modified, or distributed except
|
||||
// according to those terms.
|
||||
|
||||
use serde::{Deserialize, Serialize}; |
||||
use serde_big_array::BigArray; |
||||
|
||||
use p2p_net::types::NetAddr; |
||||
use p2p_repo::types::*; |
||||
|
||||
/// WalletId is a PubKey
|
||||
pub type WalletId = PubKey; |
||||
|
||||
/// BootstrapId is a WalletId
|
||||
pub type BootstrapId = WalletId; |
||||
|
||||
/// BootstrapServer type
|
||||
#[derive(Clone, Debug, Serialize, Deserialize, PartialEq)] |
||||
pub enum BoostrapServerTypeV0 { |
||||
Localhost, |
||||
BoxPrivate(Vec<NetAddr>), |
||||
BoxPublic(Vec<NetAddr>), |
||||
BoxPublicDyn(Vec<NetAddr>), // can be empty
|
||||
Domain(String), |
||||
} |
||||
|
||||
/// BootstrapServer details Version 0
|
||||
#[derive(Clone, Debug, Serialize, Deserialize)] |
||||
pub struct BootstrapServerV0 { |
||||
/// Network addresses
|
||||
pub serverType: BoostrapServerTypeV0, |
||||
|
||||
/// peerId of the server
|
||||
pub peerId: PubKey, |
||||
} |
||||
|
||||
/// Bootstrap content Version 0
|
||||
#[derive(Clone, Debug, Serialize, Deserialize)] |
||||
pub struct BootstrapContentV0 { |
||||
/// list of servers, in order of preference
|
||||
pub servers: Vec<BootstrapServerV0>, |
||||
} |
||||
|
||||
/// Bootstrap Version 0
|
||||
#[derive(Clone, Debug, Serialize, Deserialize)] |
||||
pub struct BootstrapV0 { |
||||
/// ID
|
||||
pub id: BootstrapId, |
||||
|
||||
/// Content
|
||||
pub content: BootstrapContentV0, |
||||
|
||||
/// Signature over content by wallet's private key
|
||||
pub sig: Sig, |
||||
} |
||||
|
||||
/// Bootstrap info
|
||||
#[derive(Clone, Debug, Serialize, Deserialize)] |
||||
pub enum Bootstrap { |
||||
V0(BootstrapV0), |
||||
} |
||||
|
||||
impl Bootstrap { |
||||
pub fn id(&self) -> BootstrapId { |
||||
match self { |
||||
Bootstrap::V0(v0) => v0.id, |
||||
} |
||||
} |
||||
pub fn content_as_bytes(&self) -> Vec<u8> { |
||||
match self { |
||||
Bootstrap::V0(v0) => serde_bare::to_vec(&v0.content).unwrap(), |
||||
} |
||||
} |
||||
pub fn sig(&self) -> Sig { |
||||