@authon/react-native-wallet 0.0.0-stage → 0.1.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.
Files changed (159) hide show
  1. package/README.md +221 -2
  2. package/android/build.gradle +40 -0
  3. package/android/consumer-rules.pro +10 -0
  4. package/android/src/main/AndroidManifest.xml +4 -0
  5. package/android/src/main/java/dev/authon/reactnative/wallet/AuthonWalletModule.kt +181 -0
  6. package/android/src/vendor/GENERATED.md +4 -0
  7. package/android/src/vendor/kotlin/dev/authon/sdk/wallet/AuthonWallet.kt +191 -0
  8. package/android/src/vendor/kotlin/dev/authon/sdk/wallet/Bytes.kt +74 -0
  9. package/android/src/vendor/kotlin/dev/authon/sdk/wallet/CredentialManagerPasskeys.kt +192 -0
  10. package/android/src/vendor/kotlin/dev/authon/sdk/wallet/DeviceStore.kt +170 -0
  11. package/android/src/vendor/kotlin/dev/authon/sdk/wallet/DialogWalletApprover.kt +141 -0
  12. package/android/src/vendor/kotlin/dev/authon/sdk/wallet/Eip712.kt +176 -0
  13. package/android/src/vendor/kotlin/dev/authon/sdk/wallet/EvmAccount.kt +45 -0
  14. package/android/src/vendor/kotlin/dev/authon/sdk/wallet/EvmTransaction.kt +180 -0
  15. package/android/src/vendor/kotlin/dev/authon/sdk/wallet/GfTables.kt +44 -0
  16. package/android/src/vendor/kotlin/dev/authon/sdk/wallet/HdWallet.kt +130 -0
  17. package/android/src/vendor/kotlin/dev/authon/sdk/wallet/Http.kt +82 -0
  18. package/android/src/vendor/kotlin/dev/authon/sdk/wallet/JsValues.kt +83 -0
  19. package/android/src/vendor/kotlin/dev/authon/sdk/wallet/KeystoreDeviceStore.kt +232 -0
  20. package/android/src/vendor/kotlin/dev/authon/sdk/wallet/Prf.kt +111 -0
  21. package/android/src/vendor/kotlin/dev/authon/sdk/wallet/Proof.kt +134 -0
  22. package/android/src/vendor/kotlin/dev/authon/sdk/wallet/Shamir.kt +106 -0
  23. package/android/src/vendor/kotlin/dev/authon/sdk/wallet/SignSummary.kt +335 -0
  24. package/android/src/vendor/kotlin/dev/authon/sdk/wallet/WalletApi.kt +353 -0
  25. package/android/src/vendor/kotlin/dev/authon/sdk/wallet/WalletError.kt +58 -0
  26. package/android/src/vendor/kotlin/dev/authon/sdk/wallet/WalletOps.kt +449 -0
  27. package/android/src/vendor/kotlin/dev/authon/sdk/wallet/WalletTypes.kt +71 -0
  28. package/build/authonContext.d.ts +19 -0
  29. package/build/authonContext.d.ts.map +1 -0
  30. package/build/authonContext.js +20 -0
  31. package/build/authonContext.js.map +1 -0
  32. package/build/client.d.ts +76 -0
  33. package/build/client.d.ts.map +1 -0
  34. package/build/client.js +349 -0
  35. package/build/client.js.map +1 -0
  36. package/build/errors.d.ts +18 -0
  37. package/build/errors.d.ts.map +1 -0
  38. package/build/errors.js +9 -0
  39. package/build/errors.js.map +1 -0
  40. package/build/index.d.ts +7 -0
  41. package/build/index.d.ts.map +1 -0
  42. package/build/index.js +4 -0
  43. package/build/index.js.map +1 -0
  44. package/build/native.d.ts +39 -0
  45. package/build/native.d.ts.map +1 -0
  46. package/build/native.js +12 -0
  47. package/build/native.js.map +1 -0
  48. package/build/types.d.ts +121 -0
  49. package/build/types.d.ts.map +1 -0
  50. package/build/types.js +3 -0
  51. package/build/types.js.map +1 -0
  52. package/build/useAuthonWallet.d.ts +25 -0
  53. package/build/useAuthonWallet.d.ts.map +1 -0
  54. package/build/useAuthonWallet.js +77 -0
  55. package/build/useAuthonWallet.js.map +1 -0
  56. package/expo-module.config.json +9 -0
  57. package/ios/AuthonReactNativeWallet.podspec +37 -0
  58. package/ios/AuthonWalletModule.swift +190 -0
  59. package/ios/vendor/AuthonWallet/AuthonWallet.swift +212 -0
  60. package/ios/vendor/AuthonWallet/Crypto/BIP39Wordlist.swift +262 -0
  61. package/ios/vendor/AuthonWallet/Crypto/HDKey.swift +108 -0
  62. package/ios/vendor/AuthonWallet/Crypto/Secp256k1.swift +104 -0
  63. package/ios/vendor/AuthonWallet/Crypto/Shamir.swift +123 -0
  64. package/ios/vendor/AuthonWallet/EVM/Address.swift +57 -0
  65. package/ios/vendor/AuthonWallet/EVM/EvmAccount.swift +48 -0
  66. package/ios/vendor/AuthonWallet/EVM/Transaction.swift +165 -0
  67. package/ios/vendor/AuthonWallet/EVM/TypedData.swift +193 -0
  68. package/ios/vendor/AuthonWallet/Support/BigInteger.swift +220 -0
  69. package/ios/vendor/AuthonWallet/Support/Bytes.swift +89 -0
  70. package/ios/vendor/AuthonWallet/Support/JSONValue.swift +341 -0
  71. package/ios/vendor/AuthonWallet/UI/WalletApprover.swift +250 -0
  72. package/ios/vendor/AuthonWallet/Wallet/Backup.swift +69 -0
  73. package/ios/vendor/AuthonWallet/Wallet/DeviceStore.swift +351 -0
  74. package/ios/vendor/AuthonWallet/Wallet/Passkeys.swift +190 -0
  75. package/ios/vendor/AuthonWallet/Wallet/Proof.swift +143 -0
  76. package/ios/vendor/AuthonWallet/Wallet/Shares.swift +116 -0
  77. package/ios/vendor/AuthonWallet/Wallet/Summary.swift +342 -0
  78. package/ios/vendor/AuthonWallet/Wallet/WalletAPI.swift +350 -0
  79. package/ios/vendor/AuthonWallet/Wallet/WalletOps.swift +555 -0
  80. package/ios/vendor/AuthonWallet/WalletError.swift +54 -0
  81. package/ios/vendor/CKeccak/LICENSE +22 -0
  82. package/ios/vendor/CKeccak/README.md +27 -0
  83. package/ios/vendor/CKeccak/byte_order.h +59 -0
  84. package/ios/vendor/CKeccak/include/ckeccak.h +9 -0
  85. package/ios/vendor/CKeccak/memzero.c +75 -0
  86. package/ios/vendor/CKeccak/memzero.h +8 -0
  87. package/ios/vendor/CKeccak/options.h +99 -0
  88. package/ios/vendor/CKeccak/sha3.c +413 -0
  89. package/ios/vendor/CKeccak/sha3.h +89 -0
  90. package/ios/vendor/CSecp256k1/COPYING +19 -0
  91. package/ios/vendor/CSecp256k1/README.md +35 -0
  92. package/ios/vendor/CSecp256k1/build/precomputed_ecmult.c +3 -0
  93. package/ios/vendor/CSecp256k1/build/precomputed_ecmult_gen.c +3 -0
  94. package/ios/vendor/CSecp256k1/build/secp256k1.c +3 -0
  95. package/ios/vendor/CSecp256k1/include/secp256k1.h +899 -0
  96. package/ios/vendor/CSecp256k1/include/secp256k1_preallocated.h +134 -0
  97. package/ios/vendor/CSecp256k1/include/secp256k1_recovery.h +113 -0
  98. package/ios/vendor/CSecp256k1/src/assumptions.h +87 -0
  99. package/ios/vendor/CSecp256k1/src/checkmem.h +102 -0
  100. package/ios/vendor/CSecp256k1/src/ecdsa.h +21 -0
  101. package/ios/vendor/CSecp256k1/src/ecdsa_impl.h +304 -0
  102. package/ios/vendor/CSecp256k1/src/eckey.h +25 -0
  103. package/ios/vendor/CSecp256k1/src/eckey_impl.h +92 -0
  104. package/ios/vendor/CSecp256k1/src/ecmult.h +61 -0
  105. package/ios/vendor/CSecp256k1/src/ecmult_const.h +38 -0
  106. package/ios/vendor/CSecp256k1/src/ecmult_const_impl.h +399 -0
  107. package/ios/vendor/CSecp256k1/src/ecmult_gen.h +143 -0
  108. package/ios/vendor/CSecp256k1/src/ecmult_gen_impl.h +341 -0
  109. package/ios/vendor/CSecp256k1/src/ecmult_impl.h +853 -0
  110. package/ios/vendor/CSecp256k1/src/field.h +350 -0
  111. package/ios/vendor/CSecp256k1/src/field_10x26.h +57 -0
  112. package/ios/vendor/CSecp256k1/src/field_10x26_impl.h +1232 -0
  113. package/ios/vendor/CSecp256k1/src/field_5x52.h +62 -0
  114. package/ios/vendor/CSecp256k1/src/field_5x52_impl.h +522 -0
  115. package/ios/vendor/CSecp256k1/src/field_5x52_int128_impl.h +274 -0
  116. package/ios/vendor/CSecp256k1/src/field_impl.h +457 -0
  117. package/ios/vendor/CSecp256k1/src/group.h +212 -0
  118. package/ios/vendor/CSecp256k1/src/group_impl.h +974 -0
  119. package/ios/vendor/CSecp256k1/src/hash.h +44 -0
  120. package/ios/vendor/CSecp256k1/src/hash_impl.h +299 -0
  121. package/ios/vendor/CSecp256k1/src/hsort.h +33 -0
  122. package/ios/vendor/CSecp256k1/src/hsort_impl.h +125 -0
  123. package/ios/vendor/CSecp256k1/src/int128.h +90 -0
  124. package/ios/vendor/CSecp256k1/src/int128_impl.h +18 -0
  125. package/ios/vendor/CSecp256k1/src/int128_native.h +19 -0
  126. package/ios/vendor/CSecp256k1/src/int128_native_impl.h +94 -0
  127. package/ios/vendor/CSecp256k1/src/int128_struct.h +14 -0
  128. package/ios/vendor/CSecp256k1/src/int128_struct_impl.h +205 -0
  129. package/ios/vendor/CSecp256k1/src/modinv32.h +43 -0
  130. package/ios/vendor/CSecp256k1/src/modinv32_impl.h +725 -0
  131. package/ios/vendor/CSecp256k1/src/modinv64.h +47 -0
  132. package/ios/vendor/CSecp256k1/src/modinv64_impl.h +780 -0
  133. package/ios/vendor/CSecp256k1/src/modules/recovery/main_impl.h +159 -0
  134. package/ios/vendor/CSecp256k1/src/precomputed_ecmult.c +16456 -0
  135. package/ios/vendor/CSecp256k1/src/precomputed_ecmult.h +38 -0
  136. package/ios/vendor/CSecp256k1/src/precomputed_ecmult_gen.c +1779 -0
  137. package/ios/vendor/CSecp256k1/src/precomputed_ecmult_gen.h +26 -0
  138. package/ios/vendor/CSecp256k1/src/scalar.h +105 -0
  139. package/ios/vendor/CSecp256k1/src/scalar_4x64.h +19 -0
  140. package/ios/vendor/CSecp256k1/src/scalar_4x64_impl.h +1000 -0
  141. package/ios/vendor/CSecp256k1/src/scalar_8x32.h +19 -0
  142. package/ios/vendor/CSecp256k1/src/scalar_8x32_impl.h +816 -0
  143. package/ios/vendor/CSecp256k1/src/scalar_impl.h +321 -0
  144. package/ios/vendor/CSecp256k1/src/scalar_low.h +24 -0
  145. package/ios/vendor/CSecp256k1/src/scalar_low_impl.h +206 -0
  146. package/ios/vendor/CSecp256k1/src/scratch.h +44 -0
  147. package/ios/vendor/CSecp256k1/src/scratch_impl.h +99 -0
  148. package/ios/vendor/CSecp256k1/src/secp256k1.c +831 -0
  149. package/ios/vendor/CSecp256k1/src/selftest.h +32 -0
  150. package/ios/vendor/CSecp256k1/src/util.h +451 -0
  151. package/ios/vendor/GENERATED.md +4 -0
  152. package/package.json +65 -3
  153. package/src/authonContext.ts +30 -0
  154. package/src/client.ts +375 -0
  155. package/src/errors.ts +52 -0
  156. package/src/index.ts +21 -0
  157. package/src/native.ts +50 -0
  158. package/src/types.ts +120 -0
  159. 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,108 @@
1
+ // GENERATED by scripts/sync-native-wallet.mjs from swift/Sources/AuthonWallet/Crypto/HDKey.swift. Do not edit: change the source and run the script.
2
+ import CommonCrypto
3
+ import CryptoKit
4
+ import Foundation
5
+
6
+ /// BIP39 (English) for 128..256-bit entropy, as @scure/bip39.
7
+ enum BIP39 {
8
+ static func mnemonic(entropy: [UInt8]) throws -> String {
9
+ guard entropy.count >= 16, entropy.count <= 32, entropy.count % 4 == 0 else {
10
+ throw WalletError(.internal, "invalid entropy length")
11
+ }
12
+ let checksumBits = entropy.count / 4
13
+ let hash = Bytes.sha256(entropy)
14
+ var bits = [Bool]()
15
+ bits.reserveCapacity(entropy.count * 8 + checksumBits)
16
+ for b in entropy { for i in (0..<8).reversed() { bits.append((b >> UInt8(i)) & 1 == 1) } }
17
+ for i in 0..<checksumBits { bits.append((hash[i / 8] >> UInt8(7 - i % 8)) & 1 == 1) }
18
+ var words = [String]()
19
+ for w in 0..<(bits.count / 11) {
20
+ var index = 0
21
+ for j in 0..<11 { index = index << 1 | (bits[w * 11 + j] ? 1 : 0) }
22
+ words.append(bip39EnglishWordlist[index])
23
+ }
24
+ return words.joined(separator: " ")
25
+ }
26
+
27
+ /// PBKDF2-HMAC-SHA512, 2048 rounds, salt "mnemonic" (empty passphrase).
28
+ static func seed(mnemonic: String) throws -> [UInt8] {
29
+ var password = Array(mnemonic.decomposedStringWithCompatibilityMapping.utf8)
30
+ defer { password.wipe() }
31
+ let salt = Array("mnemonic".utf8)
32
+ var out = [UInt8](repeating: 0, count: 64)
33
+ let status = password.withUnsafeBufferPointer { pw in
34
+ CCKeyDerivationPBKDF(
35
+ CCPBKDFAlgorithm(kCCPBKDF2),
36
+ UnsafeRawPointer(pw.baseAddress!).assumingMemoryBound(to: CChar.self), pw.count,
37
+ salt, salt.count,
38
+ CCPseudoRandomAlgorithm(kCCPRFHmacAlgSHA512), 2048,
39
+ &out, out.count
40
+ )
41
+ }
42
+ guard status == kCCSuccess else { throw WalletError(.internal, "seed derivation failed") }
43
+ return out
44
+ }
45
+ }
46
+
47
+ /// BIP32 private derivation over secp256k1 (scalar addition and public keys in libsecp256k1).
48
+ struct HDNode {
49
+ private(set) var key: [UInt8]
50
+ private(set) var chainCode: [UInt8]
51
+
52
+ static let hardened: UInt32 = 0x8000_0000
53
+
54
+ init(seed: [UInt8]) throws {
55
+ var i = HDNode.hmac(key: Array("Bitcoin seed".utf8), data: seed)
56
+ defer { i.wipe() }
57
+ let k = Array(i[0..<32])
58
+ guard Secp256k1.isValidPrivateKey(k) else { throw WalletError(.internal, "invalid master key") }
59
+ key = k
60
+ chainCode = Array(i[32..<64])
61
+ }
62
+
63
+ private init(key: [UInt8], chainCode: [UInt8]) {
64
+ self.key = key
65
+ self.chainCode = chainCode
66
+ }
67
+
68
+ func child(_ index: UInt32) throws -> HDNode {
69
+ var data: [UInt8]
70
+ if index >= HDNode.hardened {
71
+ data = [0] + key
72
+ } else {
73
+ data = try Secp256k1.publicKey(of: key, compressed: true)
74
+ }
75
+ data += [UInt8(index >> 24), UInt8(truncatingIfNeeded: index >> 16), UInt8(truncatingIfNeeded: index >> 8), UInt8(truncatingIfNeeded: index)]
76
+ var i = HDNode.hmac(key: chainCode, data: data)
77
+ defer {
78
+ i.wipe()
79
+ data.wipe()
80
+ }
81
+ let childKey = try Secp256k1.addTweak(key, Array(i[0..<32]))
82
+ return HDNode(key: childKey, chainCode: Array(i[32..<64]))
83
+ }
84
+
85
+ /// "m/44'/60'/0'/0/5"
86
+ func derive(_ path: String) throws -> HDNode {
87
+ let parts = path.split(separator: "/")
88
+ guard parts.first == "m" else { throw WalletError(.internal, "invalid path") }
89
+ var node = self
90
+ for p in parts.dropFirst() {
91
+ let hard = p.hasSuffix("'")
92
+ guard let n = UInt32(hard ? p.dropLast() : p), n < HDNode.hardened else { throw WalletError(.internal, "invalid path") }
93
+ let next = try node.child(hard ? n + HDNode.hardened : n)
94
+ node.wipe()
95
+ node = next
96
+ }
97
+ return node
98
+ }
99
+
100
+ mutating func wipe() {
101
+ key.wipe()
102
+ chainCode.wipe()
103
+ }
104
+
105
+ private static func hmac(key: [UInt8], data: [UInt8]) -> [UInt8] {
106
+ Array(HMAC<SHA512>.authenticationCode(for: data, using: SymmetricKey(data: key)))
107
+ }
108
+ }
@@ -0,0 +1,104 @@
1
+ // GENERATED by scripts/sync-native-wallet.mjs from swift/Sources/AuthonWallet/Crypto/Secp256k1.swift. Do not edit: change the source and run the script.
2
+ #if canImport(CKeccak)
3
+ import CKeccak
4
+ #endif
5
+ #if canImport(CSecp256k1)
6
+ import CSecp256k1
7
+ #endif
8
+ import Foundation
9
+
10
+ enum Keccak {
11
+ static func hash256(_ data: [UInt8]) -> [UInt8] {
12
+ var out = [UInt8](repeating: 0, count: 32)
13
+ data.withUnsafeBufferPointer { input in
14
+ out.withUnsafeMutableBufferPointer { keccak_256(input.baseAddress, input.count, $0.baseAddress) }
15
+ }
16
+ return out
17
+ }
18
+ }
19
+
20
+ /// libsecp256k1 (bitcoin-core) wrapper. All curve arithmetic happens in the vendored C library.
21
+ enum Secp256k1 {
22
+ struct RecoverableSignature {
23
+ var r: [UInt8]
24
+ var s: [UInt8]
25
+ /// 0 or 1.
26
+ var recoveryId: Int
27
+ }
28
+
29
+ private static let context: OpaquePointer = {
30
+ let ctx = secp256k1_context_create(UInt32(SECP256K1_CONTEXT_NONE))!
31
+ // Side-channel blinding of the signing context, as the library recommends.
32
+ if var seed = try? Bytes.random(32) {
33
+ _ = secp256k1_context_randomize(ctx, seed)
34
+ seed.wipe()
35
+ }
36
+ return ctx
37
+ }()
38
+ private static let lock = NSLock()
39
+
40
+ private static func withContext<T>(_ body: (OpaquePointer) throws -> T) rethrows -> T {
41
+ lock.lock()
42
+ defer { lock.unlock() }
43
+ return try body(context)
44
+ }
45
+
46
+ static func isValidPrivateKey(_ key: [UInt8]) -> Bool {
47
+ key.count == 32 && withContext { secp256k1_ec_seckey_verify($0, key) == 1 }
48
+ }
49
+
50
+ /// Public key, 65-byte uncompressed (0x04 || x || y) or 33-byte compressed.
51
+ static func publicKey(of key: [UInt8], compressed: Bool) throws -> [UInt8] {
52
+ guard key.count == 32 else { throw WalletError(.internal, "invalid private key") }
53
+ return try withContext { ctx in
54
+ var pub = secp256k1_pubkey()
55
+ guard secp256k1_ec_pubkey_create(ctx, &pub, key) == 1 else { throw WalletError(.internal, "invalid private key") }
56
+ var out = [UInt8](repeating: 0, count: compressed ? 33 : 65)
57
+ var len = out.count
58
+ let flags = UInt32(compressed ? SECP256K1_EC_COMPRESSED : SECP256K1_EC_UNCOMPRESSED)
59
+ guard secp256k1_ec_pubkey_serialize(ctx, &out, &len, &pub, flags) == 1 else { throw WalletError(.internal) }
60
+ return Array(out[0..<len])
61
+ }
62
+ }
63
+
64
+ /// (key + tweak) mod n, for BIP32 child keys. Fails when tweak >= n or the result is zero.
65
+ static func addTweak(_ key: [UInt8], _ tweak: [UInt8]) throws -> [UInt8] {
66
+ var out = key
67
+ let ok = withContext { secp256k1_ec_seckey_tweak_add($0, &out, tweak) == 1 }
68
+ guard ok else {
69
+ out.wipe()
70
+ throw WalletError(.internal, "invalid child key")
71
+ }
72
+ return out
73
+ }
74
+
75
+ /// RFC 6979 deterministic, low-s ECDSA over a 32-byte hash.
76
+ static func sign(hash: [UInt8], key: [UInt8]) throws -> RecoverableSignature {
77
+ guard hash.count == 32, key.count == 32 else { throw WalletError(.internal, "invalid signing input") }
78
+ return try withContext { ctx in
79
+ var sig = secp256k1_ecdsa_recoverable_signature()
80
+ guard secp256k1_ecdsa_sign_recoverable(ctx, &sig, hash, key, nil, nil) == 1 else {
81
+ throw WalletError(.internal, "signing failed")
82
+ }
83
+ var compact = [UInt8](repeating: 0, count: 64)
84
+ var recid: Int32 = 0
85
+ secp256k1_ecdsa_recoverable_signature_serialize_compact(ctx, &compact, &recid, &sig)
86
+ return RecoverableSignature(r: Array(compact[0..<32]), s: Array(compact[32..<64]), recoveryId: Int(recid))
87
+ }
88
+ }
89
+
90
+ /// Recovers the uncompressed public key of a signature (used to verify proofs in tests and checks).
91
+ static func recover(hash: [UInt8], r: [UInt8], s: [UInt8], recoveryId: Int) -> [UInt8]? {
92
+ guard hash.count == 32, r.count == 32, s.count == 32, (0...3).contains(recoveryId) else { return nil }
93
+ return withContext { ctx in
94
+ var sig = secp256k1_ecdsa_recoverable_signature()
95
+ guard secp256k1_ecdsa_recoverable_signature_parse_compact(ctx, &sig, r + s, Int32(recoveryId)) == 1 else { return nil }
96
+ var pub = secp256k1_pubkey()
97
+ guard secp256k1_ecdsa_recover(ctx, &pub, &sig, hash) == 1 else { return nil }
98
+ var out = [UInt8](repeating: 0, count: 65)
99
+ var len = 65
100
+ secp256k1_ec_pubkey_serialize(ctx, &out, &len, &pub, UInt32(SECP256K1_EC_UNCOMPRESSED))
101
+ return out
102
+ }
103
+ }
104
+ }
@@ -0,0 +1,123 @@
1
+ // GENERATED by scripts/sync-native-wallet.mjs from swift/Sources/AuthonWallet/Crypto/Shamir.swift. Do not edit: change the source and run the script.
2
+ import Foundation
3
+
4
+ /// Shamir secret sharing over GF(2^8), byte-compatible with the `shamir-secret-sharing`
5
+ /// 0.0.4 package the web frame uses: polynomial x^8+x^4+x^3+x+1, generator 0xe5, and each
6
+ /// share is the y bytes followed by its x coordinate. Tables are copied from that package
7
+ /// (originally hashicorp/vault shamir/tables.go).
8
+ enum Shamir {
9
+ private static let logTable: [UInt8] = [
10
+ 0x00, 0xff, 0xc8, 0x08, 0x91, 0x10, 0xd0, 0x36, 0x5a, 0x3e, 0xd8, 0x43, 0x99, 0x77, 0xfe, 0x18,
11
+ 0x23, 0x20, 0x07, 0x70, 0xa1, 0x6c, 0x0c, 0x7f, 0x62, 0x8b, 0x40, 0x46, 0xc7, 0x4b, 0xe0, 0x0e,
12
+ 0xeb, 0x16, 0xe8, 0xad, 0xcf, 0xcd, 0x39, 0x53, 0x6a, 0x27, 0x35, 0x93, 0xd4, 0x4e, 0x48, 0xc3,
13
+ 0x2b, 0x79, 0x54, 0x28, 0x09, 0x78, 0x0f, 0x21, 0x90, 0x87, 0x14, 0x2a, 0xa9, 0x9c, 0xd6, 0x74,
14
+ 0xb4, 0x7c, 0xde, 0xed, 0xb1, 0x86, 0x76, 0xa4, 0x98, 0xe2, 0x96, 0x8f, 0x02, 0x32, 0x1c, 0xc1,
15
+ 0x33, 0xee, 0xef, 0x81, 0xfd, 0x30, 0x5c, 0x13, 0x9d, 0x29, 0x17, 0xc4, 0x11, 0x44, 0x8c, 0x80,
16
+ 0xf3, 0x73, 0x42, 0x1e, 0x1d, 0xb5, 0xf0, 0x12, 0xd1, 0x5b, 0x41, 0xa2, 0xd7, 0x2c, 0xe9, 0xd5,
17
+ 0x59, 0xcb, 0x50, 0xa8, 0xdc, 0xfc, 0xf2, 0x56, 0x72, 0xa6, 0x65, 0x2f, 0x9f, 0x9b, 0x3d, 0xba,
18
+ 0x7d, 0xc2, 0x45, 0x82, 0xa7, 0x57, 0xb6, 0xa3, 0x7a, 0x75, 0x4f, 0xae, 0x3f, 0x37, 0x6d, 0x47,
19
+ 0x61, 0xbe, 0xab, 0xd3, 0x5f, 0xb0, 0x58, 0xaf, 0xca, 0x5e, 0xfa, 0x85, 0xe4, 0x4d, 0x8a, 0x05,
20
+ 0xfb, 0x60, 0xb7, 0x7b, 0xb8, 0x26, 0x4a, 0x67, 0xc6, 0x1a, 0xf8, 0x69, 0x25, 0xb3, 0xdb, 0xbd,
21
+ 0x66, 0xdd, 0xf1, 0xd2, 0xdf, 0x03, 0x8d, 0x34, 0xd9, 0x92, 0x0d, 0x63, 0x55, 0xaa, 0x49, 0xec,
22
+ 0xbc, 0x95, 0x3c, 0x84, 0x0b, 0xf5, 0xe6, 0xe7, 0xe5, 0xac, 0x7e, 0x6e, 0xb9, 0xf9, 0xda, 0x8e,
23
+ 0x9a, 0xc9, 0x24, 0xe1, 0x0a, 0x15, 0x6b, 0x3a, 0xa0, 0x51, 0xf4, 0xea, 0xb2, 0x97, 0x9e, 0x5d,
24
+ 0x22, 0x88, 0x94, 0xce, 0x19, 0x01, 0x71, 0x4c, 0xa5, 0xe3, 0xc5, 0x31, 0xbb, 0xcc, 0x1f, 0x2d,
25
+ 0x3b, 0x52, 0x6f, 0xf6, 0x2e, 0x89, 0xf7, 0xc0, 0x68, 0x1b, 0x64, 0x04, 0x06, 0xbf, 0x83, 0x38,
26
+ ]
27
+
28
+ private static let expTable: [UInt8] = [
29
+ 0x01, 0xe5, 0x4c, 0xb5, 0xfb, 0x9f, 0xfc, 0x12, 0x03, 0x34, 0xd4, 0xc4, 0x16, 0xba, 0x1f, 0x36,
30
+ 0x05, 0x5c, 0x67, 0x57, 0x3a, 0xd5, 0x21, 0x5a, 0x0f, 0xe4, 0xa9, 0xf9, 0x4e, 0x64, 0x63, 0xee,
31
+ 0x11, 0x37, 0xe0, 0x10, 0xd2, 0xac, 0xa5, 0x29, 0x33, 0x59, 0x3b, 0x30, 0x6d, 0xef, 0xf4, 0x7b,
32
+ 0x55, 0xeb, 0x4d, 0x50, 0xb7, 0x2a, 0x07, 0x8d, 0xff, 0x26, 0xd7, 0xf0, 0xc2, 0x7e, 0x09, 0x8c,
33
+ 0x1a, 0x6a, 0x62, 0x0b, 0x5d, 0x82, 0x1b, 0x8f, 0x2e, 0xbe, 0xa6, 0x1d, 0xe7, 0x9d, 0x2d, 0x8a,
34
+ 0x72, 0xd9, 0xf1, 0x27, 0x32, 0xbc, 0x77, 0x85, 0x96, 0x70, 0x08, 0x69, 0x56, 0xdf, 0x99, 0x94,
35
+ 0xa1, 0x90, 0x18, 0xbb, 0xfa, 0x7a, 0xb0, 0xa7, 0xf8, 0xab, 0x28, 0xd6, 0x15, 0x8e, 0xcb, 0xf2,
36
+ 0x13, 0xe6, 0x78, 0x61, 0x3f, 0x89, 0x46, 0x0d, 0x35, 0x31, 0x88, 0xa3, 0x41, 0x80, 0xca, 0x17,
37
+ 0x5f, 0x53, 0x83, 0xfe, 0xc3, 0x9b, 0x45, 0x39, 0xe1, 0xf5, 0x9e, 0x19, 0x5e, 0xb6, 0xcf, 0x4b,
38
+ 0x38, 0x04, 0xb9, 0x2b, 0xe2, 0xc1, 0x4a, 0xdd, 0x48, 0x0c, 0xd0, 0x7d, 0x3d, 0x58, 0xde, 0x7c,
39
+ 0xd8, 0x14, 0x6b, 0x87, 0x47, 0xe8, 0x79, 0x84, 0x73, 0x3c, 0xbd, 0x92, 0xc9, 0x23, 0x8b, 0x97,
40
+ 0x95, 0x44, 0xdc, 0xad, 0x40, 0x65, 0x86, 0xa2, 0xa4, 0xcc, 0x7f, 0xec, 0xc0, 0xaf, 0x91, 0xfd,
41
+ 0xf7, 0x4f, 0x81, 0x2f, 0x5b, 0xea, 0xa8, 0x1c, 0x02, 0xd1, 0x98, 0x71, 0xed, 0x25, 0xe3, 0x24,
42
+ 0x06, 0x68, 0xb3, 0x93, 0x2c, 0x6f, 0x3e, 0x6c, 0x0a, 0xb8, 0xce, 0xae, 0x74, 0xb1, 0x42, 0xb4,
43
+ 0x1e, 0xd3, 0x49, 0xe9, 0x9c, 0xc8, 0xc6, 0xc7, 0x22, 0x6e, 0xdb, 0x20, 0xbf, 0x43, 0x51, 0x52,
44
+ 0x66, 0xb2, 0x76, 0x60, 0xda, 0xc5, 0xf3, 0xf6, 0xaa, 0xcd, 0x9a, 0xa0, 0x75, 0x54, 0x0e, 0x01,
45
+ ]
46
+
47
+ private static func div(_ a: UInt8, _ b: UInt8) throws -> UInt8 {
48
+ guard b != 0 else { throw WalletError(.internal, "cannot divide by zero") }
49
+ if a == 0 { return 0 }
50
+ let diff = (Int(logTable[Int(a)]) - Int(logTable[Int(b)]) + 255) % 255
51
+ return expTable[diff]
52
+ }
53
+
54
+ private static func mult(_ a: UInt8, _ b: UInt8) -> UInt8 {
55
+ if a == 0 || b == 0 { return 0 }
56
+ return expTable[(Int(logTable[Int(a)]) + Int(logTable[Int(b)])) % 255]
57
+ }
58
+
59
+ private static func interpolate(_ xs: [UInt8], _ ys: [UInt8], at x: UInt8) throws -> UInt8 {
60
+ var result: UInt8 = 0
61
+ for i in 0..<xs.count {
62
+ var basis: UInt8 = 1
63
+ for j in 0..<xs.count where i != j {
64
+ basis = mult(basis, try div(x ^ xs[j], xs[i] ^ xs[j]))
65
+ }
66
+ result ^= mult(ys[i], basis)
67
+ }
68
+ return result
69
+ }
70
+
71
+ private static func evaluate(_ coefficients: [UInt8], at x: UInt8) -> UInt8 {
72
+ var result = coefficients[coefficients.count - 1]
73
+ for c in coefficients.dropLast().reversed() { result = mult(result, x) ^ c }
74
+ return result
75
+ }
76
+
77
+ /// Same shuffle as the package's newCoordinates() (a permutation of 1...255).
78
+ private static func newCoordinates() throws -> [UInt8] {
79
+ var coordinates = (0..<255).map { UInt8($0 + 1) }
80
+ let randomIndices = try Bytes.random(255)
81
+ for i in 0..<255 {
82
+ let j = Int(randomIndices[i]) % 255
83
+ coordinates.swapAt(i, j)
84
+ }
85
+ return coordinates
86
+ }
87
+
88
+ static func split(_ secret: [UInt8], shares: Int, threshold: Int) throws -> [[UInt8]] {
89
+ guard !secret.isEmpty, (2...255).contains(shares), (2...255).contains(threshold), shares >= threshold else {
90
+ throw WalletError(.internal, "invalid split parameters")
91
+ }
92
+ let xs = try newCoordinates()
93
+ var result = (0..<shares).map { i -> [UInt8] in
94
+ var share = [UInt8](repeating: 0, count: secret.count + 1)
95
+ share[secret.count] = xs[i]
96
+ return share
97
+ }
98
+ for i in 0..<secret.count {
99
+ var coefficients = [secret[i]] + (try Bytes.random(threshold - 1))
100
+ for j in 0..<shares { result[j][i] = evaluate(coefficients, at: xs[j]) }
101
+ coefficients.wipe()
102
+ }
103
+ return result
104
+ }
105
+
106
+ static func combine(_ shares: [[UInt8]]) throws -> [UInt8] {
107
+ guard (2...255).contains(shares.count) else { throw WalletError(.internal, "need at least 2 shares") }
108
+ let length = shares[0].count
109
+ guard length >= 2, shares.allSatisfy({ $0.count == length }) else {
110
+ throw WalletError(.internal, "all shares must have the same byte length")
111
+ }
112
+ let xs = shares.map { $0[length - 1] }
113
+ guard Set(xs).count == xs.count else { throw WalletError(.internal, "duplicate share") }
114
+ var secret = [UInt8](repeating: 0, count: length - 1)
115
+ var ys = [UInt8](repeating: 0, count: shares.count)
116
+ defer { ys.wipe() }
117
+ for i in 0..<(length - 1) {
118
+ for j in 0..<shares.count { ys[j] = shares[j][i] }
119
+ secret[i] = try interpolate(xs, ys, at: 0)
120
+ }
121
+ return secret
122
+ }
123
+ }