@authon/react-native-wallet 0.0.0-stage → 0.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +20 -0
- package/README.md +251 -2
- package/android/build.gradle +40 -0
- package/android/consumer-rules.pro +10 -0
- package/android/src/main/AndroidManifest.xml +8 -0
- package/android/src/main/java/dev/authon/reactnative/wallet/AuthonWalletModule.kt +235 -0
- package/android/src/vendor/GENERATED.md +4 -0
- package/android/src/vendor/kotlin/dev/authon/sdk/wallet/AndroidCapabilityProbe.kt +86 -0
- package/android/src/vendor/kotlin/dev/authon/sdk/wallet/AuthonWallet.kt +218 -0
- package/android/src/vendor/kotlin/dev/authon/sdk/wallet/Bitcoin.kt +296 -0
- package/android/src/vendor/kotlin/dev/authon/sdk/wallet/Bytes.kt +74 -0
- package/android/src/vendor/kotlin/dev/authon/sdk/wallet/Chains.kt +157 -0
- package/android/src/vendor/kotlin/dev/authon/sdk/wallet/CredentialManagerPasskeys.kt +192 -0
- package/android/src/vendor/kotlin/dev/authon/sdk/wallet/Der.kt +17 -0
- package/android/src/vendor/kotlin/dev/authon/sdk/wallet/DeviceStore.kt +170 -0
- package/android/src/vendor/kotlin/dev/authon/sdk/wallet/DialogWalletApprover.kt +141 -0
- package/android/src/vendor/kotlin/dev/authon/sdk/wallet/Eip712.kt +176 -0
- package/android/src/vendor/kotlin/dev/authon/sdk/wallet/Encodings.kt +133 -0
- package/android/src/vendor/kotlin/dev/authon/sdk/wallet/EvmAccount.kt +45 -0
- package/android/src/vendor/kotlin/dev/authon/sdk/wallet/EvmTransaction.kt +180 -0
- package/android/src/vendor/kotlin/dev/authon/sdk/wallet/GfTables.kt +44 -0
- package/android/src/vendor/kotlin/dev/authon/sdk/wallet/HdWallet.kt +130 -0
- package/android/src/vendor/kotlin/dev/authon/sdk/wallet/Http.kt +86 -0
- package/android/src/vendor/kotlin/dev/authon/sdk/wallet/JsValues.kt +83 -0
- package/android/src/vendor/kotlin/dev/authon/sdk/wallet/KeystoreDeviceStore.kt +236 -0
- package/android/src/vendor/kotlin/dev/authon/sdk/wallet/Prf.kt +111 -0
- package/android/src/vendor/kotlin/dev/authon/sdk/wallet/Proof.kt +134 -0
- package/android/src/vendor/kotlin/dev/authon/sdk/wallet/Shamir.kt +106 -0
- package/android/src/vendor/kotlin/dev/authon/sdk/wallet/SignSummary.kt +335 -0
- package/android/src/vendor/kotlin/dev/authon/sdk/wallet/Solana.kt +195 -0
- package/android/src/vendor/kotlin/dev/authon/sdk/wallet/Tron.kt +184 -0
- package/android/src/vendor/kotlin/dev/authon/sdk/wallet/WalletApi.kt +361 -0
- package/android/src/vendor/kotlin/dev/authon/sdk/wallet/WalletCapabilities.kt +91 -0
- package/android/src/vendor/kotlin/dev/authon/sdk/wallet/WalletError.kt +74 -0
- package/android/src/vendor/kotlin/dev/authon/sdk/wallet/WalletOps.kt +551 -0
- package/android/src/vendor/kotlin/dev/authon/sdk/wallet/WalletTypes.kt +78 -0
- package/android/src/vendor/kotlin/dev/authon/sdk/wallet/Xrp.kt +193 -0
- package/build/authonContext.d.ts +19 -0
- package/build/authonContext.d.ts.map +1 -0
- package/build/authonContext.js +20 -0
- package/build/authonContext.js.map +1 -0
- package/build/client.d.ts +92 -0
- package/build/client.d.ts.map +1 -0
- package/build/client.js +431 -0
- package/build/client.js.map +1 -0
- package/build/errors.d.ts +25 -0
- package/build/errors.d.ts.map +1 -0
- package/build/errors.js +15 -0
- package/build/errors.js.map +1 -0
- package/build/index.d.ts +7 -0
- package/build/index.d.ts.map +1 -0
- package/build/index.js +4 -0
- package/build/index.js.map +1 -0
- package/build/native.d.ts +43 -0
- package/build/native.d.ts.map +1 -0
- package/build/native.js +12 -0
- package/build/native.js.map +1 -0
- package/build/types.d.ts +167 -0
- package/build/types.d.ts.map +1 -0
- package/build/types.js +3 -0
- package/build/types.js.map +1 -0
- package/build/useAuthonWallet.d.ts +25 -0
- package/build/useAuthonWallet.d.ts.map +1 -0
- package/build/useAuthonWallet.js +77 -0
- package/build/useAuthonWallet.js.map +1 -0
- package/expo-module.config.json +9 -0
- package/ios/AuthonReactNativeWallet.podspec +41 -0
- package/ios/AuthonWalletModule.swift +233 -0
- package/ios/vendor/AuthonWallet/AuthonWallet.swift +232 -0
- package/ios/vendor/AuthonWallet/Capabilities.swift +149 -0
- package/ios/vendor/AuthonWallet/Chains/Bitcoin.swift +296 -0
- package/ios/vendor/AuthonWallet/Chains/Solana.swift +207 -0
- package/ios/vendor/AuthonWallet/Chains/Tron.swift +181 -0
- package/ios/vendor/AuthonWallet/Chains/XRP.swift +191 -0
- package/ios/vendor/AuthonWallet/Crypto/BIP39Wordlist.swift +262 -0
- package/ios/vendor/AuthonWallet/Crypto/Chains.swift +278 -0
- package/ios/vendor/AuthonWallet/Crypto/HDKey.swift +108 -0
- package/ios/vendor/AuthonWallet/Crypto/Secp256k1.swift +128 -0
- package/ios/vendor/AuthonWallet/Crypto/Shamir.swift +123 -0
- package/ios/vendor/AuthonWallet/EVM/Address.swift +57 -0
- package/ios/vendor/AuthonWallet/EVM/EvmAccount.swift +48 -0
- package/ios/vendor/AuthonWallet/EVM/Transaction.swift +165 -0
- package/ios/vendor/AuthonWallet/EVM/TypedData.swift +193 -0
- package/ios/vendor/AuthonWallet/Support/BigInteger.swift +220 -0
- package/ios/vendor/AuthonWallet/Support/Bytes.swift +89 -0
- package/ios/vendor/AuthonWallet/Support/JSONValue.swift +341 -0
- package/ios/vendor/AuthonWallet/UI/WalletApprover.swift +250 -0
- package/ios/vendor/AuthonWallet/Wallet/Backup.swift +69 -0
- package/ios/vendor/AuthonWallet/Wallet/DeviceStore.swift +351 -0
- package/ios/vendor/AuthonWallet/Wallet/Passkeys.swift +190 -0
- package/ios/vendor/AuthonWallet/Wallet/Proof.swift +143 -0
- package/ios/vendor/AuthonWallet/Wallet/Shares.swift +116 -0
- package/ios/vendor/AuthonWallet/Wallet/Summary.swift +342 -0
- package/ios/vendor/AuthonWallet/Wallet/WalletAPI.swift +361 -0
- package/ios/vendor/AuthonWallet/Wallet/WalletOps.swift +654 -0
- package/ios/vendor/AuthonWallet/WalletError.swift +84 -0
- package/ios/vendor/CKeccak/LICENSE +22 -0
- package/ios/vendor/CKeccak/README.md +30 -0
- package/ios/vendor/CKeccak/byte_order.h +59 -0
- package/ios/vendor/CKeccak/include/ckeccak.h +13 -0
- package/ios/vendor/CKeccak/memzero.c +75 -0
- package/ios/vendor/CKeccak/memzero.h +8 -0
- package/ios/vendor/CKeccak/options.h +99 -0
- package/ios/vendor/CKeccak/ripemd160.c +343 -0
- package/ios/vendor/CKeccak/ripemd160.h +22 -0
- package/ios/vendor/CKeccak/sha3.c +413 -0
- package/ios/vendor/CKeccak/sha3.h +89 -0
- package/ios/vendor/CMonocypher/LICENCE.md +173 -0
- package/ios/vendor/CMonocypher/README.md +27 -0
- package/ios/vendor/CMonocypher/include/monocypher-ed25519.h +140 -0
- package/ios/vendor/CMonocypher/include/monocypher.h +321 -0
- package/ios/vendor/CMonocypher/monocypher-ed25519.c +500 -0
- package/ios/vendor/CMonocypher/monocypher.c +2956 -0
- package/ios/vendor/CSecp256k1/COPYING +19 -0
- package/ios/vendor/CSecp256k1/README.md +35 -0
- package/ios/vendor/CSecp256k1/build/precomputed_ecmult.c +3 -0
- package/ios/vendor/CSecp256k1/build/precomputed_ecmult_gen.c +3 -0
- package/ios/vendor/CSecp256k1/build/secp256k1.c +3 -0
- package/ios/vendor/CSecp256k1/include/secp256k1.h +899 -0
- package/ios/vendor/CSecp256k1/include/secp256k1_preallocated.h +134 -0
- package/ios/vendor/CSecp256k1/include/secp256k1_recovery.h +113 -0
- package/ios/vendor/CSecp256k1/src/assumptions.h +87 -0
- package/ios/vendor/CSecp256k1/src/checkmem.h +102 -0
- package/ios/vendor/CSecp256k1/src/ecdsa.h +21 -0
- package/ios/vendor/CSecp256k1/src/ecdsa_impl.h +304 -0
- package/ios/vendor/CSecp256k1/src/eckey.h +25 -0
- package/ios/vendor/CSecp256k1/src/eckey_impl.h +92 -0
- package/ios/vendor/CSecp256k1/src/ecmult.h +61 -0
- package/ios/vendor/CSecp256k1/src/ecmult_const.h +38 -0
- package/ios/vendor/CSecp256k1/src/ecmult_const_impl.h +399 -0
- package/ios/vendor/CSecp256k1/src/ecmult_gen.h +143 -0
- package/ios/vendor/CSecp256k1/src/ecmult_gen_impl.h +341 -0
- package/ios/vendor/CSecp256k1/src/ecmult_impl.h +853 -0
- package/ios/vendor/CSecp256k1/src/field.h +350 -0
- package/ios/vendor/CSecp256k1/src/field_10x26.h +57 -0
- package/ios/vendor/CSecp256k1/src/field_10x26_impl.h +1232 -0
- package/ios/vendor/CSecp256k1/src/field_5x52.h +62 -0
- package/ios/vendor/CSecp256k1/src/field_5x52_impl.h +522 -0
- package/ios/vendor/CSecp256k1/src/field_5x52_int128_impl.h +274 -0
- package/ios/vendor/CSecp256k1/src/field_impl.h +457 -0
- package/ios/vendor/CSecp256k1/src/group.h +212 -0
- package/ios/vendor/CSecp256k1/src/group_impl.h +974 -0
- package/ios/vendor/CSecp256k1/src/hash.h +44 -0
- package/ios/vendor/CSecp256k1/src/hash_impl.h +299 -0
- package/ios/vendor/CSecp256k1/src/hsort.h +33 -0
- package/ios/vendor/CSecp256k1/src/hsort_impl.h +125 -0
- package/ios/vendor/CSecp256k1/src/int128.h +90 -0
- package/ios/vendor/CSecp256k1/src/int128_impl.h +18 -0
- package/ios/vendor/CSecp256k1/src/int128_native.h +19 -0
- package/ios/vendor/CSecp256k1/src/int128_native_impl.h +94 -0
- package/ios/vendor/CSecp256k1/src/int128_struct.h +14 -0
- package/ios/vendor/CSecp256k1/src/int128_struct_impl.h +205 -0
- package/ios/vendor/CSecp256k1/src/modinv32.h +43 -0
- package/ios/vendor/CSecp256k1/src/modinv32_impl.h +725 -0
- package/ios/vendor/CSecp256k1/src/modinv64.h +47 -0
- package/ios/vendor/CSecp256k1/src/modinv64_impl.h +780 -0
- package/ios/vendor/CSecp256k1/src/modules/recovery/main_impl.h +159 -0
- package/ios/vendor/CSecp256k1/src/precomputed_ecmult.c +16456 -0
- package/ios/vendor/CSecp256k1/src/precomputed_ecmult.h +38 -0
- package/ios/vendor/CSecp256k1/src/precomputed_ecmult_gen.c +1779 -0
- package/ios/vendor/CSecp256k1/src/precomputed_ecmult_gen.h +26 -0
- package/ios/vendor/CSecp256k1/src/scalar.h +105 -0
- package/ios/vendor/CSecp256k1/src/scalar_4x64.h +19 -0
- package/ios/vendor/CSecp256k1/src/scalar_4x64_impl.h +1000 -0
- package/ios/vendor/CSecp256k1/src/scalar_8x32.h +19 -0
- package/ios/vendor/CSecp256k1/src/scalar_8x32_impl.h +816 -0
- package/ios/vendor/CSecp256k1/src/scalar_impl.h +321 -0
- package/ios/vendor/CSecp256k1/src/scalar_low.h +24 -0
- package/ios/vendor/CSecp256k1/src/scalar_low_impl.h +206 -0
- package/ios/vendor/CSecp256k1/src/scratch.h +44 -0
- package/ios/vendor/CSecp256k1/src/scratch_impl.h +99 -0
- package/ios/vendor/CSecp256k1/src/secp256k1.c +831 -0
- package/ios/vendor/CSecp256k1/src/selftest.h +32 -0
- package/ios/vendor/CSecp256k1/src/util.h +451 -0
- package/ios/vendor/GENERATED.md +4 -0
- package/package.json +66 -3
- package/src/authonContext.ts +30 -0
- package/src/client.ts +459 -0
- package/src/errors.ts +58 -0
- package/src/index.ts +26 -0
- package/src/native.ts +52 -0
- package/src/types.ts +171 -0
- package/src/useAuthonWallet.ts +103 -0
|
@@ -0,0 +1,262 @@
|
|
|
1
|
+
// GENERATED by scripts/sync-native-wallet.mjs from swift/Sources/AuthonWallet/Crypto/BIP39Wordlist.swift. Do not edit: change the source and run the script.
|
|
2
|
+
// BIP39 English wordlist (https://github.com/bitcoin/bips/blob/master/bip-0039/english.txt).
|
|
3
|
+
// SHA-256 of english.txt: 2f5eed53a4727b4bf8880d8f3f199efc90e58503646d9ff8eff3a2ed3b24dbda
|
|
4
|
+
|
|
5
|
+
let bip39EnglishWordlist: [String] = [
|
|
6
|
+
"abandon", "ability", "able", "about", "above", "absent", "absorb", "abstract",
|
|
7
|
+
"absurd", "abuse", "access", "accident", "account", "accuse", "achieve", "acid",
|
|
8
|
+
"acoustic", "acquire", "across", "act", "action", "actor", "actress", "actual",
|
|
9
|
+
"adapt", "add", "addict", "address", "adjust", "admit", "adult", "advance",
|
|
10
|
+
"advice", "aerobic", "affair", "afford", "afraid", "again", "age", "agent",
|
|
11
|
+
"agree", "ahead", "aim", "air", "airport", "aisle", "alarm", "album",
|
|
12
|
+
"alcohol", "alert", "alien", "all", "alley", "allow", "almost", "alone",
|
|
13
|
+
"alpha", "already", "also", "alter", "always", "amateur", "amazing", "among",
|
|
14
|
+
"amount", "amused", "analyst", "anchor", "ancient", "anger", "angle", "angry",
|
|
15
|
+
"animal", "ankle", "announce", "annual", "another", "answer", "antenna", "antique",
|
|
16
|
+
"anxiety", "any", "apart", "apology", "appear", "apple", "approve", "april",
|
|
17
|
+
"arch", "arctic", "area", "arena", "argue", "arm", "armed", "armor",
|
|
18
|
+
"army", "around", "arrange", "arrest", "arrive", "arrow", "art", "artefact",
|
|
19
|
+
"artist", "artwork", "ask", "aspect", "assault", "asset", "assist", "assume",
|
|
20
|
+
"asthma", "athlete", "atom", "attack", "attend", "attitude", "attract", "auction",
|
|
21
|
+
"audit", "august", "aunt", "author", "auto", "autumn", "average", "avocado",
|
|
22
|
+
"avoid", "awake", "aware", "away", "awesome", "awful", "awkward", "axis",
|
|
23
|
+
"baby", "bachelor", "bacon", "badge", "bag", "balance", "balcony", "ball",
|
|
24
|
+
"bamboo", "banana", "banner", "bar", "barely", "bargain", "barrel", "base",
|
|
25
|
+
"basic", "basket", "battle", "beach", "bean", "beauty", "because", "become",
|
|
26
|
+
"beef", "before", "begin", "behave", "behind", "believe", "below", "belt",
|
|
27
|
+
"bench", "benefit", "best", "betray", "better", "between", "beyond", "bicycle",
|
|
28
|
+
"bid", "bike", "bind", "biology", "bird", "birth", "bitter", "black",
|
|
29
|
+
"blade", "blame", "blanket", "blast", "bleak", "bless", "blind", "blood",
|
|
30
|
+
"blossom", "blouse", "blue", "blur", "blush", "board", "boat", "body",
|
|
31
|
+
"boil", "bomb", "bone", "bonus", "book", "boost", "border", "boring",
|
|
32
|
+
"borrow", "boss", "bottom", "bounce", "box", "boy", "bracket", "brain",
|
|
33
|
+
"brand", "brass", "brave", "bread", "breeze", "brick", "bridge", "brief",
|
|
34
|
+
"bright", "bring", "brisk", "broccoli", "broken", "bronze", "broom", "brother",
|
|
35
|
+
"brown", "brush", "bubble", "buddy", "budget", "buffalo", "build", "bulb",
|
|
36
|
+
"bulk", "bullet", "bundle", "bunker", "burden", "burger", "burst", "bus",
|
|
37
|
+
"business", "busy", "butter", "buyer", "buzz", "cabbage", "cabin", "cable",
|
|
38
|
+
"cactus", "cage", "cake", "call", "calm", "camera", "camp", "can",
|
|
39
|
+
"canal", "cancel", "candy", "cannon", "canoe", "canvas", "canyon", "capable",
|
|
40
|
+
"capital", "captain", "car", "carbon", "card", "cargo", "carpet", "carry",
|
|
41
|
+
"cart", "case", "cash", "casino", "castle", "casual", "cat", "catalog",
|
|
42
|
+
"catch", "category", "cattle", "caught", "cause", "caution", "cave", "ceiling",
|
|
43
|
+
"celery", "cement", "census", "century", "cereal", "certain", "chair", "chalk",
|
|
44
|
+
"champion", "change", "chaos", "chapter", "charge", "chase", "chat", "cheap",
|
|
45
|
+
"check", "cheese", "chef", "cherry", "chest", "chicken", "chief", "child",
|
|
46
|
+
"chimney", "choice", "choose", "chronic", "chuckle", "chunk", "churn", "cigar",
|
|
47
|
+
"cinnamon", "circle", "citizen", "city", "civil", "claim", "clap", "clarify",
|
|
48
|
+
"claw", "clay", "clean", "clerk", "clever", "click", "client", "cliff",
|
|
49
|
+
"climb", "clinic", "clip", "clock", "clog", "close", "cloth", "cloud",
|
|
50
|
+
"clown", "club", "clump", "cluster", "clutch", "coach", "coast", "coconut",
|
|
51
|
+
"code", "coffee", "coil", "coin", "collect", "color", "column", "combine",
|
|
52
|
+
"come", "comfort", "comic", "common", "company", "concert", "conduct", "confirm",
|
|
53
|
+
"congress", "connect", "consider", "control", "convince", "cook", "cool", "copper",
|
|
54
|
+
"copy", "coral", "core", "corn", "correct", "cost", "cotton", "couch",
|
|
55
|
+
"country", "couple", "course", "cousin", "cover", "coyote", "crack", "cradle",
|
|
56
|
+
"craft", "cram", "crane", "crash", "crater", "crawl", "crazy", "cream",
|
|
57
|
+
"credit", "creek", "crew", "cricket", "crime", "crisp", "critic", "crop",
|
|
58
|
+
"cross", "crouch", "crowd", "crucial", "cruel", "cruise", "crumble", "crunch",
|
|
59
|
+
"crush", "cry", "crystal", "cube", "culture", "cup", "cupboard", "curious",
|
|
60
|
+
"current", "curtain", "curve", "cushion", "custom", "cute", "cycle", "dad",
|
|
61
|
+
"damage", "damp", "dance", "danger", "daring", "dash", "daughter", "dawn",
|
|
62
|
+
"day", "deal", "debate", "debris", "decade", "december", "decide", "decline",
|
|
63
|
+
"decorate", "decrease", "deer", "defense", "define", "defy", "degree", "delay",
|
|
64
|
+
"deliver", "demand", "demise", "denial", "dentist", "deny", "depart", "depend",
|
|
65
|
+
"deposit", "depth", "deputy", "derive", "describe", "desert", "design", "desk",
|
|
66
|
+
"despair", "destroy", "detail", "detect", "develop", "device", "devote", "diagram",
|
|
67
|
+
"dial", "diamond", "diary", "dice", "diesel", "diet", "differ", "digital",
|
|
68
|
+
"dignity", "dilemma", "dinner", "dinosaur", "direct", "dirt", "disagree", "discover",
|
|
69
|
+
"disease", "dish", "dismiss", "disorder", "display", "distance", "divert", "divide",
|
|
70
|
+
"divorce", "dizzy", "doctor", "document", "dog", "doll", "dolphin", "domain",
|
|
71
|
+
"donate", "donkey", "donor", "door", "dose", "double", "dove", "draft",
|
|
72
|
+
"dragon", "drama", "drastic", "draw", "dream", "dress", "drift", "drill",
|
|
73
|
+
"drink", "drip", "drive", "drop", "drum", "dry", "duck", "dumb",
|
|
74
|
+
"dune", "during", "dust", "dutch", "duty", "dwarf", "dynamic", "eager",
|
|
75
|
+
"eagle", "early", "earn", "earth", "easily", "east", "easy", "echo",
|
|
76
|
+
"ecology", "economy", "edge", "edit", "educate", "effort", "egg", "eight",
|
|
77
|
+
"either", "elbow", "elder", "electric", "elegant", "element", "elephant", "elevator",
|
|
78
|
+
"elite", "else", "embark", "embody", "embrace", "emerge", "emotion", "employ",
|
|
79
|
+
"empower", "empty", "enable", "enact", "end", "endless", "endorse", "enemy",
|
|
80
|
+
"energy", "enforce", "engage", "engine", "enhance", "enjoy", "enlist", "enough",
|
|
81
|
+
"enrich", "enroll", "ensure", "enter", "entire", "entry", "envelope", "episode",
|
|
82
|
+
"equal", "equip", "era", "erase", "erode", "erosion", "error", "erupt",
|
|
83
|
+
"escape", "essay", "essence", "estate", "eternal", "ethics", "evidence", "evil",
|
|
84
|
+
"evoke", "evolve", "exact", "example", "excess", "exchange", "excite", "exclude",
|
|
85
|
+
"excuse", "execute", "exercise", "exhaust", "exhibit", "exile", "exist", "exit",
|
|
86
|
+
"exotic", "expand", "expect", "expire", "explain", "expose", "express", "extend",
|
|
87
|
+
"extra", "eye", "eyebrow", "fabric", "face", "faculty", "fade", "faint",
|
|
88
|
+
"faith", "fall", "false", "fame", "family", "famous", "fan", "fancy",
|
|
89
|
+
"fantasy", "farm", "fashion", "fat", "fatal", "father", "fatigue", "fault",
|
|
90
|
+
"favorite", "feature", "february", "federal", "fee", "feed", "feel", "female",
|
|
91
|
+
"fence", "festival", "fetch", "fever", "few", "fiber", "fiction", "field",
|
|
92
|
+
"figure", "file", "film", "filter", "final", "find", "fine", "finger",
|
|
93
|
+
"finish", "fire", "firm", "first", "fiscal", "fish", "fit", "fitness",
|
|
94
|
+
"fix", "flag", "flame", "flash", "flat", "flavor", "flee", "flight",
|
|
95
|
+
"flip", "float", "flock", "floor", "flower", "fluid", "flush", "fly",
|
|
96
|
+
"foam", "focus", "fog", "foil", "fold", "follow", "food", "foot",
|
|
97
|
+
"force", "forest", "forget", "fork", "fortune", "forum", "forward", "fossil",
|
|
98
|
+
"foster", "found", "fox", "fragile", "frame", "frequent", "fresh", "friend",
|
|
99
|
+
"fringe", "frog", "front", "frost", "frown", "frozen", "fruit", "fuel",
|
|
100
|
+
"fun", "funny", "furnace", "fury", "future", "gadget", "gain", "galaxy",
|
|
101
|
+
"gallery", "game", "gap", "garage", "garbage", "garden", "garlic", "garment",
|
|
102
|
+
"gas", "gasp", "gate", "gather", "gauge", "gaze", "general", "genius",
|
|
103
|
+
"genre", "gentle", "genuine", "gesture", "ghost", "giant", "gift", "giggle",
|
|
104
|
+
"ginger", "giraffe", "girl", "give", "glad", "glance", "glare", "glass",
|
|
105
|
+
"glide", "glimpse", "globe", "gloom", "glory", "glove", "glow", "glue",
|
|
106
|
+
"goat", "goddess", "gold", "good", "goose", "gorilla", "gospel", "gossip",
|
|
107
|
+
"govern", "gown", "grab", "grace", "grain", "grant", "grape", "grass",
|
|
108
|
+
"gravity", "great", "green", "grid", "grief", "grit", "grocery", "group",
|
|
109
|
+
"grow", "grunt", "guard", "guess", "guide", "guilt", "guitar", "gun",
|
|
110
|
+
"gym", "habit", "hair", "half", "hammer", "hamster", "hand", "happy",
|
|
111
|
+
"harbor", "hard", "harsh", "harvest", "hat", "have", "hawk", "hazard",
|
|
112
|
+
"head", "health", "heart", "heavy", "hedgehog", "height", "hello", "helmet",
|
|
113
|
+
"help", "hen", "hero", "hidden", "high", "hill", "hint", "hip",
|
|
114
|
+
"hire", "history", "hobby", "hockey", "hold", "hole", "holiday", "hollow",
|
|
115
|
+
"home", "honey", "hood", "hope", "horn", "horror", "horse", "hospital",
|
|
116
|
+
"host", "hotel", "hour", "hover", "hub", "huge", "human", "humble",
|
|
117
|
+
"humor", "hundred", "hungry", "hunt", "hurdle", "hurry", "hurt", "husband",
|
|
118
|
+
"hybrid", "ice", "icon", "idea", "identify", "idle", "ignore", "ill",
|
|
119
|
+
"illegal", "illness", "image", "imitate", "immense", "immune", "impact", "impose",
|
|
120
|
+
"improve", "impulse", "inch", "include", "income", "increase", "index", "indicate",
|
|
121
|
+
"indoor", "industry", "infant", "inflict", "inform", "inhale", "inherit", "initial",
|
|
122
|
+
"inject", "injury", "inmate", "inner", "innocent", "input", "inquiry", "insane",
|
|
123
|
+
"insect", "inside", "inspire", "install", "intact", "interest", "into", "invest",
|
|
124
|
+
"invite", "involve", "iron", "island", "isolate", "issue", "item", "ivory",
|
|
125
|
+
"jacket", "jaguar", "jar", "jazz", "jealous", "jeans", "jelly", "jewel",
|
|
126
|
+
"job", "join", "joke", "journey", "joy", "judge", "juice", "jump",
|
|
127
|
+
"jungle", "junior", "junk", "just", "kangaroo", "keen", "keep", "ketchup",
|
|
128
|
+
"key", "kick", "kid", "kidney", "kind", "kingdom", "kiss", "kit",
|
|
129
|
+
"kitchen", "kite", "kitten", "kiwi", "knee", "knife", "knock", "know",
|
|
130
|
+
"lab", "label", "labor", "ladder", "lady", "lake", "lamp", "language",
|
|
131
|
+
"laptop", "large", "later", "latin", "laugh", "laundry", "lava", "law",
|
|
132
|
+
"lawn", "lawsuit", "layer", "lazy", "leader", "leaf", "learn", "leave",
|
|
133
|
+
"lecture", "left", "leg", "legal", "legend", "leisure", "lemon", "lend",
|
|
134
|
+
"length", "lens", "leopard", "lesson", "letter", "level", "liar", "liberty",
|
|
135
|
+
"library", "license", "life", "lift", "light", "like", "limb", "limit",
|
|
136
|
+
"link", "lion", "liquid", "list", "little", "live", "lizard", "load",
|
|
137
|
+
"loan", "lobster", "local", "lock", "logic", "lonely", "long", "loop",
|
|
138
|
+
"lottery", "loud", "lounge", "love", "loyal", "lucky", "luggage", "lumber",
|
|
139
|
+
"lunar", "lunch", "luxury", "lyrics", "machine", "mad", "magic", "magnet",
|
|
140
|
+
"maid", "mail", "main", "major", "make", "mammal", "man", "manage",
|
|
141
|
+
"mandate", "mango", "mansion", "manual", "maple", "marble", "march", "margin",
|
|
142
|
+
"marine", "market", "marriage", "mask", "mass", "master", "match", "material",
|
|
143
|
+
"math", "matrix", "matter", "maximum", "maze", "meadow", "mean", "measure",
|
|
144
|
+
"meat", "mechanic", "medal", "media", "melody", "melt", "member", "memory",
|
|
145
|
+
"mention", "menu", "mercy", "merge", "merit", "merry", "mesh", "message",
|
|
146
|
+
"metal", "method", "middle", "midnight", "milk", "million", "mimic", "mind",
|
|
147
|
+
"minimum", "minor", "minute", "miracle", "mirror", "misery", "miss", "mistake",
|
|
148
|
+
"mix", "mixed", "mixture", "mobile", "model", "modify", "mom", "moment",
|
|
149
|
+
"monitor", "monkey", "monster", "month", "moon", "moral", "more", "morning",
|
|
150
|
+
"mosquito", "mother", "motion", "motor", "mountain", "mouse", "move", "movie",
|
|
151
|
+
"much", "muffin", "mule", "multiply", "muscle", "museum", "mushroom", "music",
|
|
152
|
+
"must", "mutual", "myself", "mystery", "myth", "naive", "name", "napkin",
|
|
153
|
+
"narrow", "nasty", "nation", "nature", "near", "neck", "need", "negative",
|
|
154
|
+
"neglect", "neither", "nephew", "nerve", "nest", "net", "network", "neutral",
|
|
155
|
+
"never", "news", "next", "nice", "night", "noble", "noise", "nominee",
|
|
156
|
+
"noodle", "normal", "north", "nose", "notable", "note", "nothing", "notice",
|
|
157
|
+
"novel", "now", "nuclear", "number", "nurse", "nut", "oak", "obey",
|
|
158
|
+
"object", "oblige", "obscure", "observe", "obtain", "obvious", "occur", "ocean",
|
|
159
|
+
"october", "odor", "off", "offer", "office", "often", "oil", "okay",
|
|
160
|
+
"old", "olive", "olympic", "omit", "once", "one", "onion", "online",
|
|
161
|
+
"only", "open", "opera", "opinion", "oppose", "option", "orange", "orbit",
|
|
162
|
+
"orchard", "order", "ordinary", "organ", "orient", "original", "orphan", "ostrich",
|
|
163
|
+
"other", "outdoor", "outer", "output", "outside", "oval", "oven", "over",
|
|
164
|
+
"own", "owner", "oxygen", "oyster", "ozone", "pact", "paddle", "page",
|
|
165
|
+
"pair", "palace", "palm", "panda", "panel", "panic", "panther", "paper",
|
|
166
|
+
"parade", "parent", "park", "parrot", "party", "pass", "patch", "path",
|
|
167
|
+
"patient", "patrol", "pattern", "pause", "pave", "payment", "peace", "peanut",
|
|
168
|
+
"pear", "peasant", "pelican", "pen", "penalty", "pencil", "people", "pepper",
|
|
169
|
+
"perfect", "permit", "person", "pet", "phone", "photo", "phrase", "physical",
|
|
170
|
+
"piano", "picnic", "picture", "piece", "pig", "pigeon", "pill", "pilot",
|
|
171
|
+
"pink", "pioneer", "pipe", "pistol", "pitch", "pizza", "place", "planet",
|
|
172
|
+
"plastic", "plate", "play", "please", "pledge", "pluck", "plug", "plunge",
|
|
173
|
+
"poem", "poet", "point", "polar", "pole", "police", "pond", "pony",
|
|
174
|
+
"pool", "popular", "portion", "position", "possible", "post", "potato", "pottery",
|
|
175
|
+
"poverty", "powder", "power", "practice", "praise", "predict", "prefer", "prepare",
|
|
176
|
+
"present", "pretty", "prevent", "price", "pride", "primary", "print", "priority",
|
|
177
|
+
"prison", "private", "prize", "problem", "process", "produce", "profit", "program",
|
|
178
|
+
"project", "promote", "proof", "property", "prosper", "protect", "proud", "provide",
|
|
179
|
+
"public", "pudding", "pull", "pulp", "pulse", "pumpkin", "punch", "pupil",
|
|
180
|
+
"puppy", "purchase", "purity", "purpose", "purse", "push", "put", "puzzle",
|
|
181
|
+
"pyramid", "quality", "quantum", "quarter", "question", "quick", "quit", "quiz",
|
|
182
|
+
"quote", "rabbit", "raccoon", "race", "rack", "radar", "radio", "rail",
|
|
183
|
+
"rain", "raise", "rally", "ramp", "ranch", "random", "range", "rapid",
|
|
184
|
+
"rare", "rate", "rather", "raven", "raw", "razor", "ready", "real",
|
|
185
|
+
"reason", "rebel", "rebuild", "recall", "receive", "recipe", "record", "recycle",
|
|
186
|
+
"reduce", "reflect", "reform", "refuse", "region", "regret", "regular", "reject",
|
|
187
|
+
"relax", "release", "relief", "rely", "remain", "remember", "remind", "remove",
|
|
188
|
+
"render", "renew", "rent", "reopen", "repair", "repeat", "replace", "report",
|
|
189
|
+
"require", "rescue", "resemble", "resist", "resource", "response", "result", "retire",
|
|
190
|
+
"retreat", "return", "reunion", "reveal", "review", "reward", "rhythm", "rib",
|
|
191
|
+
"ribbon", "rice", "rich", "ride", "ridge", "rifle", "right", "rigid",
|
|
192
|
+
"ring", "riot", "ripple", "risk", "ritual", "rival", "river", "road",
|
|
193
|
+
"roast", "robot", "robust", "rocket", "romance", "roof", "rookie", "room",
|
|
194
|
+
"rose", "rotate", "rough", "round", "route", "royal", "rubber", "rude",
|
|
195
|
+
"rug", "rule", "run", "runway", "rural", "sad", "saddle", "sadness",
|
|
196
|
+
"safe", "sail", "salad", "salmon", "salon", "salt", "salute", "same",
|
|
197
|
+
"sample", "sand", "satisfy", "satoshi", "sauce", "sausage", "save", "say",
|
|
198
|
+
"scale", "scan", "scare", "scatter", "scene", "scheme", "school", "science",
|
|
199
|
+
"scissors", "scorpion", "scout", "scrap", "screen", "script", "scrub", "sea",
|
|
200
|
+
"search", "season", "seat", "second", "secret", "section", "security", "seed",
|
|
201
|
+
"seek", "segment", "select", "sell", "seminar", "senior", "sense", "sentence",
|
|
202
|
+
"series", "service", "session", "settle", "setup", "seven", "shadow", "shaft",
|
|
203
|
+
"shallow", "share", "shed", "shell", "sheriff", "shield", "shift", "shine",
|
|
204
|
+
"ship", "shiver", "shock", "shoe", "shoot", "shop", "short", "shoulder",
|
|
205
|
+
"shove", "shrimp", "shrug", "shuffle", "shy", "sibling", "sick", "side",
|
|
206
|
+
"siege", "sight", "sign", "silent", "silk", "silly", "silver", "similar",
|
|
207
|
+
"simple", "since", "sing", "siren", "sister", "situate", "six", "size",
|
|
208
|
+
"skate", "sketch", "ski", "skill", "skin", "skirt", "skull", "slab",
|
|
209
|
+
"slam", "sleep", "slender", "slice", "slide", "slight", "slim", "slogan",
|
|
210
|
+
"slot", "slow", "slush", "small", "smart", "smile", "smoke", "smooth",
|
|
211
|
+
"snack", "snake", "snap", "sniff", "snow", "soap", "soccer", "social",
|
|
212
|
+
"sock", "soda", "soft", "solar", "soldier", "solid", "solution", "solve",
|
|
213
|
+
"someone", "song", "soon", "sorry", "sort", "soul", "sound", "soup",
|
|
214
|
+
"source", "south", "space", "spare", "spatial", "spawn", "speak", "special",
|
|
215
|
+
"speed", "spell", "spend", "sphere", "spice", "spider", "spike", "spin",
|
|
216
|
+
"spirit", "split", "spoil", "sponsor", "spoon", "sport", "spot", "spray",
|
|
217
|
+
"spread", "spring", "spy", "square", "squeeze", "squirrel", "stable", "stadium",
|
|
218
|
+
"staff", "stage", "stairs", "stamp", "stand", "start", "state", "stay",
|
|
219
|
+
"steak", "steel", "stem", "step", "stereo", "stick", "still", "sting",
|
|
220
|
+
"stock", "stomach", "stone", "stool", "story", "stove", "strategy", "street",
|
|
221
|
+
"strike", "strong", "struggle", "student", "stuff", "stumble", "style", "subject",
|
|
222
|
+
"submit", "subway", "success", "such", "sudden", "suffer", "sugar", "suggest",
|
|
223
|
+
"suit", "summer", "sun", "sunny", "sunset", "super", "supply", "supreme",
|
|
224
|
+
"sure", "surface", "surge", "surprise", "surround", "survey", "suspect", "sustain",
|
|
225
|
+
"swallow", "swamp", "swap", "swarm", "swear", "sweet", "swift", "swim",
|
|
226
|
+
"swing", "switch", "sword", "symbol", "symptom", "syrup", "system", "table",
|
|
227
|
+
"tackle", "tag", "tail", "talent", "talk", "tank", "tape", "target",
|
|
228
|
+
"task", "taste", "tattoo", "taxi", "teach", "team", "tell", "ten",
|
|
229
|
+
"tenant", "tennis", "tent", "term", "test", "text", "thank", "that",
|
|
230
|
+
"theme", "then", "theory", "there", "they", "thing", "this", "thought",
|
|
231
|
+
"three", "thrive", "throw", "thumb", "thunder", "ticket", "tide", "tiger",
|
|
232
|
+
"tilt", "timber", "time", "tiny", "tip", "tired", "tissue", "title",
|
|
233
|
+
"toast", "tobacco", "today", "toddler", "toe", "together", "toilet", "token",
|
|
234
|
+
"tomato", "tomorrow", "tone", "tongue", "tonight", "tool", "tooth", "top",
|
|
235
|
+
"topic", "topple", "torch", "tornado", "tortoise", "toss", "total", "tourist",
|
|
236
|
+
"toward", "tower", "town", "toy", "track", "trade", "traffic", "tragic",
|
|
237
|
+
"train", "transfer", "trap", "trash", "travel", "tray", "treat", "tree",
|
|
238
|
+
"trend", "trial", "tribe", "trick", "trigger", "trim", "trip", "trophy",
|
|
239
|
+
"trouble", "truck", "true", "truly", "trumpet", "trust", "truth", "try",
|
|
240
|
+
"tube", "tuition", "tumble", "tuna", "tunnel", "turkey", "turn", "turtle",
|
|
241
|
+
"twelve", "twenty", "twice", "twin", "twist", "two", "type", "typical",
|
|
242
|
+
"ugly", "umbrella", "unable", "unaware", "uncle", "uncover", "under", "undo",
|
|
243
|
+
"unfair", "unfold", "unhappy", "uniform", "unique", "unit", "universe", "unknown",
|
|
244
|
+
"unlock", "until", "unusual", "unveil", "update", "upgrade", "uphold", "upon",
|
|
245
|
+
"upper", "upset", "urban", "urge", "usage", "use", "used", "useful",
|
|
246
|
+
"useless", "usual", "utility", "vacant", "vacuum", "vague", "valid", "valley",
|
|
247
|
+
"valve", "van", "vanish", "vapor", "various", "vast", "vault", "vehicle",
|
|
248
|
+
"velvet", "vendor", "venture", "venue", "verb", "verify", "version", "very",
|
|
249
|
+
"vessel", "veteran", "viable", "vibrant", "vicious", "victory", "video", "view",
|
|
250
|
+
"village", "vintage", "violin", "virtual", "virus", "visa", "visit", "visual",
|
|
251
|
+
"vital", "vivid", "vocal", "voice", "void", "volcano", "volume", "vote",
|
|
252
|
+
"voyage", "wage", "wagon", "wait", "walk", "wall", "walnut", "want",
|
|
253
|
+
"warfare", "warm", "warrior", "wash", "wasp", "waste", "water", "wave",
|
|
254
|
+
"way", "wealth", "weapon", "wear", "weasel", "weather", "web", "wedding",
|
|
255
|
+
"weekend", "weird", "welcome", "west", "wet", "whale", "what", "wheat",
|
|
256
|
+
"wheel", "when", "where", "whip", "whisper", "wide", "width", "wife",
|
|
257
|
+
"wild", "will", "win", "window", "wine", "wing", "wink", "winner",
|
|
258
|
+
"winter", "wire", "wisdom", "wise", "wish", "witness", "wolf", "woman",
|
|
259
|
+
"wonder", "wood", "wool", "word", "work", "world", "worry", "worth",
|
|
260
|
+
"wrap", "wreck", "wrestle", "wrist", "write", "wrong", "yard", "year",
|
|
261
|
+
"yellow", "you", "young", "youth", "zebra", "zero", "zone", "zoo",
|
|
262
|
+
]
|
|
@@ -0,0 +1,278 @@
|
|
|
1
|
+
// GENERATED by scripts/sync-native-wallet.mjs from swift/Sources/AuthonWallet/Crypto/Chains.swift. Do not edit: change the source and run the script.
|
|
2
|
+
#if canImport(CKeccak)
|
|
3
|
+
import CKeccak
|
|
4
|
+
#endif
|
|
5
|
+
import CryptoKit
|
|
6
|
+
import Foundation
|
|
7
|
+
|
|
8
|
+
/// Chains a wallet derives addresses for (docs/wallet/NATIVE.md section 11, `apps/wallet/src/chains.ts`).
|
|
9
|
+
/// Paths match standard wallets, so the same seed gives the same addresses everywhere.
|
|
10
|
+
/// Signing is EVM only for now.
|
|
11
|
+
public enum WalletChain: String, CaseIterable, Sendable {
|
|
12
|
+
case evm
|
|
13
|
+
case tron
|
|
14
|
+
case xrp
|
|
15
|
+
case bitcoin
|
|
16
|
+
case bitcoinTestnet = "bitcoin-testnet"
|
|
17
|
+
case solana
|
|
18
|
+
|
|
19
|
+
public func path(_ index: Int) -> String {
|
|
20
|
+
switch self {
|
|
21
|
+
case .evm: return "m/44'/60'/0'/0/\(index)"
|
|
22
|
+
case .tron: return "m/44'/195'/\(index)'/0/0"
|
|
23
|
+
case .xrp: return "m/44'/144'/\(index)'/0/0"
|
|
24
|
+
case .bitcoin: return "m/84'/0'/\(index)'/0/0"
|
|
25
|
+
case .bitcoinTestnet: return "m/84'/1'/\(index)'/0/0"
|
|
26
|
+
case .solana: return "m/44'/501'/\(index)'/0'"
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
enum ChainAddresses {
|
|
32
|
+
static func ripemd(_ data: [UInt8]) -> [UInt8] {
|
|
33
|
+
var out = [UInt8](repeating: 0, count: 20)
|
|
34
|
+
data.withUnsafeBufferPointer { input in
|
|
35
|
+
out.withUnsafeMutableBufferPointer { ripemd160(input.baseAddress, UInt32(input.count), $0.baseAddress) }
|
|
36
|
+
}
|
|
37
|
+
return out
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
static func hash160(_ data: [UInt8]) -> [UInt8] { ripemd(Bytes.sha256(data)) }
|
|
41
|
+
|
|
42
|
+
static func checksum4(_ payload: [UInt8]) -> [UInt8] { Array(Bytes.sha256(Bytes.sha256(payload))[0..<4]) }
|
|
43
|
+
|
|
44
|
+
/// Address of a secp256k1 key on a non-Solana chain.
|
|
45
|
+
static func secpAddress(_ chain: WalletChain, privateKey: [UInt8]) throws -> String {
|
|
46
|
+
switch chain {
|
|
47
|
+
case .evm:
|
|
48
|
+
return try EvmAddress.of(privateKey: privateKey)
|
|
49
|
+
case .tron:
|
|
50
|
+
let uncompressed = try Secp256k1.publicKey(of: privateKey, compressed: false)
|
|
51
|
+
let payload = [0x41] + Array(Keccak.hash256(Array(uncompressed.dropFirst()))[12..<32])
|
|
52
|
+
return Base58.encode(payload + checksum4(payload), alphabet: Base58.bitcoin)
|
|
53
|
+
case .xrp:
|
|
54
|
+
let payload = [0x00] + hash160(try Secp256k1.publicKey(of: privateKey, compressed: true))
|
|
55
|
+
return Base58.encode(payload + checksum4(payload), alphabet: Base58.xrp)
|
|
56
|
+
case .bitcoin, .bitcoinTestnet:
|
|
57
|
+
let program = hash160(try Secp256k1.publicKey(of: privateKey, compressed: true))
|
|
58
|
+
return Bech32.segwitAddress(hrp: chain == .bitcoin ? "bc" : "tb", version: 0, program: program)
|
|
59
|
+
case .solana:
|
|
60
|
+
throw WalletError(.internal, "solana is not a secp256k1 chain")
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
/// secp256k1 key of account `index` on a BIP32 chain other than EVM. Callers wipe it.
|
|
65
|
+
static func secpPrivateKey(_ secret: [UInt8], chain: WalletChain, index: Int) throws -> [UInt8] {
|
|
66
|
+
guard chain != .solana, chain != .evm else { throw WalletError(.internal, "not a BIP32 chain") }
|
|
67
|
+
guard WalletShares.isAccountIndex(index) else { throw WalletError(.invalidRequest, "invalid account index") }
|
|
68
|
+
guard WalletShares.isHdSecret(secret) else { throw WalletError(.accountUnavailable, "this wallet has only EVM account 0") }
|
|
69
|
+
var seed = try BIP39.seed(mnemonic: try BIP39.mnemonic(entropy: secret))
|
|
70
|
+
defer { seed.wipe() }
|
|
71
|
+
var root = try HDNode(seed: seed)
|
|
72
|
+
defer { root.wipe() }
|
|
73
|
+
var node = try root.derive(chain.path(index))
|
|
74
|
+
defer { node.wipe() }
|
|
75
|
+
return node.key
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
/// SLIP-0010 ed25519 derivation; every level is hardened. Callers wipe the 32-byte key.
|
|
79
|
+
static func ed25519Key(seed: [UInt8], path: String) throws -> [UInt8] {
|
|
80
|
+
func hmac(_ key: [UInt8], _ data: [UInt8]) -> [UInt8] {
|
|
81
|
+
Array(HMAC<SHA512>.authenticationCode(for: data, using: SymmetricKey(data: key)))
|
|
82
|
+
}
|
|
83
|
+
var i = hmac(Array("ed25519 seed".utf8), seed)
|
|
84
|
+
var key = Array(i[0..<32])
|
|
85
|
+
var code = Array(i[32..<64])
|
|
86
|
+
defer {
|
|
87
|
+
i.wipe()
|
|
88
|
+
code.wipe()
|
|
89
|
+
}
|
|
90
|
+
for part in path.split(separator: "/").dropFirst() {
|
|
91
|
+
guard part.hasSuffix("'"), let n = UInt32(part.dropLast()), n < HDNode.hardened else {
|
|
92
|
+
key.wipe()
|
|
93
|
+
throw WalletError(.internal, "ed25519 paths are hardened only")
|
|
94
|
+
}
|
|
95
|
+
let index = n + HDNode.hardened
|
|
96
|
+
var data = [0] + key + [UInt8(index >> 24), UInt8(truncatingIfNeeded: index >> 16), UInt8(truncatingIfNeeded: index >> 8), UInt8(truncatingIfNeeded: index)]
|
|
97
|
+
i.wipe()
|
|
98
|
+
i = hmac(code, data)
|
|
99
|
+
data.wipe()
|
|
100
|
+
key.wipe()
|
|
101
|
+
code.wipe()
|
|
102
|
+
key = Array(i[0..<32])
|
|
103
|
+
code = Array(i[32..<64])
|
|
104
|
+
}
|
|
105
|
+
return key
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
static func solanaAddress(seed: [UInt8], index: Int) throws -> String {
|
|
109
|
+
var key = try ed25519Key(seed: seed, path: WalletChain.solana.path(index))
|
|
110
|
+
defer { key.wipe() }
|
|
111
|
+
let pub = try Curve25519.Signing.PrivateKey(rawRepresentation: key).publicKey.rawRepresentation
|
|
112
|
+
return Base58.encode(Array(pub), alphabet: Base58.bitcoin)
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
/// Addresses of accounts start..<start+count on `chain`. Only HD (BIP39) wallets have chains other than EVM.
|
|
116
|
+
static func addresses(_ secret: [UInt8], chain: WalletChain, start: Int, count: Int) throws -> [String] {
|
|
117
|
+
guard WalletShares.isAccountIndex(start), count >= 1, WalletShares.isAccountIndex(start + count - 1) else {
|
|
118
|
+
throw WalletError(.invalidRequest, "invalid account range")
|
|
119
|
+
}
|
|
120
|
+
if chain == .evm { return try WalletShares.addresses(secret, start: start, count: count) }
|
|
121
|
+
guard WalletShares.isHdSecret(secret) else { throw WalletError(.accountUnavailable, "this wallet has only EVM account 0") }
|
|
122
|
+
var seed = try BIP39.seed(mnemonic: try BIP39.mnemonic(entropy: secret))
|
|
123
|
+
defer { seed.wipe() }
|
|
124
|
+
var out = [String]()
|
|
125
|
+
out.reserveCapacity(count)
|
|
126
|
+
if chain == .solana {
|
|
127
|
+
for i in start..<(start + count) { out.append(try solanaAddress(seed: seed, index: i)) }
|
|
128
|
+
return out
|
|
129
|
+
}
|
|
130
|
+
var root = try HDNode(seed: seed)
|
|
131
|
+
defer { root.wipe() }
|
|
132
|
+
for i in start..<(start + count) {
|
|
133
|
+
var node = try root.derive(chain.path(i))
|
|
134
|
+
defer { node.wipe() }
|
|
135
|
+
out.append(try secpAddress(chain, privateKey: node.key))
|
|
136
|
+
}
|
|
137
|
+
return out
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
/// Compressed public keys (uppercase hex) of XRP accounts start..<start+count (the SigningPubKey apps need).
|
|
141
|
+
static func xrpPublicKeys(_ secret: [UInt8], start: Int, count: Int) throws -> [String] {
|
|
142
|
+
guard WalletShares.isHdSecret(secret) else { throw WalletError(.accountUnavailable, "this wallet has only EVM account 0") }
|
|
143
|
+
var seed = try BIP39.seed(mnemonic: try BIP39.mnemonic(entropy: secret))
|
|
144
|
+
defer { seed.wipe() }
|
|
145
|
+
var root = try HDNode(seed: seed)
|
|
146
|
+
defer { root.wipe() }
|
|
147
|
+
return try (start..<(start + count)).map { i in
|
|
148
|
+
var node = try root.derive(WalletChain.xrp.path(i))
|
|
149
|
+
defer { node.wipe() }
|
|
150
|
+
return Bytes.hex(try Secp256k1.publicKey(of: node.key, compressed: true)).uppercased()
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
/// Base58 (Bitcoin and XRP alphabets).
|
|
156
|
+
enum Base58 {
|
|
157
|
+
static let bitcoin = Array("123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz".utf8)
|
|
158
|
+
static let xrp = Array("rpshnaf39wBUDNEGHJKLM4PQRST7VWXYZ2bcdeCg65jkm8oFqi1tuvAxyz".utf8)
|
|
159
|
+
|
|
160
|
+
static func encode(_ bytes: [UInt8], alphabet: [UInt8]) -> String {
|
|
161
|
+
let zeros = bytes.prefix { $0 == 0 }.count
|
|
162
|
+
var digits = [UInt8]() // little-endian base-58 digits
|
|
163
|
+
for byte in bytes[zeros...] {
|
|
164
|
+
var carry = Int(byte)
|
|
165
|
+
for j in 0..<digits.count {
|
|
166
|
+
carry += Int(digits[j]) << 8
|
|
167
|
+
digits[j] = UInt8(carry % 58)
|
|
168
|
+
carry /= 58
|
|
169
|
+
}
|
|
170
|
+
while carry > 0 {
|
|
171
|
+
digits.append(UInt8(carry % 58))
|
|
172
|
+
carry /= 58
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
let out = [UInt8](repeating: alphabet[0], count: zeros) + digits.reversed().map { alphabet[Int($0)] }
|
|
176
|
+
return String(decoding: out, as: UTF8.self)
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
static func decode(_ text: String, alphabet: [UInt8]) -> [UInt8]? {
|
|
180
|
+
let chars = Array(text.utf8)
|
|
181
|
+
let zeros = chars.prefix { $0 == alphabet[0] }.count
|
|
182
|
+
var bytes = [UInt8]() // little-endian base-256
|
|
183
|
+
for c in chars[zeros...] {
|
|
184
|
+
guard let value = alphabet.firstIndex(of: c) else { return nil }
|
|
185
|
+
var carry = value
|
|
186
|
+
for j in 0..<bytes.count {
|
|
187
|
+
carry += Int(bytes[j]) * 58
|
|
188
|
+
bytes[j] = UInt8(carry & 0xff)
|
|
189
|
+
carry >>= 8
|
|
190
|
+
}
|
|
191
|
+
while carry > 0 {
|
|
192
|
+
bytes.append(UInt8(carry & 0xff))
|
|
193
|
+
carry >>= 8
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
return [UInt8](repeating: 0, count: zeros) + bytes.reversed()
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
/// Bech32 (BIP173) for SegWit v0 addresses.
|
|
201
|
+
enum Bech32 {
|
|
202
|
+
static let charset = Array("qpzry9x8gf2tvdw0s3jn54khce6mua7l".utf8)
|
|
203
|
+
private static let generator: [UInt32] = [0x3b6a57b2, 0x26508e6d, 0x1ea119fa, 0x3d4233dd, 0x2a1462b3]
|
|
204
|
+
|
|
205
|
+
private static func polymod(_ values: [UInt8]) -> UInt32 {
|
|
206
|
+
var chk: UInt32 = 1
|
|
207
|
+
for v in values {
|
|
208
|
+
let top = chk >> 25
|
|
209
|
+
chk = (chk & 0x1ffffff) << 5 ^ UInt32(v)
|
|
210
|
+
for i in 0..<5 where (top >> UInt32(i)) & 1 == 1 { chk ^= generator[i] }
|
|
211
|
+
}
|
|
212
|
+
return chk
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
private static func hrpExpand(_ hrp: [UInt8]) -> [UInt8] {
|
|
216
|
+
hrp.map { $0 >> 5 } + [0] + hrp.map { $0 & 31 }
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
/// Bech32 (BIP173) or, with `m`, Bech32m (BIP350, SegWit v1+).
|
|
220
|
+
static func encode(hrp: String, data: [UInt8], m: Bool = false) -> String {
|
|
221
|
+
let h = Array(hrp.lowercased().utf8)
|
|
222
|
+
let mod = polymod(hrpExpand(h) + data + [0, 0, 0, 0, 0, 0]) ^ (m ? 0x2bc8_30a3 : 1)
|
|
223
|
+
let checksum = (0..<6).map { UInt8((mod >> UInt32(5 * (5 - $0))) & 31) }
|
|
224
|
+
return String(decoding: h + [UInt8(ascii: "1")] + (data + checksum).map { charset[Int($0)] }, as: UTF8.self)
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
/// (hrp, 5-bit data without checksum), or nil for an invalid string.
|
|
228
|
+
static func decode(_ text: String) -> (hrp: String, data: [UInt8])? {
|
|
229
|
+
let bytes = Array(text.utf8)
|
|
230
|
+
guard bytes.count <= 90, bytes.allSatisfy({ $0 >= 33 && $0 <= 126 }) else { return nil }
|
|
231
|
+
let lower = text.lowercased(), upper = text.uppercased()
|
|
232
|
+
guard text == lower || text == upper else { return nil }
|
|
233
|
+
let chars = Array(lower.utf8)
|
|
234
|
+
guard let sep = chars.lastIndex(of: UInt8(ascii: "1")), sep >= 1, sep + 7 <= chars.count else { return nil }
|
|
235
|
+
let hrp = Array(chars[0..<sep])
|
|
236
|
+
var data = [UInt8]()
|
|
237
|
+
for c in chars[(sep + 1)...] {
|
|
238
|
+
guard let v = charset.firstIndex(of: c) else { return nil }
|
|
239
|
+
data.append(UInt8(v))
|
|
240
|
+
}
|
|
241
|
+
guard polymod(hrpExpand(hrp) + data) == 1 else { return nil }
|
|
242
|
+
return (String(decoding: hrp, as: UTF8.self), Array(data.dropLast(6)))
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
/// Regroups bits (BIP173 convertbits).
|
|
246
|
+
static func convertBits(_ data: [UInt8], from: Int, to: Int, pad: Bool) -> [UInt8]? {
|
|
247
|
+
var acc = 0, bits = 0
|
|
248
|
+
var out = [UInt8]()
|
|
249
|
+
let maxv = (1 << to) - 1
|
|
250
|
+
for v in data {
|
|
251
|
+
guard Int(v) >> from == 0 else { return nil }
|
|
252
|
+
acc = acc << from | Int(v)
|
|
253
|
+
bits += from
|
|
254
|
+
while bits >= to {
|
|
255
|
+
bits -= to
|
|
256
|
+
out.append(UInt8((acc >> bits) & maxv))
|
|
257
|
+
}
|
|
258
|
+
}
|
|
259
|
+
if pad {
|
|
260
|
+
if bits > 0 { out.append(UInt8((acc << (to - bits)) & maxv)) }
|
|
261
|
+
} else if bits >= from || (acc << (to - bits)) & maxv != 0 {
|
|
262
|
+
return nil
|
|
263
|
+
}
|
|
264
|
+
return out
|
|
265
|
+
}
|
|
266
|
+
|
|
267
|
+
static func segwitAddress(hrp: String, version: UInt8, program: [UInt8]) -> String {
|
|
268
|
+
encode(hrp: hrp, data: [version] + convertBits(program, from: 8, to: 5, pad: true)!, m: version > 0)
|
|
269
|
+
}
|
|
270
|
+
|
|
271
|
+
/// (version, program) of a SegWit address with the expected HRP.
|
|
272
|
+
static func decodeSegwit(hrp: String, address: String) -> (version: UInt8, program: [UInt8])? {
|
|
273
|
+
guard let d = decode(address), d.hrp == hrp, let version = d.data.first, version <= 16,
|
|
274
|
+
let program = convertBits(Array(d.data.dropFirst()), from: 5, to: 8, pad: false),
|
|
275
|
+
(2...40).contains(program.count), version != 0 || program.count == 20 || program.count == 32 else { return nil }
|
|
276
|
+
return (version, program)
|
|
277
|
+
}
|
|
278
|
+
}
|