@pooflabs/web 0.0.85-rc3 → 0.0.87

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 (65) hide show
  1. package/dist/auth/providers/solana-mobile-wallet-provider.d.ts +43 -0
  2. package/dist/{index-B5qYY4YM.js → index-B-x9RTF7.js} +2 -2
  3. package/dist/index-B-x9RTF7.js.map +1 -0
  4. package/dist/{index-BaKs3A8s.js → index-BKN0IwAx.js} +3054 -300
  5. package/dist/index-BKN0IwAx.js.map +1 -0
  6. package/dist/{index-C4AnWFs_.esm.js → index-BTwX7FYW.esm.js} +425 -119
  7. package/dist/index-BTwX7FYW.esm.js.map +1 -0
  8. package/dist/{index-BzeiIIwF.js → index-DYBdUxnT.js} +3055 -301
  9. package/dist/index-DYBdUxnT.js.map +1 -0
  10. package/dist/{index-bEXLwE7_.js → index-Dj1tZr6X.js} +426 -118
  11. package/dist/index-Dj1tZr6X.js.map +1 -0
  12. package/dist/{index-dqqR5q7b.esm.js → index-DofM-ue2.esm.js} +3054 -301
  13. package/dist/index-DofM-ue2.esm.js.map +1 -0
  14. package/dist/index-_k6pjuwx.esm.js +6 -0
  15. package/dist/index-_k6pjuwx.esm.js.map +1 -0
  16. package/dist/{index-BE-VWSJT.esm.js → index-x7a-wH2l.esm.js} +3055 -300
  17. package/dist/index-x7a-wH2l.esm.js.map +1 -0
  18. package/dist/{index.browser-D8ttddP4.esm.js → index.browser-Cndx2raY.esm.js} +506 -1876
  19. package/dist/index.browser-Cndx2raY.esm.js.map +1 -0
  20. package/dist/{index.browser-CN6obNQM.js → index.browser-D7-FFk3q.js} +506 -1876
  21. package/dist/index.browser-D7-FFk3q.js.map +1 -0
  22. package/dist/{index.browser-CZIJCtms.js → index.browser-DlA-NKvf.js} +1223 -2565
  23. package/dist/index.browser-DlA-NKvf.js.map +1 -0
  24. package/dist/{index.browser-DQIwLToJ.esm.js → index.browser-nVGFrIHK.esm.js} +1223 -2565
  25. package/dist/index.browser-nVGFrIHK.esm.js.map +1 -0
  26. package/dist/index.esm.js +1 -1
  27. package/dist/index.js +1 -1
  28. package/dist/{index.native-DLziTime.esm.js → index.native-19VsREMJ.esm.js} +43 -62
  29. package/dist/index.native-19VsREMJ.esm.js.map +1 -0
  30. package/dist/{index.native-pG1NTZ0f.js → index.native-D8vj3Lbr.js} +44 -61
  31. package/dist/index.native-D8vj3Lbr.js.map +1 -0
  32. package/dist/index.native.esm.js +1 -1
  33. package/dist/index.native.js +1 -1
  34. package/dist/{phantom-wallet-provider-zBp7-uEw.js → phantom-wallet-provider-BlZZa_3s.js} +4 -4
  35. package/dist/{phantom-wallet-provider-zBp7-uEw.js.map → phantom-wallet-provider-BlZZa_3s.js.map} +1 -1
  36. package/dist/{phantom-wallet-provider-CP6NXRwG.esm.js → phantom-wallet-provider-Bz3qEFzX.esm.js} +4 -4
  37. package/dist/{phantom-wallet-provider-CP6NXRwG.esm.js.map → phantom-wallet-provider-Bz3qEFzX.esm.js.map} +1 -1
  38. package/dist/{privy-wallet-provider-CoyW5Gdg.js → privy-wallet-provider-CqCgq7uT.js} +3 -3
  39. package/dist/privy-wallet-provider-CqCgq7uT.js.map +1 -0
  40. package/dist/{privy-wallet-provider-CGYvf3-r.esm.js → privy-wallet-provider-DgNFzioA.esm.js} +3 -3
  41. package/dist/privy-wallet-provider-DgNFzioA.esm.js.map +1 -0
  42. package/dist/{solana-mobile-wallet-provider-B8rHfsPN.esm.js → solana-mobile-wallet-provider-EeQsBTdr.esm.js} +385 -60
  43. package/dist/solana-mobile-wallet-provider-EeQsBTdr.esm.js.map +1 -0
  44. package/dist/{solana-mobile-wallet-provider-CN-D_H4l.js → solana-mobile-wallet-provider-VqIGfdMV.js} +385 -60
  45. package/dist/solana-mobile-wallet-provider-VqIGfdMV.js.map +1 -0
  46. package/package.json +1 -1
  47. package/dist/index-B5qYY4YM.js.map +0 -1
  48. package/dist/index-BE-VWSJT.esm.js.map +0 -1
  49. package/dist/index-BaKs3A8s.js.map +0 -1
  50. package/dist/index-BzeiIIwF.js.map +0 -1
  51. package/dist/index-C4AnWFs_.esm.js.map +0 -1
  52. package/dist/index-TzHXEf3-.esm.js +0 -6
  53. package/dist/index-TzHXEf3-.esm.js.map +0 -1
  54. package/dist/index-bEXLwE7_.js.map +0 -1
  55. package/dist/index-dqqR5q7b.esm.js.map +0 -1
  56. package/dist/index.browser-CN6obNQM.js.map +0 -1
  57. package/dist/index.browser-CZIJCtms.js.map +0 -1
  58. package/dist/index.browser-D8ttddP4.esm.js.map +0 -1
  59. package/dist/index.browser-DQIwLToJ.esm.js.map +0 -1
  60. package/dist/index.native-DLziTime.esm.js.map +0 -1
  61. package/dist/index.native-pG1NTZ0f.js.map +0 -1
  62. package/dist/privy-wallet-provider-CGYvf3-r.esm.js.map +0 -1
  63. package/dist/privy-wallet-provider-CoyW5Gdg.js.map +0 -1
  64. package/dist/solana-mobile-wallet-provider-B8rHfsPN.esm.js.map +0 -1
  65. package/dist/solana-mobile-wallet-provider-CN-D_H4l.js.map +0 -1
@@ -2,8 +2,8 @@
2
2
 
3
3
  var React = require('react');
4
4
  var globalAxios = require('axios');
5
- var index = require('./index-B5qYY4YM.js');
6
- var index_native = require('./index.native-pG1NTZ0f.js');
5
+ var index = require('./index-B-x9RTF7.js');
6
+ var index_native = require('./index.native-D8vj3Lbr.js');
7
7
  var web3_js = require('@solana/web3.js');
8
8
  var jsxRuntime = require('react/jsx-runtime');
9
9
  require('@coral-xyz/anchor');
@@ -1019,6 +1019,2410 @@ function isSolanaChain(networkId) {
1019
1019
  return network === "solana";
1020
1020
  }
1021
1021
 
1022
+ var naclFast = {exports: {}};
1023
+
1024
+ var hasRequiredNaclFast;
1025
+
1026
+ function requireNaclFast () {
1027
+ if (hasRequiredNaclFast) return naclFast.exports;
1028
+ hasRequiredNaclFast = 1;
1029
+ (function (module) {
1030
+ (function(nacl) {
1031
+
1032
+ // Ported in 2014 by Dmitry Chestnykh and Devi Mandiri.
1033
+ // Public domain.
1034
+ //
1035
+ // Implementation derived from TweetNaCl version 20140427.
1036
+ // See for details: http://tweetnacl.cr.yp.to/
1037
+
1038
+ var gf = function(init) {
1039
+ var i, r = new Float64Array(16);
1040
+ if (init) for (i = 0; i < init.length; i++) r[i] = init[i];
1041
+ return r;
1042
+ };
1043
+
1044
+ // Pluggable, initialized in high-level API below.
1045
+ var randombytes = function(/* x, n */) { throw new Error('no PRNG'); };
1046
+
1047
+ var _0 = new Uint8Array(16);
1048
+ var _9 = new Uint8Array(32); _9[0] = 9;
1049
+
1050
+ var gf0 = gf(),
1051
+ gf1 = gf([1]),
1052
+ _121665 = gf([0xdb41, 1]),
1053
+ D = gf([0x78a3, 0x1359, 0x4dca, 0x75eb, 0xd8ab, 0x4141, 0x0a4d, 0x0070, 0xe898, 0x7779, 0x4079, 0x8cc7, 0xfe73, 0x2b6f, 0x6cee, 0x5203]),
1054
+ D2 = gf([0xf159, 0x26b2, 0x9b94, 0xebd6, 0xb156, 0x8283, 0x149a, 0x00e0, 0xd130, 0xeef3, 0x80f2, 0x198e, 0xfce7, 0x56df, 0xd9dc, 0x2406]),
1055
+ X = gf([0xd51a, 0x8f25, 0x2d60, 0xc956, 0xa7b2, 0x9525, 0xc760, 0x692c, 0xdc5c, 0xfdd6, 0xe231, 0xc0a4, 0x53fe, 0xcd6e, 0x36d3, 0x2169]),
1056
+ Y = gf([0x6658, 0x6666, 0x6666, 0x6666, 0x6666, 0x6666, 0x6666, 0x6666, 0x6666, 0x6666, 0x6666, 0x6666, 0x6666, 0x6666, 0x6666, 0x6666]),
1057
+ I = gf([0xa0b0, 0x4a0e, 0x1b27, 0xc4ee, 0xe478, 0xad2f, 0x1806, 0x2f43, 0xd7a7, 0x3dfb, 0x0099, 0x2b4d, 0xdf0b, 0x4fc1, 0x2480, 0x2b83]);
1058
+
1059
+ function ts64(x, i, h, l) {
1060
+ x[i] = (h >> 24) & 0xff;
1061
+ x[i+1] = (h >> 16) & 0xff;
1062
+ x[i+2] = (h >> 8) & 0xff;
1063
+ x[i+3] = h & 0xff;
1064
+ x[i+4] = (l >> 24) & 0xff;
1065
+ x[i+5] = (l >> 16) & 0xff;
1066
+ x[i+6] = (l >> 8) & 0xff;
1067
+ x[i+7] = l & 0xff;
1068
+ }
1069
+
1070
+ function vn(x, xi, y, yi, n) {
1071
+ var i,d = 0;
1072
+ for (i = 0; i < n; i++) d |= x[xi+i]^y[yi+i];
1073
+ return (1 & ((d - 1) >>> 8)) - 1;
1074
+ }
1075
+
1076
+ function crypto_verify_16(x, xi, y, yi) {
1077
+ return vn(x,xi,y,yi,16);
1078
+ }
1079
+
1080
+ function crypto_verify_32(x, xi, y, yi) {
1081
+ return vn(x,xi,y,yi,32);
1082
+ }
1083
+
1084
+ function core_salsa20(o, p, k, c) {
1085
+ var j0 = c[ 0] & 0xff | (c[ 1] & 0xff)<<8 | (c[ 2] & 0xff)<<16 | (c[ 3] & 0xff)<<24,
1086
+ j1 = k[ 0] & 0xff | (k[ 1] & 0xff)<<8 | (k[ 2] & 0xff)<<16 | (k[ 3] & 0xff)<<24,
1087
+ j2 = k[ 4] & 0xff | (k[ 5] & 0xff)<<8 | (k[ 6] & 0xff)<<16 | (k[ 7] & 0xff)<<24,
1088
+ j3 = k[ 8] & 0xff | (k[ 9] & 0xff)<<8 | (k[10] & 0xff)<<16 | (k[11] & 0xff)<<24,
1089
+ j4 = k[12] & 0xff | (k[13] & 0xff)<<8 | (k[14] & 0xff)<<16 | (k[15] & 0xff)<<24,
1090
+ j5 = c[ 4] & 0xff | (c[ 5] & 0xff)<<8 | (c[ 6] & 0xff)<<16 | (c[ 7] & 0xff)<<24,
1091
+ j6 = p[ 0] & 0xff | (p[ 1] & 0xff)<<8 | (p[ 2] & 0xff)<<16 | (p[ 3] & 0xff)<<24,
1092
+ j7 = p[ 4] & 0xff | (p[ 5] & 0xff)<<8 | (p[ 6] & 0xff)<<16 | (p[ 7] & 0xff)<<24,
1093
+ j8 = p[ 8] & 0xff | (p[ 9] & 0xff)<<8 | (p[10] & 0xff)<<16 | (p[11] & 0xff)<<24,
1094
+ j9 = p[12] & 0xff | (p[13] & 0xff)<<8 | (p[14] & 0xff)<<16 | (p[15] & 0xff)<<24,
1095
+ j10 = c[ 8] & 0xff | (c[ 9] & 0xff)<<8 | (c[10] & 0xff)<<16 | (c[11] & 0xff)<<24,
1096
+ j11 = k[16] & 0xff | (k[17] & 0xff)<<8 | (k[18] & 0xff)<<16 | (k[19] & 0xff)<<24,
1097
+ j12 = k[20] & 0xff | (k[21] & 0xff)<<8 | (k[22] & 0xff)<<16 | (k[23] & 0xff)<<24,
1098
+ j13 = k[24] & 0xff | (k[25] & 0xff)<<8 | (k[26] & 0xff)<<16 | (k[27] & 0xff)<<24,
1099
+ j14 = k[28] & 0xff | (k[29] & 0xff)<<8 | (k[30] & 0xff)<<16 | (k[31] & 0xff)<<24,
1100
+ j15 = c[12] & 0xff | (c[13] & 0xff)<<8 | (c[14] & 0xff)<<16 | (c[15] & 0xff)<<24;
1101
+
1102
+ var x0 = j0, x1 = j1, x2 = j2, x3 = j3, x4 = j4, x5 = j5, x6 = j6, x7 = j7,
1103
+ x8 = j8, x9 = j9, x10 = j10, x11 = j11, x12 = j12, x13 = j13, x14 = j14,
1104
+ x15 = j15, u;
1105
+
1106
+ for (var i = 0; i < 20; i += 2) {
1107
+ u = x0 + x12 | 0;
1108
+ x4 ^= u<<7 | u>>>(32-7);
1109
+ u = x4 + x0 | 0;
1110
+ x8 ^= u<<9 | u>>>(32-9);
1111
+ u = x8 + x4 | 0;
1112
+ x12 ^= u<<13 | u>>>(32-13);
1113
+ u = x12 + x8 | 0;
1114
+ x0 ^= u<<18 | u>>>(32-18);
1115
+
1116
+ u = x5 + x1 | 0;
1117
+ x9 ^= u<<7 | u>>>(32-7);
1118
+ u = x9 + x5 | 0;
1119
+ x13 ^= u<<9 | u>>>(32-9);
1120
+ u = x13 + x9 | 0;
1121
+ x1 ^= u<<13 | u>>>(32-13);
1122
+ u = x1 + x13 | 0;
1123
+ x5 ^= u<<18 | u>>>(32-18);
1124
+
1125
+ u = x10 + x6 | 0;
1126
+ x14 ^= u<<7 | u>>>(32-7);
1127
+ u = x14 + x10 | 0;
1128
+ x2 ^= u<<9 | u>>>(32-9);
1129
+ u = x2 + x14 | 0;
1130
+ x6 ^= u<<13 | u>>>(32-13);
1131
+ u = x6 + x2 | 0;
1132
+ x10 ^= u<<18 | u>>>(32-18);
1133
+
1134
+ u = x15 + x11 | 0;
1135
+ x3 ^= u<<7 | u>>>(32-7);
1136
+ u = x3 + x15 | 0;
1137
+ x7 ^= u<<9 | u>>>(32-9);
1138
+ u = x7 + x3 | 0;
1139
+ x11 ^= u<<13 | u>>>(32-13);
1140
+ u = x11 + x7 | 0;
1141
+ x15 ^= u<<18 | u>>>(32-18);
1142
+
1143
+ u = x0 + x3 | 0;
1144
+ x1 ^= u<<7 | u>>>(32-7);
1145
+ u = x1 + x0 | 0;
1146
+ x2 ^= u<<9 | u>>>(32-9);
1147
+ u = x2 + x1 | 0;
1148
+ x3 ^= u<<13 | u>>>(32-13);
1149
+ u = x3 + x2 | 0;
1150
+ x0 ^= u<<18 | u>>>(32-18);
1151
+
1152
+ u = x5 + x4 | 0;
1153
+ x6 ^= u<<7 | u>>>(32-7);
1154
+ u = x6 + x5 | 0;
1155
+ x7 ^= u<<9 | u>>>(32-9);
1156
+ u = x7 + x6 | 0;
1157
+ x4 ^= u<<13 | u>>>(32-13);
1158
+ u = x4 + x7 | 0;
1159
+ x5 ^= u<<18 | u>>>(32-18);
1160
+
1161
+ u = x10 + x9 | 0;
1162
+ x11 ^= u<<7 | u>>>(32-7);
1163
+ u = x11 + x10 | 0;
1164
+ x8 ^= u<<9 | u>>>(32-9);
1165
+ u = x8 + x11 | 0;
1166
+ x9 ^= u<<13 | u>>>(32-13);
1167
+ u = x9 + x8 | 0;
1168
+ x10 ^= u<<18 | u>>>(32-18);
1169
+
1170
+ u = x15 + x14 | 0;
1171
+ x12 ^= u<<7 | u>>>(32-7);
1172
+ u = x12 + x15 | 0;
1173
+ x13 ^= u<<9 | u>>>(32-9);
1174
+ u = x13 + x12 | 0;
1175
+ x14 ^= u<<13 | u>>>(32-13);
1176
+ u = x14 + x13 | 0;
1177
+ x15 ^= u<<18 | u>>>(32-18);
1178
+ }
1179
+ x0 = x0 + j0 | 0;
1180
+ x1 = x1 + j1 | 0;
1181
+ x2 = x2 + j2 | 0;
1182
+ x3 = x3 + j3 | 0;
1183
+ x4 = x4 + j4 | 0;
1184
+ x5 = x5 + j5 | 0;
1185
+ x6 = x6 + j6 | 0;
1186
+ x7 = x7 + j7 | 0;
1187
+ x8 = x8 + j8 | 0;
1188
+ x9 = x9 + j9 | 0;
1189
+ x10 = x10 + j10 | 0;
1190
+ x11 = x11 + j11 | 0;
1191
+ x12 = x12 + j12 | 0;
1192
+ x13 = x13 + j13 | 0;
1193
+ x14 = x14 + j14 | 0;
1194
+ x15 = x15 + j15 | 0;
1195
+
1196
+ o[ 0] = x0 >>> 0 & 0xff;
1197
+ o[ 1] = x0 >>> 8 & 0xff;
1198
+ o[ 2] = x0 >>> 16 & 0xff;
1199
+ o[ 3] = x0 >>> 24 & 0xff;
1200
+
1201
+ o[ 4] = x1 >>> 0 & 0xff;
1202
+ o[ 5] = x1 >>> 8 & 0xff;
1203
+ o[ 6] = x1 >>> 16 & 0xff;
1204
+ o[ 7] = x1 >>> 24 & 0xff;
1205
+
1206
+ o[ 8] = x2 >>> 0 & 0xff;
1207
+ o[ 9] = x2 >>> 8 & 0xff;
1208
+ o[10] = x2 >>> 16 & 0xff;
1209
+ o[11] = x2 >>> 24 & 0xff;
1210
+
1211
+ o[12] = x3 >>> 0 & 0xff;
1212
+ o[13] = x3 >>> 8 & 0xff;
1213
+ o[14] = x3 >>> 16 & 0xff;
1214
+ o[15] = x3 >>> 24 & 0xff;
1215
+
1216
+ o[16] = x4 >>> 0 & 0xff;
1217
+ o[17] = x4 >>> 8 & 0xff;
1218
+ o[18] = x4 >>> 16 & 0xff;
1219
+ o[19] = x4 >>> 24 & 0xff;
1220
+
1221
+ o[20] = x5 >>> 0 & 0xff;
1222
+ o[21] = x5 >>> 8 & 0xff;
1223
+ o[22] = x5 >>> 16 & 0xff;
1224
+ o[23] = x5 >>> 24 & 0xff;
1225
+
1226
+ o[24] = x6 >>> 0 & 0xff;
1227
+ o[25] = x6 >>> 8 & 0xff;
1228
+ o[26] = x6 >>> 16 & 0xff;
1229
+ o[27] = x6 >>> 24 & 0xff;
1230
+
1231
+ o[28] = x7 >>> 0 & 0xff;
1232
+ o[29] = x7 >>> 8 & 0xff;
1233
+ o[30] = x7 >>> 16 & 0xff;
1234
+ o[31] = x7 >>> 24 & 0xff;
1235
+
1236
+ o[32] = x8 >>> 0 & 0xff;
1237
+ o[33] = x8 >>> 8 & 0xff;
1238
+ o[34] = x8 >>> 16 & 0xff;
1239
+ o[35] = x8 >>> 24 & 0xff;
1240
+
1241
+ o[36] = x9 >>> 0 & 0xff;
1242
+ o[37] = x9 >>> 8 & 0xff;
1243
+ o[38] = x9 >>> 16 & 0xff;
1244
+ o[39] = x9 >>> 24 & 0xff;
1245
+
1246
+ o[40] = x10 >>> 0 & 0xff;
1247
+ o[41] = x10 >>> 8 & 0xff;
1248
+ o[42] = x10 >>> 16 & 0xff;
1249
+ o[43] = x10 >>> 24 & 0xff;
1250
+
1251
+ o[44] = x11 >>> 0 & 0xff;
1252
+ o[45] = x11 >>> 8 & 0xff;
1253
+ o[46] = x11 >>> 16 & 0xff;
1254
+ o[47] = x11 >>> 24 & 0xff;
1255
+
1256
+ o[48] = x12 >>> 0 & 0xff;
1257
+ o[49] = x12 >>> 8 & 0xff;
1258
+ o[50] = x12 >>> 16 & 0xff;
1259
+ o[51] = x12 >>> 24 & 0xff;
1260
+
1261
+ o[52] = x13 >>> 0 & 0xff;
1262
+ o[53] = x13 >>> 8 & 0xff;
1263
+ o[54] = x13 >>> 16 & 0xff;
1264
+ o[55] = x13 >>> 24 & 0xff;
1265
+
1266
+ o[56] = x14 >>> 0 & 0xff;
1267
+ o[57] = x14 >>> 8 & 0xff;
1268
+ o[58] = x14 >>> 16 & 0xff;
1269
+ o[59] = x14 >>> 24 & 0xff;
1270
+
1271
+ o[60] = x15 >>> 0 & 0xff;
1272
+ o[61] = x15 >>> 8 & 0xff;
1273
+ o[62] = x15 >>> 16 & 0xff;
1274
+ o[63] = x15 >>> 24 & 0xff;
1275
+ }
1276
+
1277
+ function core_hsalsa20(o,p,k,c) {
1278
+ var j0 = c[ 0] & 0xff | (c[ 1] & 0xff)<<8 | (c[ 2] & 0xff)<<16 | (c[ 3] & 0xff)<<24,
1279
+ j1 = k[ 0] & 0xff | (k[ 1] & 0xff)<<8 | (k[ 2] & 0xff)<<16 | (k[ 3] & 0xff)<<24,
1280
+ j2 = k[ 4] & 0xff | (k[ 5] & 0xff)<<8 | (k[ 6] & 0xff)<<16 | (k[ 7] & 0xff)<<24,
1281
+ j3 = k[ 8] & 0xff | (k[ 9] & 0xff)<<8 | (k[10] & 0xff)<<16 | (k[11] & 0xff)<<24,
1282
+ j4 = k[12] & 0xff | (k[13] & 0xff)<<8 | (k[14] & 0xff)<<16 | (k[15] & 0xff)<<24,
1283
+ j5 = c[ 4] & 0xff | (c[ 5] & 0xff)<<8 | (c[ 6] & 0xff)<<16 | (c[ 7] & 0xff)<<24,
1284
+ j6 = p[ 0] & 0xff | (p[ 1] & 0xff)<<8 | (p[ 2] & 0xff)<<16 | (p[ 3] & 0xff)<<24,
1285
+ j7 = p[ 4] & 0xff | (p[ 5] & 0xff)<<8 | (p[ 6] & 0xff)<<16 | (p[ 7] & 0xff)<<24,
1286
+ j8 = p[ 8] & 0xff | (p[ 9] & 0xff)<<8 | (p[10] & 0xff)<<16 | (p[11] & 0xff)<<24,
1287
+ j9 = p[12] & 0xff | (p[13] & 0xff)<<8 | (p[14] & 0xff)<<16 | (p[15] & 0xff)<<24,
1288
+ j10 = c[ 8] & 0xff | (c[ 9] & 0xff)<<8 | (c[10] & 0xff)<<16 | (c[11] & 0xff)<<24,
1289
+ j11 = k[16] & 0xff | (k[17] & 0xff)<<8 | (k[18] & 0xff)<<16 | (k[19] & 0xff)<<24,
1290
+ j12 = k[20] & 0xff | (k[21] & 0xff)<<8 | (k[22] & 0xff)<<16 | (k[23] & 0xff)<<24,
1291
+ j13 = k[24] & 0xff | (k[25] & 0xff)<<8 | (k[26] & 0xff)<<16 | (k[27] & 0xff)<<24,
1292
+ j14 = k[28] & 0xff | (k[29] & 0xff)<<8 | (k[30] & 0xff)<<16 | (k[31] & 0xff)<<24,
1293
+ j15 = c[12] & 0xff | (c[13] & 0xff)<<8 | (c[14] & 0xff)<<16 | (c[15] & 0xff)<<24;
1294
+
1295
+ var x0 = j0, x1 = j1, x2 = j2, x3 = j3, x4 = j4, x5 = j5, x6 = j6, x7 = j7,
1296
+ x8 = j8, x9 = j9, x10 = j10, x11 = j11, x12 = j12, x13 = j13, x14 = j14,
1297
+ x15 = j15, u;
1298
+
1299
+ for (var i = 0; i < 20; i += 2) {
1300
+ u = x0 + x12 | 0;
1301
+ x4 ^= u<<7 | u>>>(32-7);
1302
+ u = x4 + x0 | 0;
1303
+ x8 ^= u<<9 | u>>>(32-9);
1304
+ u = x8 + x4 | 0;
1305
+ x12 ^= u<<13 | u>>>(32-13);
1306
+ u = x12 + x8 | 0;
1307
+ x0 ^= u<<18 | u>>>(32-18);
1308
+
1309
+ u = x5 + x1 | 0;
1310
+ x9 ^= u<<7 | u>>>(32-7);
1311
+ u = x9 + x5 | 0;
1312
+ x13 ^= u<<9 | u>>>(32-9);
1313
+ u = x13 + x9 | 0;
1314
+ x1 ^= u<<13 | u>>>(32-13);
1315
+ u = x1 + x13 | 0;
1316
+ x5 ^= u<<18 | u>>>(32-18);
1317
+
1318
+ u = x10 + x6 | 0;
1319
+ x14 ^= u<<7 | u>>>(32-7);
1320
+ u = x14 + x10 | 0;
1321
+ x2 ^= u<<9 | u>>>(32-9);
1322
+ u = x2 + x14 | 0;
1323
+ x6 ^= u<<13 | u>>>(32-13);
1324
+ u = x6 + x2 | 0;
1325
+ x10 ^= u<<18 | u>>>(32-18);
1326
+
1327
+ u = x15 + x11 | 0;
1328
+ x3 ^= u<<7 | u>>>(32-7);
1329
+ u = x3 + x15 | 0;
1330
+ x7 ^= u<<9 | u>>>(32-9);
1331
+ u = x7 + x3 | 0;
1332
+ x11 ^= u<<13 | u>>>(32-13);
1333
+ u = x11 + x7 | 0;
1334
+ x15 ^= u<<18 | u>>>(32-18);
1335
+
1336
+ u = x0 + x3 | 0;
1337
+ x1 ^= u<<7 | u>>>(32-7);
1338
+ u = x1 + x0 | 0;
1339
+ x2 ^= u<<9 | u>>>(32-9);
1340
+ u = x2 + x1 | 0;
1341
+ x3 ^= u<<13 | u>>>(32-13);
1342
+ u = x3 + x2 | 0;
1343
+ x0 ^= u<<18 | u>>>(32-18);
1344
+
1345
+ u = x5 + x4 | 0;
1346
+ x6 ^= u<<7 | u>>>(32-7);
1347
+ u = x6 + x5 | 0;
1348
+ x7 ^= u<<9 | u>>>(32-9);
1349
+ u = x7 + x6 | 0;
1350
+ x4 ^= u<<13 | u>>>(32-13);
1351
+ u = x4 + x7 | 0;
1352
+ x5 ^= u<<18 | u>>>(32-18);
1353
+
1354
+ u = x10 + x9 | 0;
1355
+ x11 ^= u<<7 | u>>>(32-7);
1356
+ u = x11 + x10 | 0;
1357
+ x8 ^= u<<9 | u>>>(32-9);
1358
+ u = x8 + x11 | 0;
1359
+ x9 ^= u<<13 | u>>>(32-13);
1360
+ u = x9 + x8 | 0;
1361
+ x10 ^= u<<18 | u>>>(32-18);
1362
+
1363
+ u = x15 + x14 | 0;
1364
+ x12 ^= u<<7 | u>>>(32-7);
1365
+ u = x12 + x15 | 0;
1366
+ x13 ^= u<<9 | u>>>(32-9);
1367
+ u = x13 + x12 | 0;
1368
+ x14 ^= u<<13 | u>>>(32-13);
1369
+ u = x14 + x13 | 0;
1370
+ x15 ^= u<<18 | u>>>(32-18);
1371
+ }
1372
+
1373
+ o[ 0] = x0 >>> 0 & 0xff;
1374
+ o[ 1] = x0 >>> 8 & 0xff;
1375
+ o[ 2] = x0 >>> 16 & 0xff;
1376
+ o[ 3] = x0 >>> 24 & 0xff;
1377
+
1378
+ o[ 4] = x5 >>> 0 & 0xff;
1379
+ o[ 5] = x5 >>> 8 & 0xff;
1380
+ o[ 6] = x5 >>> 16 & 0xff;
1381
+ o[ 7] = x5 >>> 24 & 0xff;
1382
+
1383
+ o[ 8] = x10 >>> 0 & 0xff;
1384
+ o[ 9] = x10 >>> 8 & 0xff;
1385
+ o[10] = x10 >>> 16 & 0xff;
1386
+ o[11] = x10 >>> 24 & 0xff;
1387
+
1388
+ o[12] = x15 >>> 0 & 0xff;
1389
+ o[13] = x15 >>> 8 & 0xff;
1390
+ o[14] = x15 >>> 16 & 0xff;
1391
+ o[15] = x15 >>> 24 & 0xff;
1392
+
1393
+ o[16] = x6 >>> 0 & 0xff;
1394
+ o[17] = x6 >>> 8 & 0xff;
1395
+ o[18] = x6 >>> 16 & 0xff;
1396
+ o[19] = x6 >>> 24 & 0xff;
1397
+
1398
+ o[20] = x7 >>> 0 & 0xff;
1399
+ o[21] = x7 >>> 8 & 0xff;
1400
+ o[22] = x7 >>> 16 & 0xff;
1401
+ o[23] = x7 >>> 24 & 0xff;
1402
+
1403
+ o[24] = x8 >>> 0 & 0xff;
1404
+ o[25] = x8 >>> 8 & 0xff;
1405
+ o[26] = x8 >>> 16 & 0xff;
1406
+ o[27] = x8 >>> 24 & 0xff;
1407
+
1408
+ o[28] = x9 >>> 0 & 0xff;
1409
+ o[29] = x9 >>> 8 & 0xff;
1410
+ o[30] = x9 >>> 16 & 0xff;
1411
+ o[31] = x9 >>> 24 & 0xff;
1412
+ }
1413
+
1414
+ function crypto_core_salsa20(out,inp,k,c) {
1415
+ core_salsa20(out,inp,k,c);
1416
+ }
1417
+
1418
+ function crypto_core_hsalsa20(out,inp,k,c) {
1419
+ core_hsalsa20(out,inp,k,c);
1420
+ }
1421
+
1422
+ var sigma = new Uint8Array([101, 120, 112, 97, 110, 100, 32, 51, 50, 45, 98, 121, 116, 101, 32, 107]);
1423
+ // "expand 32-byte k"
1424
+
1425
+ function crypto_stream_salsa20_xor(c,cpos,m,mpos,b,n,k) {
1426
+ var z = new Uint8Array(16), x = new Uint8Array(64);
1427
+ var u, i;
1428
+ for (i = 0; i < 16; i++) z[i] = 0;
1429
+ for (i = 0; i < 8; i++) z[i] = n[i];
1430
+ while (b >= 64) {
1431
+ crypto_core_salsa20(x,z,k,sigma);
1432
+ for (i = 0; i < 64; i++) c[cpos+i] = m[mpos+i] ^ x[i];
1433
+ u = 1;
1434
+ for (i = 8; i < 16; i++) {
1435
+ u = u + (z[i] & 0xff) | 0;
1436
+ z[i] = u & 0xff;
1437
+ u >>>= 8;
1438
+ }
1439
+ b -= 64;
1440
+ cpos += 64;
1441
+ mpos += 64;
1442
+ }
1443
+ if (b > 0) {
1444
+ crypto_core_salsa20(x,z,k,sigma);
1445
+ for (i = 0; i < b; i++) c[cpos+i] = m[mpos+i] ^ x[i];
1446
+ }
1447
+ return 0;
1448
+ }
1449
+
1450
+ function crypto_stream_salsa20(c,cpos,b,n,k) {
1451
+ var z = new Uint8Array(16), x = new Uint8Array(64);
1452
+ var u, i;
1453
+ for (i = 0; i < 16; i++) z[i] = 0;
1454
+ for (i = 0; i < 8; i++) z[i] = n[i];
1455
+ while (b >= 64) {
1456
+ crypto_core_salsa20(x,z,k,sigma);
1457
+ for (i = 0; i < 64; i++) c[cpos+i] = x[i];
1458
+ u = 1;
1459
+ for (i = 8; i < 16; i++) {
1460
+ u = u + (z[i] & 0xff) | 0;
1461
+ z[i] = u & 0xff;
1462
+ u >>>= 8;
1463
+ }
1464
+ b -= 64;
1465
+ cpos += 64;
1466
+ }
1467
+ if (b > 0) {
1468
+ crypto_core_salsa20(x,z,k,sigma);
1469
+ for (i = 0; i < b; i++) c[cpos+i] = x[i];
1470
+ }
1471
+ return 0;
1472
+ }
1473
+
1474
+ function crypto_stream(c,cpos,d,n,k) {
1475
+ var s = new Uint8Array(32);
1476
+ crypto_core_hsalsa20(s,n,k,sigma);
1477
+ var sn = new Uint8Array(8);
1478
+ for (var i = 0; i < 8; i++) sn[i] = n[i+16];
1479
+ return crypto_stream_salsa20(c,cpos,d,sn,s);
1480
+ }
1481
+
1482
+ function crypto_stream_xor(c,cpos,m,mpos,d,n,k) {
1483
+ var s = new Uint8Array(32);
1484
+ crypto_core_hsalsa20(s,n,k,sigma);
1485
+ var sn = new Uint8Array(8);
1486
+ for (var i = 0; i < 8; i++) sn[i] = n[i+16];
1487
+ return crypto_stream_salsa20_xor(c,cpos,m,mpos,d,sn,s);
1488
+ }
1489
+
1490
+ /*
1491
+ * Port of Andrew Moon's Poly1305-donna-16. Public domain.
1492
+ * https://github.com/floodyberry/poly1305-donna
1493
+ */
1494
+
1495
+ var poly1305 = function(key) {
1496
+ this.buffer = new Uint8Array(16);
1497
+ this.r = new Uint16Array(10);
1498
+ this.h = new Uint16Array(10);
1499
+ this.pad = new Uint16Array(8);
1500
+ this.leftover = 0;
1501
+ this.fin = 0;
1502
+
1503
+ var t0, t1, t2, t3, t4, t5, t6, t7;
1504
+
1505
+ t0 = key[ 0] & 0xff | (key[ 1] & 0xff) << 8; this.r[0] = ( t0 ) & 0x1fff;
1506
+ t1 = key[ 2] & 0xff | (key[ 3] & 0xff) << 8; this.r[1] = ((t0 >>> 13) | (t1 << 3)) & 0x1fff;
1507
+ t2 = key[ 4] & 0xff | (key[ 5] & 0xff) << 8; this.r[2] = ((t1 >>> 10) | (t2 << 6)) & 0x1f03;
1508
+ t3 = key[ 6] & 0xff | (key[ 7] & 0xff) << 8; this.r[3] = ((t2 >>> 7) | (t3 << 9)) & 0x1fff;
1509
+ t4 = key[ 8] & 0xff | (key[ 9] & 0xff) << 8; this.r[4] = ((t3 >>> 4) | (t4 << 12)) & 0x00ff;
1510
+ this.r[5] = ((t4 >>> 1)) & 0x1ffe;
1511
+ t5 = key[10] & 0xff | (key[11] & 0xff) << 8; this.r[6] = ((t4 >>> 14) | (t5 << 2)) & 0x1fff;
1512
+ t6 = key[12] & 0xff | (key[13] & 0xff) << 8; this.r[7] = ((t5 >>> 11) | (t6 << 5)) & 0x1f81;
1513
+ t7 = key[14] & 0xff | (key[15] & 0xff) << 8; this.r[8] = ((t6 >>> 8) | (t7 << 8)) & 0x1fff;
1514
+ this.r[9] = ((t7 >>> 5)) & 0x007f;
1515
+
1516
+ this.pad[0] = key[16] & 0xff | (key[17] & 0xff) << 8;
1517
+ this.pad[1] = key[18] & 0xff | (key[19] & 0xff) << 8;
1518
+ this.pad[2] = key[20] & 0xff | (key[21] & 0xff) << 8;
1519
+ this.pad[3] = key[22] & 0xff | (key[23] & 0xff) << 8;
1520
+ this.pad[4] = key[24] & 0xff | (key[25] & 0xff) << 8;
1521
+ this.pad[5] = key[26] & 0xff | (key[27] & 0xff) << 8;
1522
+ this.pad[6] = key[28] & 0xff | (key[29] & 0xff) << 8;
1523
+ this.pad[7] = key[30] & 0xff | (key[31] & 0xff) << 8;
1524
+ };
1525
+
1526
+ poly1305.prototype.blocks = function(m, mpos, bytes) {
1527
+ var hibit = this.fin ? 0 : (1 << 11);
1528
+ var t0, t1, t2, t3, t4, t5, t6, t7, c;
1529
+ var d0, d1, d2, d3, d4, d5, d6, d7, d8, d9;
1530
+
1531
+ var h0 = this.h[0],
1532
+ h1 = this.h[1],
1533
+ h2 = this.h[2],
1534
+ h3 = this.h[3],
1535
+ h4 = this.h[4],
1536
+ h5 = this.h[5],
1537
+ h6 = this.h[6],
1538
+ h7 = this.h[7],
1539
+ h8 = this.h[8],
1540
+ h9 = this.h[9];
1541
+
1542
+ var r0 = this.r[0],
1543
+ r1 = this.r[1],
1544
+ r2 = this.r[2],
1545
+ r3 = this.r[3],
1546
+ r4 = this.r[4],
1547
+ r5 = this.r[5],
1548
+ r6 = this.r[6],
1549
+ r7 = this.r[7],
1550
+ r8 = this.r[8],
1551
+ r9 = this.r[9];
1552
+
1553
+ while (bytes >= 16) {
1554
+ t0 = m[mpos+ 0] & 0xff | (m[mpos+ 1] & 0xff) << 8; h0 += ( t0 ) & 0x1fff;
1555
+ t1 = m[mpos+ 2] & 0xff | (m[mpos+ 3] & 0xff) << 8; h1 += ((t0 >>> 13) | (t1 << 3)) & 0x1fff;
1556
+ t2 = m[mpos+ 4] & 0xff | (m[mpos+ 5] & 0xff) << 8; h2 += ((t1 >>> 10) | (t2 << 6)) & 0x1fff;
1557
+ t3 = m[mpos+ 6] & 0xff | (m[mpos+ 7] & 0xff) << 8; h3 += ((t2 >>> 7) | (t3 << 9)) & 0x1fff;
1558
+ t4 = m[mpos+ 8] & 0xff | (m[mpos+ 9] & 0xff) << 8; h4 += ((t3 >>> 4) | (t4 << 12)) & 0x1fff;
1559
+ h5 += ((t4 >>> 1)) & 0x1fff;
1560
+ t5 = m[mpos+10] & 0xff | (m[mpos+11] & 0xff) << 8; h6 += ((t4 >>> 14) | (t5 << 2)) & 0x1fff;
1561
+ t6 = m[mpos+12] & 0xff | (m[mpos+13] & 0xff) << 8; h7 += ((t5 >>> 11) | (t6 << 5)) & 0x1fff;
1562
+ t7 = m[mpos+14] & 0xff | (m[mpos+15] & 0xff) << 8; h8 += ((t6 >>> 8) | (t7 << 8)) & 0x1fff;
1563
+ h9 += ((t7 >>> 5)) | hibit;
1564
+
1565
+ c = 0;
1566
+
1567
+ d0 = c;
1568
+ d0 += h0 * r0;
1569
+ d0 += h1 * (5 * r9);
1570
+ d0 += h2 * (5 * r8);
1571
+ d0 += h3 * (5 * r7);
1572
+ d0 += h4 * (5 * r6);
1573
+ c = (d0 >>> 13); d0 &= 0x1fff;
1574
+ d0 += h5 * (5 * r5);
1575
+ d0 += h6 * (5 * r4);
1576
+ d0 += h7 * (5 * r3);
1577
+ d0 += h8 * (5 * r2);
1578
+ d0 += h9 * (5 * r1);
1579
+ c += (d0 >>> 13); d0 &= 0x1fff;
1580
+
1581
+ d1 = c;
1582
+ d1 += h0 * r1;
1583
+ d1 += h1 * r0;
1584
+ d1 += h2 * (5 * r9);
1585
+ d1 += h3 * (5 * r8);
1586
+ d1 += h4 * (5 * r7);
1587
+ c = (d1 >>> 13); d1 &= 0x1fff;
1588
+ d1 += h5 * (5 * r6);
1589
+ d1 += h6 * (5 * r5);
1590
+ d1 += h7 * (5 * r4);
1591
+ d1 += h8 * (5 * r3);
1592
+ d1 += h9 * (5 * r2);
1593
+ c += (d1 >>> 13); d1 &= 0x1fff;
1594
+
1595
+ d2 = c;
1596
+ d2 += h0 * r2;
1597
+ d2 += h1 * r1;
1598
+ d2 += h2 * r0;
1599
+ d2 += h3 * (5 * r9);
1600
+ d2 += h4 * (5 * r8);
1601
+ c = (d2 >>> 13); d2 &= 0x1fff;
1602
+ d2 += h5 * (5 * r7);
1603
+ d2 += h6 * (5 * r6);
1604
+ d2 += h7 * (5 * r5);
1605
+ d2 += h8 * (5 * r4);
1606
+ d2 += h9 * (5 * r3);
1607
+ c += (d2 >>> 13); d2 &= 0x1fff;
1608
+
1609
+ d3 = c;
1610
+ d3 += h0 * r3;
1611
+ d3 += h1 * r2;
1612
+ d3 += h2 * r1;
1613
+ d3 += h3 * r0;
1614
+ d3 += h4 * (5 * r9);
1615
+ c = (d3 >>> 13); d3 &= 0x1fff;
1616
+ d3 += h5 * (5 * r8);
1617
+ d3 += h6 * (5 * r7);
1618
+ d3 += h7 * (5 * r6);
1619
+ d3 += h8 * (5 * r5);
1620
+ d3 += h9 * (5 * r4);
1621
+ c += (d3 >>> 13); d3 &= 0x1fff;
1622
+
1623
+ d4 = c;
1624
+ d4 += h0 * r4;
1625
+ d4 += h1 * r3;
1626
+ d4 += h2 * r2;
1627
+ d4 += h3 * r1;
1628
+ d4 += h4 * r0;
1629
+ c = (d4 >>> 13); d4 &= 0x1fff;
1630
+ d4 += h5 * (5 * r9);
1631
+ d4 += h6 * (5 * r8);
1632
+ d4 += h7 * (5 * r7);
1633
+ d4 += h8 * (5 * r6);
1634
+ d4 += h9 * (5 * r5);
1635
+ c += (d4 >>> 13); d4 &= 0x1fff;
1636
+
1637
+ d5 = c;
1638
+ d5 += h0 * r5;
1639
+ d5 += h1 * r4;
1640
+ d5 += h2 * r3;
1641
+ d5 += h3 * r2;
1642
+ d5 += h4 * r1;
1643
+ c = (d5 >>> 13); d5 &= 0x1fff;
1644
+ d5 += h5 * r0;
1645
+ d5 += h6 * (5 * r9);
1646
+ d5 += h7 * (5 * r8);
1647
+ d5 += h8 * (5 * r7);
1648
+ d5 += h9 * (5 * r6);
1649
+ c += (d5 >>> 13); d5 &= 0x1fff;
1650
+
1651
+ d6 = c;
1652
+ d6 += h0 * r6;
1653
+ d6 += h1 * r5;
1654
+ d6 += h2 * r4;
1655
+ d6 += h3 * r3;
1656
+ d6 += h4 * r2;
1657
+ c = (d6 >>> 13); d6 &= 0x1fff;
1658
+ d6 += h5 * r1;
1659
+ d6 += h6 * r0;
1660
+ d6 += h7 * (5 * r9);
1661
+ d6 += h8 * (5 * r8);
1662
+ d6 += h9 * (5 * r7);
1663
+ c += (d6 >>> 13); d6 &= 0x1fff;
1664
+
1665
+ d7 = c;
1666
+ d7 += h0 * r7;
1667
+ d7 += h1 * r6;
1668
+ d7 += h2 * r5;
1669
+ d7 += h3 * r4;
1670
+ d7 += h4 * r3;
1671
+ c = (d7 >>> 13); d7 &= 0x1fff;
1672
+ d7 += h5 * r2;
1673
+ d7 += h6 * r1;
1674
+ d7 += h7 * r0;
1675
+ d7 += h8 * (5 * r9);
1676
+ d7 += h9 * (5 * r8);
1677
+ c += (d7 >>> 13); d7 &= 0x1fff;
1678
+
1679
+ d8 = c;
1680
+ d8 += h0 * r8;
1681
+ d8 += h1 * r7;
1682
+ d8 += h2 * r6;
1683
+ d8 += h3 * r5;
1684
+ d8 += h4 * r4;
1685
+ c = (d8 >>> 13); d8 &= 0x1fff;
1686
+ d8 += h5 * r3;
1687
+ d8 += h6 * r2;
1688
+ d8 += h7 * r1;
1689
+ d8 += h8 * r0;
1690
+ d8 += h9 * (5 * r9);
1691
+ c += (d8 >>> 13); d8 &= 0x1fff;
1692
+
1693
+ d9 = c;
1694
+ d9 += h0 * r9;
1695
+ d9 += h1 * r8;
1696
+ d9 += h2 * r7;
1697
+ d9 += h3 * r6;
1698
+ d9 += h4 * r5;
1699
+ c = (d9 >>> 13); d9 &= 0x1fff;
1700
+ d9 += h5 * r4;
1701
+ d9 += h6 * r3;
1702
+ d9 += h7 * r2;
1703
+ d9 += h8 * r1;
1704
+ d9 += h9 * r0;
1705
+ c += (d9 >>> 13); d9 &= 0x1fff;
1706
+
1707
+ c = (((c << 2) + c)) | 0;
1708
+ c = (c + d0) | 0;
1709
+ d0 = c & 0x1fff;
1710
+ c = (c >>> 13);
1711
+ d1 += c;
1712
+
1713
+ h0 = d0;
1714
+ h1 = d1;
1715
+ h2 = d2;
1716
+ h3 = d3;
1717
+ h4 = d4;
1718
+ h5 = d5;
1719
+ h6 = d6;
1720
+ h7 = d7;
1721
+ h8 = d8;
1722
+ h9 = d9;
1723
+
1724
+ mpos += 16;
1725
+ bytes -= 16;
1726
+ }
1727
+ this.h[0] = h0;
1728
+ this.h[1] = h1;
1729
+ this.h[2] = h2;
1730
+ this.h[3] = h3;
1731
+ this.h[4] = h4;
1732
+ this.h[5] = h5;
1733
+ this.h[6] = h6;
1734
+ this.h[7] = h7;
1735
+ this.h[8] = h8;
1736
+ this.h[9] = h9;
1737
+ };
1738
+
1739
+ poly1305.prototype.finish = function(mac, macpos) {
1740
+ var g = new Uint16Array(10);
1741
+ var c, mask, f, i;
1742
+
1743
+ if (this.leftover) {
1744
+ i = this.leftover;
1745
+ this.buffer[i++] = 1;
1746
+ for (; i < 16; i++) this.buffer[i] = 0;
1747
+ this.fin = 1;
1748
+ this.blocks(this.buffer, 0, 16);
1749
+ }
1750
+
1751
+ c = this.h[1] >>> 13;
1752
+ this.h[1] &= 0x1fff;
1753
+ for (i = 2; i < 10; i++) {
1754
+ this.h[i] += c;
1755
+ c = this.h[i] >>> 13;
1756
+ this.h[i] &= 0x1fff;
1757
+ }
1758
+ this.h[0] += (c * 5);
1759
+ c = this.h[0] >>> 13;
1760
+ this.h[0] &= 0x1fff;
1761
+ this.h[1] += c;
1762
+ c = this.h[1] >>> 13;
1763
+ this.h[1] &= 0x1fff;
1764
+ this.h[2] += c;
1765
+
1766
+ g[0] = this.h[0] + 5;
1767
+ c = g[0] >>> 13;
1768
+ g[0] &= 0x1fff;
1769
+ for (i = 1; i < 10; i++) {
1770
+ g[i] = this.h[i] + c;
1771
+ c = g[i] >>> 13;
1772
+ g[i] &= 0x1fff;
1773
+ }
1774
+ g[9] -= (1 << 13);
1775
+
1776
+ mask = (c ^ 1) - 1;
1777
+ for (i = 0; i < 10; i++) g[i] &= mask;
1778
+ mask = ~mask;
1779
+ for (i = 0; i < 10; i++) this.h[i] = (this.h[i] & mask) | g[i];
1780
+
1781
+ this.h[0] = ((this.h[0] ) | (this.h[1] << 13) ) & 0xffff;
1782
+ this.h[1] = ((this.h[1] >>> 3) | (this.h[2] << 10) ) & 0xffff;
1783
+ this.h[2] = ((this.h[2] >>> 6) | (this.h[3] << 7) ) & 0xffff;
1784
+ this.h[3] = ((this.h[3] >>> 9) | (this.h[4] << 4) ) & 0xffff;
1785
+ this.h[4] = ((this.h[4] >>> 12) | (this.h[5] << 1) | (this.h[6] << 14)) & 0xffff;
1786
+ this.h[5] = ((this.h[6] >>> 2) | (this.h[7] << 11) ) & 0xffff;
1787
+ this.h[6] = ((this.h[7] >>> 5) | (this.h[8] << 8) ) & 0xffff;
1788
+ this.h[7] = ((this.h[8] >>> 8) | (this.h[9] << 5) ) & 0xffff;
1789
+
1790
+ f = this.h[0] + this.pad[0];
1791
+ this.h[0] = f & 0xffff;
1792
+ for (i = 1; i < 8; i++) {
1793
+ f = (((this.h[i] + this.pad[i]) | 0) + (f >>> 16)) | 0;
1794
+ this.h[i] = f & 0xffff;
1795
+ }
1796
+
1797
+ mac[macpos+ 0] = (this.h[0] >>> 0) & 0xff;
1798
+ mac[macpos+ 1] = (this.h[0] >>> 8) & 0xff;
1799
+ mac[macpos+ 2] = (this.h[1] >>> 0) & 0xff;
1800
+ mac[macpos+ 3] = (this.h[1] >>> 8) & 0xff;
1801
+ mac[macpos+ 4] = (this.h[2] >>> 0) & 0xff;
1802
+ mac[macpos+ 5] = (this.h[2] >>> 8) & 0xff;
1803
+ mac[macpos+ 6] = (this.h[3] >>> 0) & 0xff;
1804
+ mac[macpos+ 7] = (this.h[3] >>> 8) & 0xff;
1805
+ mac[macpos+ 8] = (this.h[4] >>> 0) & 0xff;
1806
+ mac[macpos+ 9] = (this.h[4] >>> 8) & 0xff;
1807
+ mac[macpos+10] = (this.h[5] >>> 0) & 0xff;
1808
+ mac[macpos+11] = (this.h[5] >>> 8) & 0xff;
1809
+ mac[macpos+12] = (this.h[6] >>> 0) & 0xff;
1810
+ mac[macpos+13] = (this.h[6] >>> 8) & 0xff;
1811
+ mac[macpos+14] = (this.h[7] >>> 0) & 0xff;
1812
+ mac[macpos+15] = (this.h[7] >>> 8) & 0xff;
1813
+ };
1814
+
1815
+ poly1305.prototype.update = function(m, mpos, bytes) {
1816
+ var i, want;
1817
+
1818
+ if (this.leftover) {
1819
+ want = (16 - this.leftover);
1820
+ if (want > bytes)
1821
+ want = bytes;
1822
+ for (i = 0; i < want; i++)
1823
+ this.buffer[this.leftover + i] = m[mpos+i];
1824
+ bytes -= want;
1825
+ mpos += want;
1826
+ this.leftover += want;
1827
+ if (this.leftover < 16)
1828
+ return;
1829
+ this.blocks(this.buffer, 0, 16);
1830
+ this.leftover = 0;
1831
+ }
1832
+
1833
+ if (bytes >= 16) {
1834
+ want = bytes - (bytes % 16);
1835
+ this.blocks(m, mpos, want);
1836
+ mpos += want;
1837
+ bytes -= want;
1838
+ }
1839
+
1840
+ if (bytes) {
1841
+ for (i = 0; i < bytes; i++)
1842
+ this.buffer[this.leftover + i] = m[mpos+i];
1843
+ this.leftover += bytes;
1844
+ }
1845
+ };
1846
+
1847
+ function crypto_onetimeauth(out, outpos, m, mpos, n, k) {
1848
+ var s = new poly1305(k);
1849
+ s.update(m, mpos, n);
1850
+ s.finish(out, outpos);
1851
+ return 0;
1852
+ }
1853
+
1854
+ function crypto_onetimeauth_verify(h, hpos, m, mpos, n, k) {
1855
+ var x = new Uint8Array(16);
1856
+ crypto_onetimeauth(x,0,m,mpos,n,k);
1857
+ return crypto_verify_16(h,hpos,x,0);
1858
+ }
1859
+
1860
+ function crypto_secretbox(c,m,d,n,k) {
1861
+ var i;
1862
+ if (d < 32) return -1;
1863
+ crypto_stream_xor(c,0,m,0,d,n,k);
1864
+ crypto_onetimeauth(c, 16, c, 32, d - 32, c);
1865
+ for (i = 0; i < 16; i++) c[i] = 0;
1866
+ return 0;
1867
+ }
1868
+
1869
+ function crypto_secretbox_open(m,c,d,n,k) {
1870
+ var i;
1871
+ var x = new Uint8Array(32);
1872
+ if (d < 32) return -1;
1873
+ crypto_stream(x,0,32,n,k);
1874
+ if (crypto_onetimeauth_verify(c, 16,c, 32,d - 32,x) !== 0) return -1;
1875
+ crypto_stream_xor(m,0,c,0,d,n,k);
1876
+ for (i = 0; i < 32; i++) m[i] = 0;
1877
+ return 0;
1878
+ }
1879
+
1880
+ function set25519(r, a) {
1881
+ var i;
1882
+ for (i = 0; i < 16; i++) r[i] = a[i]|0;
1883
+ }
1884
+
1885
+ function car25519(o) {
1886
+ var i, v, c = 1;
1887
+ for (i = 0; i < 16; i++) {
1888
+ v = o[i] + c + 65535;
1889
+ c = Math.floor(v / 65536);
1890
+ o[i] = v - c * 65536;
1891
+ }
1892
+ o[0] += c-1 + 37 * (c-1);
1893
+ }
1894
+
1895
+ function sel25519(p, q, b) {
1896
+ var t, c = ~(b-1);
1897
+ for (var i = 0; i < 16; i++) {
1898
+ t = c & (p[i] ^ q[i]);
1899
+ p[i] ^= t;
1900
+ q[i] ^= t;
1901
+ }
1902
+ }
1903
+
1904
+ function pack25519(o, n) {
1905
+ var i, j, b;
1906
+ var m = gf(), t = gf();
1907
+ for (i = 0; i < 16; i++) t[i] = n[i];
1908
+ car25519(t);
1909
+ car25519(t);
1910
+ car25519(t);
1911
+ for (j = 0; j < 2; j++) {
1912
+ m[0] = t[0] - 0xffed;
1913
+ for (i = 1; i < 15; i++) {
1914
+ m[i] = t[i] - 0xffff - ((m[i-1]>>16) & 1);
1915
+ m[i-1] &= 0xffff;
1916
+ }
1917
+ m[15] = t[15] - 0x7fff - ((m[14]>>16) & 1);
1918
+ b = (m[15]>>16) & 1;
1919
+ m[14] &= 0xffff;
1920
+ sel25519(t, m, 1-b);
1921
+ }
1922
+ for (i = 0; i < 16; i++) {
1923
+ o[2*i] = t[i] & 0xff;
1924
+ o[2*i+1] = t[i]>>8;
1925
+ }
1926
+ }
1927
+
1928
+ function neq25519(a, b) {
1929
+ var c = new Uint8Array(32), d = new Uint8Array(32);
1930
+ pack25519(c, a);
1931
+ pack25519(d, b);
1932
+ return crypto_verify_32(c, 0, d, 0);
1933
+ }
1934
+
1935
+ function par25519(a) {
1936
+ var d = new Uint8Array(32);
1937
+ pack25519(d, a);
1938
+ return d[0] & 1;
1939
+ }
1940
+
1941
+ function unpack25519(o, n) {
1942
+ var i;
1943
+ for (i = 0; i < 16; i++) o[i] = n[2*i] + (n[2*i+1] << 8);
1944
+ o[15] &= 0x7fff;
1945
+ }
1946
+
1947
+ function A(o, a, b) {
1948
+ for (var i = 0; i < 16; i++) o[i] = a[i] + b[i];
1949
+ }
1950
+
1951
+ function Z(o, a, b) {
1952
+ for (var i = 0; i < 16; i++) o[i] = a[i] - b[i];
1953
+ }
1954
+
1955
+ function M(o, a, b) {
1956
+ var v, c,
1957
+ t0 = 0, t1 = 0, t2 = 0, t3 = 0, t4 = 0, t5 = 0, t6 = 0, t7 = 0,
1958
+ t8 = 0, t9 = 0, t10 = 0, t11 = 0, t12 = 0, t13 = 0, t14 = 0, t15 = 0,
1959
+ t16 = 0, t17 = 0, t18 = 0, t19 = 0, t20 = 0, t21 = 0, t22 = 0, t23 = 0,
1960
+ t24 = 0, t25 = 0, t26 = 0, t27 = 0, t28 = 0, t29 = 0, t30 = 0,
1961
+ b0 = b[0],
1962
+ b1 = b[1],
1963
+ b2 = b[2],
1964
+ b3 = b[3],
1965
+ b4 = b[4],
1966
+ b5 = b[5],
1967
+ b6 = b[6],
1968
+ b7 = b[7],
1969
+ b8 = b[8],
1970
+ b9 = b[9],
1971
+ b10 = b[10],
1972
+ b11 = b[11],
1973
+ b12 = b[12],
1974
+ b13 = b[13],
1975
+ b14 = b[14],
1976
+ b15 = b[15];
1977
+
1978
+ v = a[0];
1979
+ t0 += v * b0;
1980
+ t1 += v * b1;
1981
+ t2 += v * b2;
1982
+ t3 += v * b3;
1983
+ t4 += v * b4;
1984
+ t5 += v * b5;
1985
+ t6 += v * b6;
1986
+ t7 += v * b7;
1987
+ t8 += v * b8;
1988
+ t9 += v * b9;
1989
+ t10 += v * b10;
1990
+ t11 += v * b11;
1991
+ t12 += v * b12;
1992
+ t13 += v * b13;
1993
+ t14 += v * b14;
1994
+ t15 += v * b15;
1995
+ v = a[1];
1996
+ t1 += v * b0;
1997
+ t2 += v * b1;
1998
+ t3 += v * b2;
1999
+ t4 += v * b3;
2000
+ t5 += v * b4;
2001
+ t6 += v * b5;
2002
+ t7 += v * b6;
2003
+ t8 += v * b7;
2004
+ t9 += v * b8;
2005
+ t10 += v * b9;
2006
+ t11 += v * b10;
2007
+ t12 += v * b11;
2008
+ t13 += v * b12;
2009
+ t14 += v * b13;
2010
+ t15 += v * b14;
2011
+ t16 += v * b15;
2012
+ v = a[2];
2013
+ t2 += v * b0;
2014
+ t3 += v * b1;
2015
+ t4 += v * b2;
2016
+ t5 += v * b3;
2017
+ t6 += v * b4;
2018
+ t7 += v * b5;
2019
+ t8 += v * b6;
2020
+ t9 += v * b7;
2021
+ t10 += v * b8;
2022
+ t11 += v * b9;
2023
+ t12 += v * b10;
2024
+ t13 += v * b11;
2025
+ t14 += v * b12;
2026
+ t15 += v * b13;
2027
+ t16 += v * b14;
2028
+ t17 += v * b15;
2029
+ v = a[3];
2030
+ t3 += v * b0;
2031
+ t4 += v * b1;
2032
+ t5 += v * b2;
2033
+ t6 += v * b3;
2034
+ t7 += v * b4;
2035
+ t8 += v * b5;
2036
+ t9 += v * b6;
2037
+ t10 += v * b7;
2038
+ t11 += v * b8;
2039
+ t12 += v * b9;
2040
+ t13 += v * b10;
2041
+ t14 += v * b11;
2042
+ t15 += v * b12;
2043
+ t16 += v * b13;
2044
+ t17 += v * b14;
2045
+ t18 += v * b15;
2046
+ v = a[4];
2047
+ t4 += v * b0;
2048
+ t5 += v * b1;
2049
+ t6 += v * b2;
2050
+ t7 += v * b3;
2051
+ t8 += v * b4;
2052
+ t9 += v * b5;
2053
+ t10 += v * b6;
2054
+ t11 += v * b7;
2055
+ t12 += v * b8;
2056
+ t13 += v * b9;
2057
+ t14 += v * b10;
2058
+ t15 += v * b11;
2059
+ t16 += v * b12;
2060
+ t17 += v * b13;
2061
+ t18 += v * b14;
2062
+ t19 += v * b15;
2063
+ v = a[5];
2064
+ t5 += v * b0;
2065
+ t6 += v * b1;
2066
+ t7 += v * b2;
2067
+ t8 += v * b3;
2068
+ t9 += v * b4;
2069
+ t10 += v * b5;
2070
+ t11 += v * b6;
2071
+ t12 += v * b7;
2072
+ t13 += v * b8;
2073
+ t14 += v * b9;
2074
+ t15 += v * b10;
2075
+ t16 += v * b11;
2076
+ t17 += v * b12;
2077
+ t18 += v * b13;
2078
+ t19 += v * b14;
2079
+ t20 += v * b15;
2080
+ v = a[6];
2081
+ t6 += v * b0;
2082
+ t7 += v * b1;
2083
+ t8 += v * b2;
2084
+ t9 += v * b3;
2085
+ t10 += v * b4;
2086
+ t11 += v * b5;
2087
+ t12 += v * b6;
2088
+ t13 += v * b7;
2089
+ t14 += v * b8;
2090
+ t15 += v * b9;
2091
+ t16 += v * b10;
2092
+ t17 += v * b11;
2093
+ t18 += v * b12;
2094
+ t19 += v * b13;
2095
+ t20 += v * b14;
2096
+ t21 += v * b15;
2097
+ v = a[7];
2098
+ t7 += v * b0;
2099
+ t8 += v * b1;
2100
+ t9 += v * b2;
2101
+ t10 += v * b3;
2102
+ t11 += v * b4;
2103
+ t12 += v * b5;
2104
+ t13 += v * b6;
2105
+ t14 += v * b7;
2106
+ t15 += v * b8;
2107
+ t16 += v * b9;
2108
+ t17 += v * b10;
2109
+ t18 += v * b11;
2110
+ t19 += v * b12;
2111
+ t20 += v * b13;
2112
+ t21 += v * b14;
2113
+ t22 += v * b15;
2114
+ v = a[8];
2115
+ t8 += v * b0;
2116
+ t9 += v * b1;
2117
+ t10 += v * b2;
2118
+ t11 += v * b3;
2119
+ t12 += v * b4;
2120
+ t13 += v * b5;
2121
+ t14 += v * b6;
2122
+ t15 += v * b7;
2123
+ t16 += v * b8;
2124
+ t17 += v * b9;
2125
+ t18 += v * b10;
2126
+ t19 += v * b11;
2127
+ t20 += v * b12;
2128
+ t21 += v * b13;
2129
+ t22 += v * b14;
2130
+ t23 += v * b15;
2131
+ v = a[9];
2132
+ t9 += v * b0;
2133
+ t10 += v * b1;
2134
+ t11 += v * b2;
2135
+ t12 += v * b3;
2136
+ t13 += v * b4;
2137
+ t14 += v * b5;
2138
+ t15 += v * b6;
2139
+ t16 += v * b7;
2140
+ t17 += v * b8;
2141
+ t18 += v * b9;
2142
+ t19 += v * b10;
2143
+ t20 += v * b11;
2144
+ t21 += v * b12;
2145
+ t22 += v * b13;
2146
+ t23 += v * b14;
2147
+ t24 += v * b15;
2148
+ v = a[10];
2149
+ t10 += v * b0;
2150
+ t11 += v * b1;
2151
+ t12 += v * b2;
2152
+ t13 += v * b3;
2153
+ t14 += v * b4;
2154
+ t15 += v * b5;
2155
+ t16 += v * b6;
2156
+ t17 += v * b7;
2157
+ t18 += v * b8;
2158
+ t19 += v * b9;
2159
+ t20 += v * b10;
2160
+ t21 += v * b11;
2161
+ t22 += v * b12;
2162
+ t23 += v * b13;
2163
+ t24 += v * b14;
2164
+ t25 += v * b15;
2165
+ v = a[11];
2166
+ t11 += v * b0;
2167
+ t12 += v * b1;
2168
+ t13 += v * b2;
2169
+ t14 += v * b3;
2170
+ t15 += v * b4;
2171
+ t16 += v * b5;
2172
+ t17 += v * b6;
2173
+ t18 += v * b7;
2174
+ t19 += v * b8;
2175
+ t20 += v * b9;
2176
+ t21 += v * b10;
2177
+ t22 += v * b11;
2178
+ t23 += v * b12;
2179
+ t24 += v * b13;
2180
+ t25 += v * b14;
2181
+ t26 += v * b15;
2182
+ v = a[12];
2183
+ t12 += v * b0;
2184
+ t13 += v * b1;
2185
+ t14 += v * b2;
2186
+ t15 += v * b3;
2187
+ t16 += v * b4;
2188
+ t17 += v * b5;
2189
+ t18 += v * b6;
2190
+ t19 += v * b7;
2191
+ t20 += v * b8;
2192
+ t21 += v * b9;
2193
+ t22 += v * b10;
2194
+ t23 += v * b11;
2195
+ t24 += v * b12;
2196
+ t25 += v * b13;
2197
+ t26 += v * b14;
2198
+ t27 += v * b15;
2199
+ v = a[13];
2200
+ t13 += v * b0;
2201
+ t14 += v * b1;
2202
+ t15 += v * b2;
2203
+ t16 += v * b3;
2204
+ t17 += v * b4;
2205
+ t18 += v * b5;
2206
+ t19 += v * b6;
2207
+ t20 += v * b7;
2208
+ t21 += v * b8;
2209
+ t22 += v * b9;
2210
+ t23 += v * b10;
2211
+ t24 += v * b11;
2212
+ t25 += v * b12;
2213
+ t26 += v * b13;
2214
+ t27 += v * b14;
2215
+ t28 += v * b15;
2216
+ v = a[14];
2217
+ t14 += v * b0;
2218
+ t15 += v * b1;
2219
+ t16 += v * b2;
2220
+ t17 += v * b3;
2221
+ t18 += v * b4;
2222
+ t19 += v * b5;
2223
+ t20 += v * b6;
2224
+ t21 += v * b7;
2225
+ t22 += v * b8;
2226
+ t23 += v * b9;
2227
+ t24 += v * b10;
2228
+ t25 += v * b11;
2229
+ t26 += v * b12;
2230
+ t27 += v * b13;
2231
+ t28 += v * b14;
2232
+ t29 += v * b15;
2233
+ v = a[15];
2234
+ t15 += v * b0;
2235
+ t16 += v * b1;
2236
+ t17 += v * b2;
2237
+ t18 += v * b3;
2238
+ t19 += v * b4;
2239
+ t20 += v * b5;
2240
+ t21 += v * b6;
2241
+ t22 += v * b7;
2242
+ t23 += v * b8;
2243
+ t24 += v * b9;
2244
+ t25 += v * b10;
2245
+ t26 += v * b11;
2246
+ t27 += v * b12;
2247
+ t28 += v * b13;
2248
+ t29 += v * b14;
2249
+ t30 += v * b15;
2250
+
2251
+ t0 += 38 * t16;
2252
+ t1 += 38 * t17;
2253
+ t2 += 38 * t18;
2254
+ t3 += 38 * t19;
2255
+ t4 += 38 * t20;
2256
+ t5 += 38 * t21;
2257
+ t6 += 38 * t22;
2258
+ t7 += 38 * t23;
2259
+ t8 += 38 * t24;
2260
+ t9 += 38 * t25;
2261
+ t10 += 38 * t26;
2262
+ t11 += 38 * t27;
2263
+ t12 += 38 * t28;
2264
+ t13 += 38 * t29;
2265
+ t14 += 38 * t30;
2266
+ // t15 left as is
2267
+
2268
+ // first car
2269
+ c = 1;
2270
+ v = t0 + c + 65535; c = Math.floor(v / 65536); t0 = v - c * 65536;
2271
+ v = t1 + c + 65535; c = Math.floor(v / 65536); t1 = v - c * 65536;
2272
+ v = t2 + c + 65535; c = Math.floor(v / 65536); t2 = v - c * 65536;
2273
+ v = t3 + c + 65535; c = Math.floor(v / 65536); t3 = v - c * 65536;
2274
+ v = t4 + c + 65535; c = Math.floor(v / 65536); t4 = v - c * 65536;
2275
+ v = t5 + c + 65535; c = Math.floor(v / 65536); t5 = v - c * 65536;
2276
+ v = t6 + c + 65535; c = Math.floor(v / 65536); t6 = v - c * 65536;
2277
+ v = t7 + c + 65535; c = Math.floor(v / 65536); t7 = v - c * 65536;
2278
+ v = t8 + c + 65535; c = Math.floor(v / 65536); t8 = v - c * 65536;
2279
+ v = t9 + c + 65535; c = Math.floor(v / 65536); t9 = v - c * 65536;
2280
+ v = t10 + c + 65535; c = Math.floor(v / 65536); t10 = v - c * 65536;
2281
+ v = t11 + c + 65535; c = Math.floor(v / 65536); t11 = v - c * 65536;
2282
+ v = t12 + c + 65535; c = Math.floor(v / 65536); t12 = v - c * 65536;
2283
+ v = t13 + c + 65535; c = Math.floor(v / 65536); t13 = v - c * 65536;
2284
+ v = t14 + c + 65535; c = Math.floor(v / 65536); t14 = v - c * 65536;
2285
+ v = t15 + c + 65535; c = Math.floor(v / 65536); t15 = v - c * 65536;
2286
+ t0 += c-1 + 37 * (c-1);
2287
+
2288
+ // second car
2289
+ c = 1;
2290
+ v = t0 + c + 65535; c = Math.floor(v / 65536); t0 = v - c * 65536;
2291
+ v = t1 + c + 65535; c = Math.floor(v / 65536); t1 = v - c * 65536;
2292
+ v = t2 + c + 65535; c = Math.floor(v / 65536); t2 = v - c * 65536;
2293
+ v = t3 + c + 65535; c = Math.floor(v / 65536); t3 = v - c * 65536;
2294
+ v = t4 + c + 65535; c = Math.floor(v / 65536); t4 = v - c * 65536;
2295
+ v = t5 + c + 65535; c = Math.floor(v / 65536); t5 = v - c * 65536;
2296
+ v = t6 + c + 65535; c = Math.floor(v / 65536); t6 = v - c * 65536;
2297
+ v = t7 + c + 65535; c = Math.floor(v / 65536); t7 = v - c * 65536;
2298
+ v = t8 + c + 65535; c = Math.floor(v / 65536); t8 = v - c * 65536;
2299
+ v = t9 + c + 65535; c = Math.floor(v / 65536); t9 = v - c * 65536;
2300
+ v = t10 + c + 65535; c = Math.floor(v / 65536); t10 = v - c * 65536;
2301
+ v = t11 + c + 65535; c = Math.floor(v / 65536); t11 = v - c * 65536;
2302
+ v = t12 + c + 65535; c = Math.floor(v / 65536); t12 = v - c * 65536;
2303
+ v = t13 + c + 65535; c = Math.floor(v / 65536); t13 = v - c * 65536;
2304
+ v = t14 + c + 65535; c = Math.floor(v / 65536); t14 = v - c * 65536;
2305
+ v = t15 + c + 65535; c = Math.floor(v / 65536); t15 = v - c * 65536;
2306
+ t0 += c-1 + 37 * (c-1);
2307
+
2308
+ o[ 0] = t0;
2309
+ o[ 1] = t1;
2310
+ o[ 2] = t2;
2311
+ o[ 3] = t3;
2312
+ o[ 4] = t4;
2313
+ o[ 5] = t5;
2314
+ o[ 6] = t6;
2315
+ o[ 7] = t7;
2316
+ o[ 8] = t8;
2317
+ o[ 9] = t9;
2318
+ o[10] = t10;
2319
+ o[11] = t11;
2320
+ o[12] = t12;
2321
+ o[13] = t13;
2322
+ o[14] = t14;
2323
+ o[15] = t15;
2324
+ }
2325
+
2326
+ function S(o, a) {
2327
+ M(o, a, a);
2328
+ }
2329
+
2330
+ function inv25519(o, i) {
2331
+ var c = gf();
2332
+ var a;
2333
+ for (a = 0; a < 16; a++) c[a] = i[a];
2334
+ for (a = 253; a >= 0; a--) {
2335
+ S(c, c);
2336
+ if(a !== 2 && a !== 4) M(c, c, i);
2337
+ }
2338
+ for (a = 0; a < 16; a++) o[a] = c[a];
2339
+ }
2340
+
2341
+ function pow2523(o, i) {
2342
+ var c = gf();
2343
+ var a;
2344
+ for (a = 0; a < 16; a++) c[a] = i[a];
2345
+ for (a = 250; a >= 0; a--) {
2346
+ S(c, c);
2347
+ if(a !== 1) M(c, c, i);
2348
+ }
2349
+ for (a = 0; a < 16; a++) o[a] = c[a];
2350
+ }
2351
+
2352
+ function crypto_scalarmult(q, n, p) {
2353
+ var z = new Uint8Array(32);
2354
+ var x = new Float64Array(80), r, i;
2355
+ var a = gf(), b = gf(), c = gf(),
2356
+ d = gf(), e = gf(), f = gf();
2357
+ for (i = 0; i < 31; i++) z[i] = n[i];
2358
+ z[31]=(n[31]&127)|64;
2359
+ z[0]&=248;
2360
+ unpack25519(x,p);
2361
+ for (i = 0; i < 16; i++) {
2362
+ b[i]=x[i];
2363
+ d[i]=a[i]=c[i]=0;
2364
+ }
2365
+ a[0]=d[0]=1;
2366
+ for (i=254; i>=0; --i) {
2367
+ r=(z[i>>>3]>>>(i&7))&1;
2368
+ sel25519(a,b,r);
2369
+ sel25519(c,d,r);
2370
+ A(e,a,c);
2371
+ Z(a,a,c);
2372
+ A(c,b,d);
2373
+ Z(b,b,d);
2374
+ S(d,e);
2375
+ S(f,a);
2376
+ M(a,c,a);
2377
+ M(c,b,e);
2378
+ A(e,a,c);
2379
+ Z(a,a,c);
2380
+ S(b,a);
2381
+ Z(c,d,f);
2382
+ M(a,c,_121665);
2383
+ A(a,a,d);
2384
+ M(c,c,a);
2385
+ M(a,d,f);
2386
+ M(d,b,x);
2387
+ S(b,e);
2388
+ sel25519(a,b,r);
2389
+ sel25519(c,d,r);
2390
+ }
2391
+ for (i = 0; i < 16; i++) {
2392
+ x[i+16]=a[i];
2393
+ x[i+32]=c[i];
2394
+ x[i+48]=b[i];
2395
+ x[i+64]=d[i];
2396
+ }
2397
+ var x32 = x.subarray(32);
2398
+ var x16 = x.subarray(16);
2399
+ inv25519(x32,x32);
2400
+ M(x16,x16,x32);
2401
+ pack25519(q,x16);
2402
+ return 0;
2403
+ }
2404
+
2405
+ function crypto_scalarmult_base(q, n) {
2406
+ return crypto_scalarmult(q, n, _9);
2407
+ }
2408
+
2409
+ function crypto_box_keypair(y, x) {
2410
+ randombytes(x, 32);
2411
+ return crypto_scalarmult_base(y, x);
2412
+ }
2413
+
2414
+ function crypto_box_beforenm(k, y, x) {
2415
+ var s = new Uint8Array(32);
2416
+ crypto_scalarmult(s, x, y);
2417
+ return crypto_core_hsalsa20(k, _0, s, sigma);
2418
+ }
2419
+
2420
+ var crypto_box_afternm = crypto_secretbox;
2421
+ var crypto_box_open_afternm = crypto_secretbox_open;
2422
+
2423
+ function crypto_box(c, m, d, n, y, x) {
2424
+ var k = new Uint8Array(32);
2425
+ crypto_box_beforenm(k, y, x);
2426
+ return crypto_box_afternm(c, m, d, n, k);
2427
+ }
2428
+
2429
+ function crypto_box_open(m, c, d, n, y, x) {
2430
+ var k = new Uint8Array(32);
2431
+ crypto_box_beforenm(k, y, x);
2432
+ return crypto_box_open_afternm(m, c, d, n, k);
2433
+ }
2434
+
2435
+ var K = [
2436
+ 0x428a2f98, 0xd728ae22, 0x71374491, 0x23ef65cd,
2437
+ 0xb5c0fbcf, 0xec4d3b2f, 0xe9b5dba5, 0x8189dbbc,
2438
+ 0x3956c25b, 0xf348b538, 0x59f111f1, 0xb605d019,
2439
+ 0x923f82a4, 0xaf194f9b, 0xab1c5ed5, 0xda6d8118,
2440
+ 0xd807aa98, 0xa3030242, 0x12835b01, 0x45706fbe,
2441
+ 0x243185be, 0x4ee4b28c, 0x550c7dc3, 0xd5ffb4e2,
2442
+ 0x72be5d74, 0xf27b896f, 0x80deb1fe, 0x3b1696b1,
2443
+ 0x9bdc06a7, 0x25c71235, 0xc19bf174, 0xcf692694,
2444
+ 0xe49b69c1, 0x9ef14ad2, 0xefbe4786, 0x384f25e3,
2445
+ 0x0fc19dc6, 0x8b8cd5b5, 0x240ca1cc, 0x77ac9c65,
2446
+ 0x2de92c6f, 0x592b0275, 0x4a7484aa, 0x6ea6e483,
2447
+ 0x5cb0a9dc, 0xbd41fbd4, 0x76f988da, 0x831153b5,
2448
+ 0x983e5152, 0xee66dfab, 0xa831c66d, 0x2db43210,
2449
+ 0xb00327c8, 0x98fb213f, 0xbf597fc7, 0xbeef0ee4,
2450
+ 0xc6e00bf3, 0x3da88fc2, 0xd5a79147, 0x930aa725,
2451
+ 0x06ca6351, 0xe003826f, 0x14292967, 0x0a0e6e70,
2452
+ 0x27b70a85, 0x46d22ffc, 0x2e1b2138, 0x5c26c926,
2453
+ 0x4d2c6dfc, 0x5ac42aed, 0x53380d13, 0x9d95b3df,
2454
+ 0x650a7354, 0x8baf63de, 0x766a0abb, 0x3c77b2a8,
2455
+ 0x81c2c92e, 0x47edaee6, 0x92722c85, 0x1482353b,
2456
+ 0xa2bfe8a1, 0x4cf10364, 0xa81a664b, 0xbc423001,
2457
+ 0xc24b8b70, 0xd0f89791, 0xc76c51a3, 0x0654be30,
2458
+ 0xd192e819, 0xd6ef5218, 0xd6990624, 0x5565a910,
2459
+ 0xf40e3585, 0x5771202a, 0x106aa070, 0x32bbd1b8,
2460
+ 0x19a4c116, 0xb8d2d0c8, 0x1e376c08, 0x5141ab53,
2461
+ 0x2748774c, 0xdf8eeb99, 0x34b0bcb5, 0xe19b48a8,
2462
+ 0x391c0cb3, 0xc5c95a63, 0x4ed8aa4a, 0xe3418acb,
2463
+ 0x5b9cca4f, 0x7763e373, 0x682e6ff3, 0xd6b2b8a3,
2464
+ 0x748f82ee, 0x5defb2fc, 0x78a5636f, 0x43172f60,
2465
+ 0x84c87814, 0xa1f0ab72, 0x8cc70208, 0x1a6439ec,
2466
+ 0x90befffa, 0x23631e28, 0xa4506ceb, 0xde82bde9,
2467
+ 0xbef9a3f7, 0xb2c67915, 0xc67178f2, 0xe372532b,
2468
+ 0xca273ece, 0xea26619c, 0xd186b8c7, 0x21c0c207,
2469
+ 0xeada7dd6, 0xcde0eb1e, 0xf57d4f7f, 0xee6ed178,
2470
+ 0x06f067aa, 0x72176fba, 0x0a637dc5, 0xa2c898a6,
2471
+ 0x113f9804, 0xbef90dae, 0x1b710b35, 0x131c471b,
2472
+ 0x28db77f5, 0x23047d84, 0x32caab7b, 0x40c72493,
2473
+ 0x3c9ebe0a, 0x15c9bebc, 0x431d67c4, 0x9c100d4c,
2474
+ 0x4cc5d4be, 0xcb3e42b6, 0x597f299c, 0xfc657e2a,
2475
+ 0x5fcb6fab, 0x3ad6faec, 0x6c44198c, 0x4a475817
2476
+ ];
2477
+
2478
+ function crypto_hashblocks_hl(hh, hl, m, n) {
2479
+ var wh = new Int32Array(16), wl = new Int32Array(16),
2480
+ bh0, bh1, bh2, bh3, bh4, bh5, bh6, bh7,
2481
+ bl0, bl1, bl2, bl3, bl4, bl5, bl6, bl7,
2482
+ th, tl, i, j, h, l, a, b, c, d;
2483
+
2484
+ var ah0 = hh[0],
2485
+ ah1 = hh[1],
2486
+ ah2 = hh[2],
2487
+ ah3 = hh[3],
2488
+ ah4 = hh[4],
2489
+ ah5 = hh[5],
2490
+ ah6 = hh[6],
2491
+ ah7 = hh[7],
2492
+
2493
+ al0 = hl[0],
2494
+ al1 = hl[1],
2495
+ al2 = hl[2],
2496
+ al3 = hl[3],
2497
+ al4 = hl[4],
2498
+ al5 = hl[5],
2499
+ al6 = hl[6],
2500
+ al7 = hl[7];
2501
+
2502
+ var pos = 0;
2503
+ while (n >= 128) {
2504
+ for (i = 0; i < 16; i++) {
2505
+ j = 8 * i + pos;
2506
+ wh[i] = (m[j+0] << 24) | (m[j+1] << 16) | (m[j+2] << 8) | m[j+3];
2507
+ wl[i] = (m[j+4] << 24) | (m[j+5] << 16) | (m[j+6] << 8) | m[j+7];
2508
+ }
2509
+ for (i = 0; i < 80; i++) {
2510
+ bh0 = ah0;
2511
+ bh1 = ah1;
2512
+ bh2 = ah2;
2513
+ bh3 = ah3;
2514
+ bh4 = ah4;
2515
+ bh5 = ah5;
2516
+ bh6 = ah6;
2517
+ bh7 = ah7;
2518
+
2519
+ bl0 = al0;
2520
+ bl1 = al1;
2521
+ bl2 = al2;
2522
+ bl3 = al3;
2523
+ bl4 = al4;
2524
+ bl5 = al5;
2525
+ bl6 = al6;
2526
+ bl7 = al7;
2527
+
2528
+ // add
2529
+ h = ah7;
2530
+ l = al7;
2531
+
2532
+ a = l & 0xffff; b = l >>> 16;
2533
+ c = h & 0xffff; d = h >>> 16;
2534
+
2535
+ // Sigma1
2536
+ h = ((ah4 >>> 14) | (al4 << (32-14))) ^ ((ah4 >>> 18) | (al4 << (32-18))) ^ ((al4 >>> (41-32)) | (ah4 << (32-(41-32))));
2537
+ l = ((al4 >>> 14) | (ah4 << (32-14))) ^ ((al4 >>> 18) | (ah4 << (32-18))) ^ ((ah4 >>> (41-32)) | (al4 << (32-(41-32))));
2538
+
2539
+ a += l & 0xffff; b += l >>> 16;
2540
+ c += h & 0xffff; d += h >>> 16;
2541
+
2542
+ // Ch
2543
+ h = (ah4 & ah5) ^ (~ah4 & ah6);
2544
+ l = (al4 & al5) ^ (~al4 & al6);
2545
+
2546
+ a += l & 0xffff; b += l >>> 16;
2547
+ c += h & 0xffff; d += h >>> 16;
2548
+
2549
+ // K
2550
+ h = K[i*2];
2551
+ l = K[i*2+1];
2552
+
2553
+ a += l & 0xffff; b += l >>> 16;
2554
+ c += h & 0xffff; d += h >>> 16;
2555
+
2556
+ // w
2557
+ h = wh[i%16];
2558
+ l = wl[i%16];
2559
+
2560
+ a += l & 0xffff; b += l >>> 16;
2561
+ c += h & 0xffff; d += h >>> 16;
2562
+
2563
+ b += a >>> 16;
2564
+ c += b >>> 16;
2565
+ d += c >>> 16;
2566
+
2567
+ th = c & 0xffff | d << 16;
2568
+ tl = a & 0xffff | b << 16;
2569
+
2570
+ // add
2571
+ h = th;
2572
+ l = tl;
2573
+
2574
+ a = l & 0xffff; b = l >>> 16;
2575
+ c = h & 0xffff; d = h >>> 16;
2576
+
2577
+ // Sigma0
2578
+ h = ((ah0 >>> 28) | (al0 << (32-28))) ^ ((al0 >>> (34-32)) | (ah0 << (32-(34-32)))) ^ ((al0 >>> (39-32)) | (ah0 << (32-(39-32))));
2579
+ l = ((al0 >>> 28) | (ah0 << (32-28))) ^ ((ah0 >>> (34-32)) | (al0 << (32-(34-32)))) ^ ((ah0 >>> (39-32)) | (al0 << (32-(39-32))));
2580
+
2581
+ a += l & 0xffff; b += l >>> 16;
2582
+ c += h & 0xffff; d += h >>> 16;
2583
+
2584
+ // Maj
2585
+ h = (ah0 & ah1) ^ (ah0 & ah2) ^ (ah1 & ah2);
2586
+ l = (al0 & al1) ^ (al0 & al2) ^ (al1 & al2);
2587
+
2588
+ a += l & 0xffff; b += l >>> 16;
2589
+ c += h & 0xffff; d += h >>> 16;
2590
+
2591
+ b += a >>> 16;
2592
+ c += b >>> 16;
2593
+ d += c >>> 16;
2594
+
2595
+ bh7 = (c & 0xffff) | (d << 16);
2596
+ bl7 = (a & 0xffff) | (b << 16);
2597
+
2598
+ // add
2599
+ h = bh3;
2600
+ l = bl3;
2601
+
2602
+ a = l & 0xffff; b = l >>> 16;
2603
+ c = h & 0xffff; d = h >>> 16;
2604
+
2605
+ h = th;
2606
+ l = tl;
2607
+
2608
+ a += l & 0xffff; b += l >>> 16;
2609
+ c += h & 0xffff; d += h >>> 16;
2610
+
2611
+ b += a >>> 16;
2612
+ c += b >>> 16;
2613
+ d += c >>> 16;
2614
+
2615
+ bh3 = (c & 0xffff) | (d << 16);
2616
+ bl3 = (a & 0xffff) | (b << 16);
2617
+
2618
+ ah1 = bh0;
2619
+ ah2 = bh1;
2620
+ ah3 = bh2;
2621
+ ah4 = bh3;
2622
+ ah5 = bh4;
2623
+ ah6 = bh5;
2624
+ ah7 = bh6;
2625
+ ah0 = bh7;
2626
+
2627
+ al1 = bl0;
2628
+ al2 = bl1;
2629
+ al3 = bl2;
2630
+ al4 = bl3;
2631
+ al5 = bl4;
2632
+ al6 = bl5;
2633
+ al7 = bl6;
2634
+ al0 = bl7;
2635
+
2636
+ if (i%16 === 15) {
2637
+ for (j = 0; j < 16; j++) {
2638
+ // add
2639
+ h = wh[j];
2640
+ l = wl[j];
2641
+
2642
+ a = l & 0xffff; b = l >>> 16;
2643
+ c = h & 0xffff; d = h >>> 16;
2644
+
2645
+ h = wh[(j+9)%16];
2646
+ l = wl[(j+9)%16];
2647
+
2648
+ a += l & 0xffff; b += l >>> 16;
2649
+ c += h & 0xffff; d += h >>> 16;
2650
+
2651
+ // sigma0
2652
+ th = wh[(j+1)%16];
2653
+ tl = wl[(j+1)%16];
2654
+ h = ((th >>> 1) | (tl << (32-1))) ^ ((th >>> 8) | (tl << (32-8))) ^ (th >>> 7);
2655
+ l = ((tl >>> 1) | (th << (32-1))) ^ ((tl >>> 8) | (th << (32-8))) ^ ((tl >>> 7) | (th << (32-7)));
2656
+
2657
+ a += l & 0xffff; b += l >>> 16;
2658
+ c += h & 0xffff; d += h >>> 16;
2659
+
2660
+ // sigma1
2661
+ th = wh[(j+14)%16];
2662
+ tl = wl[(j+14)%16];
2663
+ h = ((th >>> 19) | (tl << (32-19))) ^ ((tl >>> (61-32)) | (th << (32-(61-32)))) ^ (th >>> 6);
2664
+ l = ((tl >>> 19) | (th << (32-19))) ^ ((th >>> (61-32)) | (tl << (32-(61-32)))) ^ ((tl >>> 6) | (th << (32-6)));
2665
+
2666
+ a += l & 0xffff; b += l >>> 16;
2667
+ c += h & 0xffff; d += h >>> 16;
2668
+
2669
+ b += a >>> 16;
2670
+ c += b >>> 16;
2671
+ d += c >>> 16;
2672
+
2673
+ wh[j] = (c & 0xffff) | (d << 16);
2674
+ wl[j] = (a & 0xffff) | (b << 16);
2675
+ }
2676
+ }
2677
+ }
2678
+
2679
+ // add
2680
+ h = ah0;
2681
+ l = al0;
2682
+
2683
+ a = l & 0xffff; b = l >>> 16;
2684
+ c = h & 0xffff; d = h >>> 16;
2685
+
2686
+ h = hh[0];
2687
+ l = hl[0];
2688
+
2689
+ a += l & 0xffff; b += l >>> 16;
2690
+ c += h & 0xffff; d += h >>> 16;
2691
+
2692
+ b += a >>> 16;
2693
+ c += b >>> 16;
2694
+ d += c >>> 16;
2695
+
2696
+ hh[0] = ah0 = (c & 0xffff) | (d << 16);
2697
+ hl[0] = al0 = (a & 0xffff) | (b << 16);
2698
+
2699
+ h = ah1;
2700
+ l = al1;
2701
+
2702
+ a = l & 0xffff; b = l >>> 16;
2703
+ c = h & 0xffff; d = h >>> 16;
2704
+
2705
+ h = hh[1];
2706
+ l = hl[1];
2707
+
2708
+ a += l & 0xffff; b += l >>> 16;
2709
+ c += h & 0xffff; d += h >>> 16;
2710
+
2711
+ b += a >>> 16;
2712
+ c += b >>> 16;
2713
+ d += c >>> 16;
2714
+
2715
+ hh[1] = ah1 = (c & 0xffff) | (d << 16);
2716
+ hl[1] = al1 = (a & 0xffff) | (b << 16);
2717
+
2718
+ h = ah2;
2719
+ l = al2;
2720
+
2721
+ a = l & 0xffff; b = l >>> 16;
2722
+ c = h & 0xffff; d = h >>> 16;
2723
+
2724
+ h = hh[2];
2725
+ l = hl[2];
2726
+
2727
+ a += l & 0xffff; b += l >>> 16;
2728
+ c += h & 0xffff; d += h >>> 16;
2729
+
2730
+ b += a >>> 16;
2731
+ c += b >>> 16;
2732
+ d += c >>> 16;
2733
+
2734
+ hh[2] = ah2 = (c & 0xffff) | (d << 16);
2735
+ hl[2] = al2 = (a & 0xffff) | (b << 16);
2736
+
2737
+ h = ah3;
2738
+ l = al3;
2739
+
2740
+ a = l & 0xffff; b = l >>> 16;
2741
+ c = h & 0xffff; d = h >>> 16;
2742
+
2743
+ h = hh[3];
2744
+ l = hl[3];
2745
+
2746
+ a += l & 0xffff; b += l >>> 16;
2747
+ c += h & 0xffff; d += h >>> 16;
2748
+
2749
+ b += a >>> 16;
2750
+ c += b >>> 16;
2751
+ d += c >>> 16;
2752
+
2753
+ hh[3] = ah3 = (c & 0xffff) | (d << 16);
2754
+ hl[3] = al3 = (a & 0xffff) | (b << 16);
2755
+
2756
+ h = ah4;
2757
+ l = al4;
2758
+
2759
+ a = l & 0xffff; b = l >>> 16;
2760
+ c = h & 0xffff; d = h >>> 16;
2761
+
2762
+ h = hh[4];
2763
+ l = hl[4];
2764
+
2765
+ a += l & 0xffff; b += l >>> 16;
2766
+ c += h & 0xffff; d += h >>> 16;
2767
+
2768
+ b += a >>> 16;
2769
+ c += b >>> 16;
2770
+ d += c >>> 16;
2771
+
2772
+ hh[4] = ah4 = (c & 0xffff) | (d << 16);
2773
+ hl[4] = al4 = (a & 0xffff) | (b << 16);
2774
+
2775
+ h = ah5;
2776
+ l = al5;
2777
+
2778
+ a = l & 0xffff; b = l >>> 16;
2779
+ c = h & 0xffff; d = h >>> 16;
2780
+
2781
+ h = hh[5];
2782
+ l = hl[5];
2783
+
2784
+ a += l & 0xffff; b += l >>> 16;
2785
+ c += h & 0xffff; d += h >>> 16;
2786
+
2787
+ b += a >>> 16;
2788
+ c += b >>> 16;
2789
+ d += c >>> 16;
2790
+
2791
+ hh[5] = ah5 = (c & 0xffff) | (d << 16);
2792
+ hl[5] = al5 = (a & 0xffff) | (b << 16);
2793
+
2794
+ h = ah6;
2795
+ l = al6;
2796
+
2797
+ a = l & 0xffff; b = l >>> 16;
2798
+ c = h & 0xffff; d = h >>> 16;
2799
+
2800
+ h = hh[6];
2801
+ l = hl[6];
2802
+
2803
+ a += l & 0xffff; b += l >>> 16;
2804
+ c += h & 0xffff; d += h >>> 16;
2805
+
2806
+ b += a >>> 16;
2807
+ c += b >>> 16;
2808
+ d += c >>> 16;
2809
+
2810
+ hh[6] = ah6 = (c & 0xffff) | (d << 16);
2811
+ hl[6] = al6 = (a & 0xffff) | (b << 16);
2812
+
2813
+ h = ah7;
2814
+ l = al7;
2815
+
2816
+ a = l & 0xffff; b = l >>> 16;
2817
+ c = h & 0xffff; d = h >>> 16;
2818
+
2819
+ h = hh[7];
2820
+ l = hl[7];
2821
+
2822
+ a += l & 0xffff; b += l >>> 16;
2823
+ c += h & 0xffff; d += h >>> 16;
2824
+
2825
+ b += a >>> 16;
2826
+ c += b >>> 16;
2827
+ d += c >>> 16;
2828
+
2829
+ hh[7] = ah7 = (c & 0xffff) | (d << 16);
2830
+ hl[7] = al7 = (a & 0xffff) | (b << 16);
2831
+
2832
+ pos += 128;
2833
+ n -= 128;
2834
+ }
2835
+
2836
+ return n;
2837
+ }
2838
+
2839
+ function crypto_hash(out, m, n) {
2840
+ var hh = new Int32Array(8),
2841
+ hl = new Int32Array(8),
2842
+ x = new Uint8Array(256),
2843
+ i, b = n;
2844
+
2845
+ hh[0] = 0x6a09e667;
2846
+ hh[1] = 0xbb67ae85;
2847
+ hh[2] = 0x3c6ef372;
2848
+ hh[3] = 0xa54ff53a;
2849
+ hh[4] = 0x510e527f;
2850
+ hh[5] = 0x9b05688c;
2851
+ hh[6] = 0x1f83d9ab;
2852
+ hh[7] = 0x5be0cd19;
2853
+
2854
+ hl[0] = 0xf3bcc908;
2855
+ hl[1] = 0x84caa73b;
2856
+ hl[2] = 0xfe94f82b;
2857
+ hl[3] = 0x5f1d36f1;
2858
+ hl[4] = 0xade682d1;
2859
+ hl[5] = 0x2b3e6c1f;
2860
+ hl[6] = 0xfb41bd6b;
2861
+ hl[7] = 0x137e2179;
2862
+
2863
+ crypto_hashblocks_hl(hh, hl, m, n);
2864
+ n %= 128;
2865
+
2866
+ for (i = 0; i < n; i++) x[i] = m[b-n+i];
2867
+ x[n] = 128;
2868
+
2869
+ n = 256-128*(n<112?1:0);
2870
+ x[n-9] = 0;
2871
+ ts64(x, n-8, (b / 0x20000000) | 0, b << 3);
2872
+ crypto_hashblocks_hl(hh, hl, x, n);
2873
+
2874
+ for (i = 0; i < 8; i++) ts64(out, 8*i, hh[i], hl[i]);
2875
+
2876
+ return 0;
2877
+ }
2878
+
2879
+ function add(p, q) {
2880
+ var a = gf(), b = gf(), c = gf(),
2881
+ d = gf(), e = gf(), f = gf(),
2882
+ g = gf(), h = gf(), t = gf();
2883
+
2884
+ Z(a, p[1], p[0]);
2885
+ Z(t, q[1], q[0]);
2886
+ M(a, a, t);
2887
+ A(b, p[0], p[1]);
2888
+ A(t, q[0], q[1]);
2889
+ M(b, b, t);
2890
+ M(c, p[3], q[3]);
2891
+ M(c, c, D2);
2892
+ M(d, p[2], q[2]);
2893
+ A(d, d, d);
2894
+ Z(e, b, a);
2895
+ Z(f, d, c);
2896
+ A(g, d, c);
2897
+ A(h, b, a);
2898
+
2899
+ M(p[0], e, f);
2900
+ M(p[1], h, g);
2901
+ M(p[2], g, f);
2902
+ M(p[3], e, h);
2903
+ }
2904
+
2905
+ function cswap(p, q, b) {
2906
+ var i;
2907
+ for (i = 0; i < 4; i++) {
2908
+ sel25519(p[i], q[i], b);
2909
+ }
2910
+ }
2911
+
2912
+ function pack(r, p) {
2913
+ var tx = gf(), ty = gf(), zi = gf();
2914
+ inv25519(zi, p[2]);
2915
+ M(tx, p[0], zi);
2916
+ M(ty, p[1], zi);
2917
+ pack25519(r, ty);
2918
+ r[31] ^= par25519(tx) << 7;
2919
+ }
2920
+
2921
+ function scalarmult(p, q, s) {
2922
+ var b, i;
2923
+ set25519(p[0], gf0);
2924
+ set25519(p[1], gf1);
2925
+ set25519(p[2], gf1);
2926
+ set25519(p[3], gf0);
2927
+ for (i = 255; i >= 0; --i) {
2928
+ b = (s[(i/8)|0] >> (i&7)) & 1;
2929
+ cswap(p, q, b);
2930
+ add(q, p);
2931
+ add(p, p);
2932
+ cswap(p, q, b);
2933
+ }
2934
+ }
2935
+
2936
+ function scalarbase(p, s) {
2937
+ var q = [gf(), gf(), gf(), gf()];
2938
+ set25519(q[0], X);
2939
+ set25519(q[1], Y);
2940
+ set25519(q[2], gf1);
2941
+ M(q[3], X, Y);
2942
+ scalarmult(p, q, s);
2943
+ }
2944
+
2945
+ function crypto_sign_keypair(pk, sk, seeded) {
2946
+ var d = new Uint8Array(64);
2947
+ var p = [gf(), gf(), gf(), gf()];
2948
+ var i;
2949
+
2950
+ if (!seeded) randombytes(sk, 32);
2951
+ crypto_hash(d, sk, 32);
2952
+ d[0] &= 248;
2953
+ d[31] &= 127;
2954
+ d[31] |= 64;
2955
+
2956
+ scalarbase(p, d);
2957
+ pack(pk, p);
2958
+
2959
+ for (i = 0; i < 32; i++) sk[i+32] = pk[i];
2960
+ return 0;
2961
+ }
2962
+
2963
+ var L = new Float64Array([0xed, 0xd3, 0xf5, 0x5c, 0x1a, 0x63, 0x12, 0x58, 0xd6, 0x9c, 0xf7, 0xa2, 0xde, 0xf9, 0xde, 0x14, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0x10]);
2964
+
2965
+ function modL(r, x) {
2966
+ var carry, i, j, k;
2967
+ for (i = 63; i >= 32; --i) {
2968
+ carry = 0;
2969
+ for (j = i - 32, k = i - 12; j < k; ++j) {
2970
+ x[j] += carry - 16 * x[i] * L[j - (i - 32)];
2971
+ carry = Math.floor((x[j] + 128) / 256);
2972
+ x[j] -= carry * 256;
2973
+ }
2974
+ x[j] += carry;
2975
+ x[i] = 0;
2976
+ }
2977
+ carry = 0;
2978
+ for (j = 0; j < 32; j++) {
2979
+ x[j] += carry - (x[31] >> 4) * L[j];
2980
+ carry = x[j] >> 8;
2981
+ x[j] &= 255;
2982
+ }
2983
+ for (j = 0; j < 32; j++) x[j] -= carry * L[j];
2984
+ for (i = 0; i < 32; i++) {
2985
+ x[i+1] += x[i] >> 8;
2986
+ r[i] = x[i] & 255;
2987
+ }
2988
+ }
2989
+
2990
+ function reduce(r) {
2991
+ var x = new Float64Array(64), i;
2992
+ for (i = 0; i < 64; i++) x[i] = r[i];
2993
+ for (i = 0; i < 64; i++) r[i] = 0;
2994
+ modL(r, x);
2995
+ }
2996
+
2997
+ // Note: difference from C - smlen returned, not passed as argument.
2998
+ function crypto_sign(sm, m, n, sk) {
2999
+ var d = new Uint8Array(64), h = new Uint8Array(64), r = new Uint8Array(64);
3000
+ var i, j, x = new Float64Array(64);
3001
+ var p = [gf(), gf(), gf(), gf()];
3002
+
3003
+ crypto_hash(d, sk, 32);
3004
+ d[0] &= 248;
3005
+ d[31] &= 127;
3006
+ d[31] |= 64;
3007
+
3008
+ var smlen = n + 64;
3009
+ for (i = 0; i < n; i++) sm[64 + i] = m[i];
3010
+ for (i = 0; i < 32; i++) sm[32 + i] = d[32 + i];
3011
+
3012
+ crypto_hash(r, sm.subarray(32), n+32);
3013
+ reduce(r);
3014
+ scalarbase(p, r);
3015
+ pack(sm, p);
3016
+
3017
+ for (i = 32; i < 64; i++) sm[i] = sk[i];
3018
+ crypto_hash(h, sm, n + 64);
3019
+ reduce(h);
3020
+
3021
+ for (i = 0; i < 64; i++) x[i] = 0;
3022
+ for (i = 0; i < 32; i++) x[i] = r[i];
3023
+ for (i = 0; i < 32; i++) {
3024
+ for (j = 0; j < 32; j++) {
3025
+ x[i+j] += h[i] * d[j];
3026
+ }
3027
+ }
3028
+
3029
+ modL(sm.subarray(32), x);
3030
+ return smlen;
3031
+ }
3032
+
3033
+ function unpackneg(r, p) {
3034
+ var t = gf(), chk = gf(), num = gf(),
3035
+ den = gf(), den2 = gf(), den4 = gf(),
3036
+ den6 = gf();
3037
+
3038
+ set25519(r[2], gf1);
3039
+ unpack25519(r[1], p);
3040
+ S(num, r[1]);
3041
+ M(den, num, D);
3042
+ Z(num, num, r[2]);
3043
+ A(den, r[2], den);
3044
+
3045
+ S(den2, den);
3046
+ S(den4, den2);
3047
+ M(den6, den4, den2);
3048
+ M(t, den6, num);
3049
+ M(t, t, den);
3050
+
3051
+ pow2523(t, t);
3052
+ M(t, t, num);
3053
+ M(t, t, den);
3054
+ M(t, t, den);
3055
+ M(r[0], t, den);
3056
+
3057
+ S(chk, r[0]);
3058
+ M(chk, chk, den);
3059
+ if (neq25519(chk, num)) M(r[0], r[0], I);
3060
+
3061
+ S(chk, r[0]);
3062
+ M(chk, chk, den);
3063
+ if (neq25519(chk, num)) return -1;
3064
+
3065
+ if (par25519(r[0]) === (p[31]>>7)) Z(r[0], gf0, r[0]);
3066
+
3067
+ M(r[3], r[0], r[1]);
3068
+ return 0;
3069
+ }
3070
+
3071
+ function crypto_sign_open(m, sm, n, pk) {
3072
+ var i;
3073
+ var t = new Uint8Array(32), h = new Uint8Array(64);
3074
+ var p = [gf(), gf(), gf(), gf()],
3075
+ q = [gf(), gf(), gf(), gf()];
3076
+
3077
+ if (n < 64) return -1;
3078
+
3079
+ if (unpackneg(q, pk)) return -1;
3080
+
3081
+ for (i = 0; i < n; i++) m[i] = sm[i];
3082
+ for (i = 0; i < 32; i++) m[i+32] = pk[i];
3083
+ crypto_hash(h, m, n);
3084
+ reduce(h);
3085
+ scalarmult(p, q, h);
3086
+
3087
+ scalarbase(q, sm.subarray(32));
3088
+ add(p, q);
3089
+ pack(t, p);
3090
+
3091
+ n -= 64;
3092
+ if (crypto_verify_32(sm, 0, t, 0)) {
3093
+ for (i = 0; i < n; i++) m[i] = 0;
3094
+ return -1;
3095
+ }
3096
+
3097
+ for (i = 0; i < n; i++) m[i] = sm[i + 64];
3098
+ return n;
3099
+ }
3100
+
3101
+ var crypto_secretbox_KEYBYTES = 32,
3102
+ crypto_secretbox_NONCEBYTES = 24,
3103
+ crypto_secretbox_ZEROBYTES = 32,
3104
+ crypto_secretbox_BOXZEROBYTES = 16,
3105
+ crypto_scalarmult_BYTES = 32,
3106
+ crypto_scalarmult_SCALARBYTES = 32,
3107
+ crypto_box_PUBLICKEYBYTES = 32,
3108
+ crypto_box_SECRETKEYBYTES = 32,
3109
+ crypto_box_BEFORENMBYTES = 32,
3110
+ crypto_box_NONCEBYTES = crypto_secretbox_NONCEBYTES,
3111
+ crypto_box_ZEROBYTES = crypto_secretbox_ZEROBYTES,
3112
+ crypto_box_BOXZEROBYTES = crypto_secretbox_BOXZEROBYTES,
3113
+ crypto_sign_BYTES = 64,
3114
+ crypto_sign_PUBLICKEYBYTES = 32,
3115
+ crypto_sign_SECRETKEYBYTES = 64,
3116
+ crypto_sign_SEEDBYTES = 32,
3117
+ crypto_hash_BYTES = 64;
3118
+
3119
+ nacl.lowlevel = {
3120
+ crypto_core_hsalsa20: crypto_core_hsalsa20,
3121
+ crypto_stream_xor: crypto_stream_xor,
3122
+ crypto_stream: crypto_stream,
3123
+ crypto_stream_salsa20_xor: crypto_stream_salsa20_xor,
3124
+ crypto_stream_salsa20: crypto_stream_salsa20,
3125
+ crypto_onetimeauth: crypto_onetimeauth,
3126
+ crypto_onetimeauth_verify: crypto_onetimeauth_verify,
3127
+ crypto_verify_16: crypto_verify_16,
3128
+ crypto_verify_32: crypto_verify_32,
3129
+ crypto_secretbox: crypto_secretbox,
3130
+ crypto_secretbox_open: crypto_secretbox_open,
3131
+ crypto_scalarmult: crypto_scalarmult,
3132
+ crypto_scalarmult_base: crypto_scalarmult_base,
3133
+ crypto_box_beforenm: crypto_box_beforenm,
3134
+ crypto_box_afternm: crypto_box_afternm,
3135
+ crypto_box: crypto_box,
3136
+ crypto_box_open: crypto_box_open,
3137
+ crypto_box_keypair: crypto_box_keypair,
3138
+ crypto_hash: crypto_hash,
3139
+ crypto_sign: crypto_sign,
3140
+ crypto_sign_keypair: crypto_sign_keypair,
3141
+ crypto_sign_open: crypto_sign_open,
3142
+
3143
+ crypto_secretbox_KEYBYTES: crypto_secretbox_KEYBYTES,
3144
+ crypto_secretbox_NONCEBYTES: crypto_secretbox_NONCEBYTES,
3145
+ crypto_secretbox_ZEROBYTES: crypto_secretbox_ZEROBYTES,
3146
+ crypto_secretbox_BOXZEROBYTES: crypto_secretbox_BOXZEROBYTES,
3147
+ crypto_scalarmult_BYTES: crypto_scalarmult_BYTES,
3148
+ crypto_scalarmult_SCALARBYTES: crypto_scalarmult_SCALARBYTES,
3149
+ crypto_box_PUBLICKEYBYTES: crypto_box_PUBLICKEYBYTES,
3150
+ crypto_box_SECRETKEYBYTES: crypto_box_SECRETKEYBYTES,
3151
+ crypto_box_BEFORENMBYTES: crypto_box_BEFORENMBYTES,
3152
+ crypto_box_NONCEBYTES: crypto_box_NONCEBYTES,
3153
+ crypto_box_ZEROBYTES: crypto_box_ZEROBYTES,
3154
+ crypto_box_BOXZEROBYTES: crypto_box_BOXZEROBYTES,
3155
+ crypto_sign_BYTES: crypto_sign_BYTES,
3156
+ crypto_sign_PUBLICKEYBYTES: crypto_sign_PUBLICKEYBYTES,
3157
+ crypto_sign_SECRETKEYBYTES: crypto_sign_SECRETKEYBYTES,
3158
+ crypto_sign_SEEDBYTES: crypto_sign_SEEDBYTES,
3159
+ crypto_hash_BYTES: crypto_hash_BYTES,
3160
+
3161
+ gf: gf,
3162
+ D: D,
3163
+ L: L,
3164
+ pack25519: pack25519,
3165
+ unpack25519: unpack25519,
3166
+ M: M,
3167
+ A: A,
3168
+ S: S,
3169
+ Z: Z,
3170
+ pow2523: pow2523,
3171
+ add: add,
3172
+ set25519: set25519,
3173
+ modL: modL,
3174
+ scalarmult: scalarmult,
3175
+ scalarbase: scalarbase,
3176
+ };
3177
+
3178
+ /* High-level API */
3179
+
3180
+ function checkLengths(k, n) {
3181
+ if (k.length !== crypto_secretbox_KEYBYTES) throw new Error('bad key size');
3182
+ if (n.length !== crypto_secretbox_NONCEBYTES) throw new Error('bad nonce size');
3183
+ }
3184
+
3185
+ function checkBoxLengths(pk, sk) {
3186
+ if (pk.length !== crypto_box_PUBLICKEYBYTES) throw new Error('bad public key size');
3187
+ if (sk.length !== crypto_box_SECRETKEYBYTES) throw new Error('bad secret key size');
3188
+ }
3189
+
3190
+ function checkArrayTypes() {
3191
+ for (var i = 0; i < arguments.length; i++) {
3192
+ if (!(arguments[i] instanceof Uint8Array))
3193
+ throw new TypeError('unexpected type, use Uint8Array');
3194
+ }
3195
+ }
3196
+
3197
+ function cleanup(arr) {
3198
+ for (var i = 0; i < arr.length; i++) arr[i] = 0;
3199
+ }
3200
+
3201
+ nacl.randomBytes = function(n) {
3202
+ var b = new Uint8Array(n);
3203
+ randombytes(b, n);
3204
+ return b;
3205
+ };
3206
+
3207
+ nacl.secretbox = function(msg, nonce, key) {
3208
+ checkArrayTypes(msg, nonce, key);
3209
+ checkLengths(key, nonce);
3210
+ var m = new Uint8Array(crypto_secretbox_ZEROBYTES + msg.length);
3211
+ var c = new Uint8Array(m.length);
3212
+ for (var i = 0; i < msg.length; i++) m[i+crypto_secretbox_ZEROBYTES] = msg[i];
3213
+ crypto_secretbox(c, m, m.length, nonce, key);
3214
+ return c.subarray(crypto_secretbox_BOXZEROBYTES);
3215
+ };
3216
+
3217
+ nacl.secretbox.open = function(box, nonce, key) {
3218
+ checkArrayTypes(box, nonce, key);
3219
+ checkLengths(key, nonce);
3220
+ var c = new Uint8Array(crypto_secretbox_BOXZEROBYTES + box.length);
3221
+ var m = new Uint8Array(c.length);
3222
+ for (var i = 0; i < box.length; i++) c[i+crypto_secretbox_BOXZEROBYTES] = box[i];
3223
+ if (c.length < 32) return null;
3224
+ if (crypto_secretbox_open(m, c, c.length, nonce, key) !== 0) return null;
3225
+ return m.subarray(crypto_secretbox_ZEROBYTES);
3226
+ };
3227
+
3228
+ nacl.secretbox.keyLength = crypto_secretbox_KEYBYTES;
3229
+ nacl.secretbox.nonceLength = crypto_secretbox_NONCEBYTES;
3230
+ nacl.secretbox.overheadLength = crypto_secretbox_BOXZEROBYTES;
3231
+
3232
+ nacl.scalarMult = function(n, p) {
3233
+ checkArrayTypes(n, p);
3234
+ if (n.length !== crypto_scalarmult_SCALARBYTES) throw new Error('bad n size');
3235
+ if (p.length !== crypto_scalarmult_BYTES) throw new Error('bad p size');
3236
+ var q = new Uint8Array(crypto_scalarmult_BYTES);
3237
+ crypto_scalarmult(q, n, p);
3238
+ return q;
3239
+ };
3240
+
3241
+ nacl.scalarMult.base = function(n) {
3242
+ checkArrayTypes(n);
3243
+ if (n.length !== crypto_scalarmult_SCALARBYTES) throw new Error('bad n size');
3244
+ var q = new Uint8Array(crypto_scalarmult_BYTES);
3245
+ crypto_scalarmult_base(q, n);
3246
+ return q;
3247
+ };
3248
+
3249
+ nacl.scalarMult.scalarLength = crypto_scalarmult_SCALARBYTES;
3250
+ nacl.scalarMult.groupElementLength = crypto_scalarmult_BYTES;
3251
+
3252
+ nacl.box = function(msg, nonce, publicKey, secretKey) {
3253
+ var k = nacl.box.before(publicKey, secretKey);
3254
+ return nacl.secretbox(msg, nonce, k);
3255
+ };
3256
+
3257
+ nacl.box.before = function(publicKey, secretKey) {
3258
+ checkArrayTypes(publicKey, secretKey);
3259
+ checkBoxLengths(publicKey, secretKey);
3260
+ var k = new Uint8Array(crypto_box_BEFORENMBYTES);
3261
+ crypto_box_beforenm(k, publicKey, secretKey);
3262
+ return k;
3263
+ };
3264
+
3265
+ nacl.box.after = nacl.secretbox;
3266
+
3267
+ nacl.box.open = function(msg, nonce, publicKey, secretKey) {
3268
+ var k = nacl.box.before(publicKey, secretKey);
3269
+ return nacl.secretbox.open(msg, nonce, k);
3270
+ };
3271
+
3272
+ nacl.box.open.after = nacl.secretbox.open;
3273
+
3274
+ nacl.box.keyPair = function() {
3275
+ var pk = new Uint8Array(crypto_box_PUBLICKEYBYTES);
3276
+ var sk = new Uint8Array(crypto_box_SECRETKEYBYTES);
3277
+ crypto_box_keypair(pk, sk);
3278
+ return {publicKey: pk, secretKey: sk};
3279
+ };
3280
+
3281
+ nacl.box.keyPair.fromSecretKey = function(secretKey) {
3282
+ checkArrayTypes(secretKey);
3283
+ if (secretKey.length !== crypto_box_SECRETKEYBYTES)
3284
+ throw new Error('bad secret key size');
3285
+ var pk = new Uint8Array(crypto_box_PUBLICKEYBYTES);
3286
+ crypto_scalarmult_base(pk, secretKey);
3287
+ return {publicKey: pk, secretKey: new Uint8Array(secretKey)};
3288
+ };
3289
+
3290
+ nacl.box.publicKeyLength = crypto_box_PUBLICKEYBYTES;
3291
+ nacl.box.secretKeyLength = crypto_box_SECRETKEYBYTES;
3292
+ nacl.box.sharedKeyLength = crypto_box_BEFORENMBYTES;
3293
+ nacl.box.nonceLength = crypto_box_NONCEBYTES;
3294
+ nacl.box.overheadLength = nacl.secretbox.overheadLength;
3295
+
3296
+ nacl.sign = function(msg, secretKey) {
3297
+ checkArrayTypes(msg, secretKey);
3298
+ if (secretKey.length !== crypto_sign_SECRETKEYBYTES)
3299
+ throw new Error('bad secret key size');
3300
+ var signedMsg = new Uint8Array(crypto_sign_BYTES+msg.length);
3301
+ crypto_sign(signedMsg, msg, msg.length, secretKey);
3302
+ return signedMsg;
3303
+ };
3304
+
3305
+ nacl.sign.open = function(signedMsg, publicKey) {
3306
+ checkArrayTypes(signedMsg, publicKey);
3307
+ if (publicKey.length !== crypto_sign_PUBLICKEYBYTES)
3308
+ throw new Error('bad public key size');
3309
+ var tmp = new Uint8Array(signedMsg.length);
3310
+ var mlen = crypto_sign_open(tmp, signedMsg, signedMsg.length, publicKey);
3311
+ if (mlen < 0) return null;
3312
+ var m = new Uint8Array(mlen);
3313
+ for (var i = 0; i < m.length; i++) m[i] = tmp[i];
3314
+ return m;
3315
+ };
3316
+
3317
+ nacl.sign.detached = function(msg, secretKey) {
3318
+ var signedMsg = nacl.sign(msg, secretKey);
3319
+ var sig = new Uint8Array(crypto_sign_BYTES);
3320
+ for (var i = 0; i < sig.length; i++) sig[i] = signedMsg[i];
3321
+ return sig;
3322
+ };
3323
+
3324
+ nacl.sign.detached.verify = function(msg, sig, publicKey) {
3325
+ checkArrayTypes(msg, sig, publicKey);
3326
+ if (sig.length !== crypto_sign_BYTES)
3327
+ throw new Error('bad signature size');
3328
+ if (publicKey.length !== crypto_sign_PUBLICKEYBYTES)
3329
+ throw new Error('bad public key size');
3330
+ var sm = new Uint8Array(crypto_sign_BYTES + msg.length);
3331
+ var m = new Uint8Array(crypto_sign_BYTES + msg.length);
3332
+ var i;
3333
+ for (i = 0; i < crypto_sign_BYTES; i++) sm[i] = sig[i];
3334
+ for (i = 0; i < msg.length; i++) sm[i+crypto_sign_BYTES] = msg[i];
3335
+ return (crypto_sign_open(m, sm, sm.length, publicKey) >= 0);
3336
+ };
3337
+
3338
+ nacl.sign.keyPair = function() {
3339
+ var pk = new Uint8Array(crypto_sign_PUBLICKEYBYTES);
3340
+ var sk = new Uint8Array(crypto_sign_SECRETKEYBYTES);
3341
+ crypto_sign_keypair(pk, sk);
3342
+ return {publicKey: pk, secretKey: sk};
3343
+ };
3344
+
3345
+ nacl.sign.keyPair.fromSecretKey = function(secretKey) {
3346
+ checkArrayTypes(secretKey);
3347
+ if (secretKey.length !== crypto_sign_SECRETKEYBYTES)
3348
+ throw new Error('bad secret key size');
3349
+ var pk = new Uint8Array(crypto_sign_PUBLICKEYBYTES);
3350
+ for (var i = 0; i < pk.length; i++) pk[i] = secretKey[32+i];
3351
+ return {publicKey: pk, secretKey: new Uint8Array(secretKey)};
3352
+ };
3353
+
3354
+ nacl.sign.keyPair.fromSeed = function(seed) {
3355
+ checkArrayTypes(seed);
3356
+ if (seed.length !== crypto_sign_SEEDBYTES)
3357
+ throw new Error('bad seed size');
3358
+ var pk = new Uint8Array(crypto_sign_PUBLICKEYBYTES);
3359
+ var sk = new Uint8Array(crypto_sign_SECRETKEYBYTES);
3360
+ for (var i = 0; i < 32; i++) sk[i] = seed[i];
3361
+ crypto_sign_keypair(pk, sk, true);
3362
+ return {publicKey: pk, secretKey: sk};
3363
+ };
3364
+
3365
+ nacl.sign.publicKeyLength = crypto_sign_PUBLICKEYBYTES;
3366
+ nacl.sign.secretKeyLength = crypto_sign_SECRETKEYBYTES;
3367
+ nacl.sign.seedLength = crypto_sign_SEEDBYTES;
3368
+ nacl.sign.signatureLength = crypto_sign_BYTES;
3369
+
3370
+ nacl.hash = function(msg) {
3371
+ checkArrayTypes(msg);
3372
+ var h = new Uint8Array(crypto_hash_BYTES);
3373
+ crypto_hash(h, msg, msg.length);
3374
+ return h;
3375
+ };
3376
+
3377
+ nacl.hash.hashLength = crypto_hash_BYTES;
3378
+
3379
+ nacl.verify = function(x, y) {
3380
+ checkArrayTypes(x, y);
3381
+ // Zero length arguments are considered not equal.
3382
+ if (x.length === 0 || y.length === 0) return false;
3383
+ if (x.length !== y.length) return false;
3384
+ return (vn(x, 0, y, 0, x.length) === 0) ? true : false;
3385
+ };
3386
+
3387
+ nacl.setPRNG = function(fn) {
3388
+ randombytes = fn;
3389
+ };
3390
+
3391
+ (function() {
3392
+ // Initialize PRNG if environment provides CSPRNG.
3393
+ // If not, methods calling randombytes will throw.
3394
+ var crypto = typeof self !== 'undefined' ? (self.crypto || self.msCrypto) : null;
3395
+ if (crypto && crypto.getRandomValues) {
3396
+ // Browsers.
3397
+ var QUOTA = 65536;
3398
+ nacl.setPRNG(function(x, n) {
3399
+ var i, v = new Uint8Array(n);
3400
+ for (i = 0; i < n; i += QUOTA) {
3401
+ crypto.getRandomValues(v.subarray(i, i + Math.min(n - i, QUOTA)));
3402
+ }
3403
+ for (i = 0; i < n; i++) x[i] = v[i];
3404
+ cleanup(v);
3405
+ });
3406
+ } else if (typeof index_native.commonjsRequire !== 'undefined') {
3407
+ // Node.js.
3408
+ crypto = index_native.require$$0;
3409
+ if (crypto && crypto.randomBytes) {
3410
+ nacl.setPRNG(function(x, n) {
3411
+ var i, v = crypto.randomBytes(n);
3412
+ for (i = 0; i < n; i++) x[i] = v[i];
3413
+ cleanup(v);
3414
+ });
3415
+ }
3416
+ }
3417
+ })();
3418
+
3419
+ })(module.exports ? module.exports : (self.nacl = self.nacl || {}));
3420
+ } (naclFast));
3421
+ return naclFast.exports;
3422
+ }
3423
+
3424
+ requireNaclFast();
3425
+
1022
3426
  // src/PhantomClient.ts
1023
3427
  var CAIP2_NETWORK_MAPPINGS = {
1024
3428
  // Solana networks
@@ -2974,13 +5378,13 @@ function createAutoConfirmPlugin() {
2974
5378
  };
2975
5379
  }
2976
5380
 
2977
- var eventemitter3 = {exports: {}};
5381
+ var eventemitter3$1 = {exports: {}};
2978
5382
 
2979
- var hasRequiredEventemitter3;
5383
+ var hasRequiredEventemitter3$1;
2980
5384
 
2981
- function requireEventemitter3 () {
2982
- if (hasRequiredEventemitter3) return eventemitter3.exports;
2983
- hasRequiredEventemitter3 = 1;
5385
+ function requireEventemitter3$1 () {
5386
+ if (hasRequiredEventemitter3$1) return eventemitter3$1.exports;
5387
+ hasRequiredEventemitter3$1 = 1;
2984
5388
  (function (module) {
2985
5389
 
2986
5390
  var has = Object.prototype.hasOwnProperty
@@ -3317,12 +5721,12 @@ function requireEventemitter3 () {
3317
5721
  {
3318
5722
  module.exports = EventEmitter;
3319
5723
  }
3320
- } (eventemitter3));
3321
- return eventemitter3.exports;
5724
+ } (eventemitter3$1));
5725
+ return eventemitter3$1.exports;
3322
5726
  }
3323
5727
 
3324
- var eventemitter3Exports = requireEventemitter3();
3325
- var EventEmitter3 = /*@__PURE__*/index_native.getDefaultExportFromCjs(eventemitter3Exports);
5728
+ var eventemitter3Exports$1 = requireEventemitter3$1();
5729
+ var EventEmitter3 = /*@__PURE__*/index_native.getDefaultExportFromCjs(eventemitter3Exports$1);
3326
5730
 
3327
5731
  // src/index.ts
3328
5732
  var isBrowser = typeof window !== "undefined" && typeof window.btoa !== "undefined";
@@ -8643,300 +11047,650 @@ class Transaction {
8643
11047
  assertArgument(result.isSigned(), "unsigned transaction cannot define '.hash'", "tx", tx);
8644
11048
  assertArgument(result.hash === tx.hash, "hash mismatch", "tx", tx);
8645
11049
  }
8646
- if (tx.from != null) {
8647
- assertArgument(result.isSigned(), "unsigned transaction cannot define '.from'", "tx", tx);
8648
- assertArgument(result.from.toLowerCase() === (tx.from || "").toLowerCase(), "from mismatch", "tx", tx);
11050
+ if (tx.from != null) {
11051
+ assertArgument(result.isSigned(), "unsigned transaction cannot define '.from'", "tx", tx);
11052
+ assertArgument(result.from.toLowerCase() === (tx.from || "").toLowerCase(), "from mismatch", "tx", tx);
11053
+ }
11054
+ return result;
11055
+ }
11056
+ }
11057
+
11058
+ // src/index.ts
11059
+ function parseSignMessageResponse(base64Response, networkId) {
11060
+ const networkPrefix = networkId.split(":")[0].toLowerCase();
11061
+ switch (networkPrefix) {
11062
+ case "solana":
11063
+ return parseSolanaSignatureResponse(base64Response);
11064
+ case "eip155":
11065
+ case "ethereum":
11066
+ return parseEVMSignatureResponse(base64Response);
11067
+ case "sui":
11068
+ return parseSuiSignatureResponse(base64Response);
11069
+ case "bip122":
11070
+ case "bitcoin":
11071
+ return parseBitcoinSignatureResponse(base64Response);
11072
+ default:
11073
+ return {
11074
+ signature: base64Response,
11075
+ rawSignature: base64Response
11076
+ };
11077
+ }
11078
+ }
11079
+ function parseTransactionResponse(base64RawTransaction, networkId, hash) {
11080
+ let rawTransaction = base64RawTransaction;
11081
+ if (isEthereumChain(networkId)) {
11082
+ try {
11083
+ const txBytes = base64urlDecode(base64RawTransaction);
11084
+ rawTransaction = "0x" + index.bufferExports.Buffer.from(txBytes).toString("hex");
11085
+ } catch (error) {
11086
+ rawTransaction = base64RawTransaction.startsWith("0x") ? base64RawTransaction : "0x" + base64RawTransaction;
11087
+ }
11088
+ }
11089
+ if (hash) {
11090
+ return {
11091
+ hash,
11092
+ rawTransaction,
11093
+ blockExplorer: getExplorerUrl(networkId, "transaction", hash)
11094
+ };
11095
+ } else {
11096
+ return {
11097
+ rawTransaction
11098
+ };
11099
+ }
11100
+ }
11101
+ function parseSolanaSignatureResponse(base64Response) {
11102
+ try {
11103
+ const signatureBytes = base64urlDecode(base64Response);
11104
+ const signature = index_native.base58.encode(signatureBytes);
11105
+ return {
11106
+ signature,
11107
+ rawSignature: base64Response
11108
+ };
11109
+ } catch (error) {
11110
+ return {
11111
+ signature: base64Response,
11112
+ rawSignature: base64Response
11113
+ };
11114
+ }
11115
+ }
11116
+ function parseEVMSignatureResponse(base64Response) {
11117
+ const signatureBytes = base64urlDecode(base64Response);
11118
+ const signature = "0x" + index.bufferExports.Buffer.from(signatureBytes).toString("hex");
11119
+ return {
11120
+ signature,
11121
+ rawSignature: base64Response
11122
+ };
11123
+ }
11124
+ function parseSuiSignatureResponse(base64Response) {
11125
+ try {
11126
+ const signatureBytes = base64urlDecode(base64Response);
11127
+ const signature = index.bufferExports.Buffer.from(signatureBytes).toString("base64");
11128
+ return {
11129
+ signature,
11130
+ rawSignature: base64Response
11131
+ };
11132
+ } catch (error) {
11133
+ return {
11134
+ signature: base64Response,
11135
+ rawSignature: base64Response
11136
+ };
11137
+ }
11138
+ }
11139
+ function parseBitcoinSignatureResponse(base64Response) {
11140
+ try {
11141
+ const signatureBytes = base64urlDecode(base64Response);
11142
+ const signature = index.bufferExports.Buffer.from(signatureBytes).toString("hex");
11143
+ return {
11144
+ signature,
11145
+ rawSignature: base64Response
11146
+ };
11147
+ } catch (error) {
11148
+ return {
11149
+ signature: base64Response,
11150
+ rawSignature: base64Response
11151
+ };
11152
+ }
11153
+ }
11154
+ function parseSolanaSignedTransaction(base64RawTransaction) {
11155
+ try {
11156
+ const transactionBytes = base64urlDecode(base64RawTransaction);
11157
+ return deserializeSolanaTransaction(transactionBytes);
11158
+ } catch (error) {
11159
+ return null;
11160
+ }
11161
+ }
11162
+ function deserializeSolanaTransaction(transactionBytes) {
11163
+ try {
11164
+ const transaction = web3_js.Transaction.from(transactionBytes);
11165
+ return transaction;
11166
+ } catch (legacyError) {
11167
+ if (legacyError instanceof Error && legacyError.message.includes("Versioned messages")) {
11168
+ const versionedTransaction = web3_js.VersionedTransaction.deserialize(transactionBytes);
11169
+ return versionedTransaction;
11170
+ }
11171
+ throw legacyError;
11172
+ }
11173
+ }
11174
+
11175
+ // src/index.ts
11176
+ async function parseToKmsTransaction(transaction, networkId) {
11177
+ const networkPrefix = networkId.split(":")[0].toLowerCase();
11178
+ switch (networkPrefix) {
11179
+ case "solana":
11180
+ return parseSolanaTransactionToBase64Url(transaction);
11181
+ case "ethereum":
11182
+ case "eip155":
11183
+ case "polygon":
11184
+ case "optimism":
11185
+ case "arbitrum":
11186
+ case "base":
11187
+ return parseEVMTransactionToHex(transaction);
11188
+ case "sui":
11189
+ return await parseSuiTransactionToBase64Url(transaction);
11190
+ case "bitcoin":
11191
+ return parseBitcoinTransactionToBase64Url(transaction);
11192
+ default:
11193
+ throw new Error(`Unsupported network: ${networkPrefix}`);
11194
+ }
11195
+ }
11196
+ function parseSolanaTransactionToBase64Url(transaction) {
11197
+ if (transaction?.messageBytes != null) {
11198
+ return {
11199
+ parsed: base64urlEncode(transaction.messageBytes),
11200
+ originalFormat: "@solana/kit"
11201
+ };
11202
+ }
11203
+ if (typeof transaction?.serialize === "function") {
11204
+ const serialized = transaction.serialize({
11205
+ requireAllSignatures: false,
11206
+ verifySignatures: false
11207
+ });
11208
+ return {
11209
+ parsed: base64urlEncode(serialized),
11210
+ originalFormat: "@solana/web3.js"
11211
+ };
11212
+ }
11213
+ if (transaction instanceof Uint8Array) {
11214
+ return {
11215
+ parsed: base64urlEncode(transaction),
11216
+ originalFormat: "bytes"
11217
+ };
11218
+ }
11219
+ if (typeof transaction === "string") {
11220
+ try {
11221
+ const bytes = index.bufferExports.Buffer.from(transaction, "base64");
11222
+ return {
11223
+ parsed: base64urlEncode(new Uint8Array(bytes)),
11224
+ originalFormat: "base64"
11225
+ };
11226
+ } catch {
11227
+ throw new Error("Unsupported Solana transaction format");
11228
+ }
11229
+ }
11230
+ throw new Error("Unsupported Solana transaction format");
11231
+ }
11232
+ function parseEVMTransactionToHex(transaction) {
11233
+ if (typeof transaction === "string" && transaction.startsWith("0x")) {
11234
+ return {
11235
+ parsed: transaction,
11236
+ originalFormat: "hex"
11237
+ };
11238
+ }
11239
+ if (transaction?.serialize && typeof transaction.serialize === "function") {
11240
+ const serialized = transaction.serialize();
11241
+ const hex = serialized.startsWith("0x") ? serialized : "0x" + serialized;
11242
+ return {
11243
+ parsed: hex,
11244
+ originalFormat: "ethers"
11245
+ };
11246
+ }
11247
+ if (transaction instanceof Uint8Array) {
11248
+ const hex = "0x" + index.bufferExports.Buffer.from(transaction).toString("hex");
11249
+ return {
11250
+ parsed: hex,
11251
+ originalFormat: "bytes"
11252
+ };
11253
+ }
11254
+ if (transaction && typeof transaction === "object" && (transaction.to || transaction.data || transaction.from)) {
11255
+ try {
11256
+ const { from, gas, ...txForSerialization } = transaction;
11257
+ if (gas) {
11258
+ txForSerialization.gasLimit = gas;
11259
+ }
11260
+ if (!txForSerialization.gasLimit) {
11261
+ if (txForSerialization.to && txForSerialization.value && !txForSerialization.data) {
11262
+ txForSerialization.gasLimit = "0x5208";
11263
+ }
11264
+ }
11265
+ if (txForSerialization.to && typeof txForSerialization.to === "string") {
11266
+ try {
11267
+ txForSerialization.to = getAddress(txForSerialization.to);
11268
+ } catch {
11269
+ txForSerialization.to = txForSerialization.to.toLowerCase();
8649
11270
  }
8650
- return result;
11271
+ }
11272
+ const serialized = Transaction.from(txForSerialization).unsignedSerialized;
11273
+ const hex = serialized.startsWith("0x") ? serialized : "0x" + serialized;
11274
+ return {
11275
+ parsed: hex,
11276
+ originalFormat: "json"
11277
+ };
11278
+ } catch (error) {
11279
+ const errorMessage = error instanceof Error ? error.message : "Unknown error";
11280
+ const txKeys = transaction ? Object.keys(transaction).join(", ") : "N/A";
11281
+ const txValues = transaction ? JSON.stringify(transaction, null, 2) : "N/A";
11282
+ throw new Error(
11283
+ `Failed to RLP encode EVM transaction: ${errorMessage}.
11284
+ Transaction keys: [${txKeys}].
11285
+ Transaction: ${txValues}
11286
+ Please ensure the transaction object includes required fields (to, value, chainId, gasLimit or gasPrice, etc.)`
11287
+ );
11288
+ }
11289
+ }
11290
+ throw new Error(
11291
+ "Unsupported EVM transaction format. Expected hex string, bytes, or transaction object with 'to', 'data', or 'from' fields."
11292
+ );
11293
+ }
11294
+ async function parseSuiTransactionToBase64Url(transaction) {
11295
+ if (transaction?.serialize && typeof transaction.serialize === "function") {
11296
+ const serialized = transaction.serialize();
11297
+ return {
11298
+ parsed: base64urlEncode(serialized),
11299
+ originalFormat: "sui-sdk"
11300
+ };
11301
+ }
11302
+ if (transaction instanceof Uint8Array) {
11303
+ return {
11304
+ parsed: base64urlEncode(transaction),
11305
+ originalFormat: "bytes"
11306
+ };
11307
+ }
11308
+ if (transaction?.build && typeof transaction.build === "function") {
11309
+ const built = await transaction.build();
11310
+ if (built?.serialize && typeof built.serialize === "function") {
11311
+ const serialized = built.serialize();
11312
+ return {
11313
+ parsed: base64urlEncode(serialized),
11314
+ originalFormat: "transaction-block"
11315
+ };
8651
11316
  }
11317
+ }
11318
+ throw new Error("Unsupported Sui transaction format");
11319
+ }
11320
+ function parseBitcoinTransactionToBase64Url(transaction) {
11321
+ if (transaction?.toBuffer && typeof transaction.toBuffer === "function") {
11322
+ const buffer = transaction.toBuffer();
11323
+ return {
11324
+ parsed: base64urlEncode(new Uint8Array(buffer)),
11325
+ originalFormat: "bitcoinjs-lib"
11326
+ };
11327
+ }
11328
+ if (transaction instanceof Uint8Array) {
11329
+ return {
11330
+ parsed: base64urlEncode(transaction),
11331
+ originalFormat: "bytes"
11332
+ };
11333
+ }
11334
+ if (typeof transaction === "string") {
11335
+ const bytes = new Uint8Array(index.bufferExports.Buffer.from(transaction, "hex"));
11336
+ return {
11337
+ parsed: base64urlEncode(bytes),
11338
+ originalFormat: "hex"
11339
+ };
11340
+ }
11341
+ throw new Error("Unsupported Bitcoin transaction format");
8652
11342
  }
8653
11343
 
8654
- // src/index.ts
8655
- function parseSignMessageResponse(base64Response, networkId) {
8656
- const networkPrefix = networkId.split(":")[0].toLowerCase();
8657
- switch (networkPrefix) {
8658
- case "solana":
8659
- return parseSolanaSignatureResponse(base64Response);
8660
- case "eip155":
8661
- case "ethereum":
8662
- return parseEVMSignatureResponse(base64Response);
8663
- case "sui":
8664
- return parseSuiSignatureResponse(base64Response);
8665
- case "bip122":
8666
- case "bitcoin":
8667
- return parseBitcoinSignatureResponse(base64Response);
8668
- default:
8669
- return {
8670
- signature: base64Response,
8671
- rawSignature: base64Response
8672
- };
8673
- }
8674
- }
8675
- function parseTransactionResponse(base64RawTransaction, networkId, hash) {
8676
- let rawTransaction = base64RawTransaction;
8677
- if (isEthereumChain(networkId)) {
8678
- try {
8679
- const txBytes = base64urlDecode(base64RawTransaction);
8680
- rawTransaction = "0x" + index.bufferExports.Buffer.from(txBytes).toString("hex");
8681
- } catch (error) {
8682
- rawTransaction = base64RawTransaction.startsWith("0x") ? base64RawTransaction : "0x" + base64RawTransaction;
8683
- }
8684
- }
8685
- if (hash) {
8686
- return {
8687
- hash,
8688
- rawTransaction,
8689
- blockExplorer: getExplorerUrl(networkId, "transaction", hash)
8690
- };
8691
- } else {
8692
- return {
8693
- rawTransaction
8694
- };
8695
- }
8696
- }
8697
- function parseSolanaSignatureResponse(base64Response) {
8698
- try {
8699
- const signatureBytes = base64urlDecode(base64Response);
8700
- const signature = index_native.base58.encode(signatureBytes);
8701
- return {
8702
- signature,
8703
- rawSignature: base64Response
8704
- };
8705
- } catch (error) {
8706
- return {
8707
- signature: base64Response,
8708
- rawSignature: base64Response
8709
- };
8710
- }
8711
- }
8712
- function parseEVMSignatureResponse(base64Response) {
8713
- const signatureBytes = base64urlDecode(base64Response);
8714
- const signature = "0x" + index.bufferExports.Buffer.from(signatureBytes).toString("hex");
8715
- return {
8716
- signature,
8717
- rawSignature: base64Response
8718
- };
8719
- }
8720
- function parseSuiSignatureResponse(base64Response) {
8721
- try {
8722
- const signatureBytes = base64urlDecode(base64Response);
8723
- const signature = index.bufferExports.Buffer.from(signatureBytes).toString("base64");
8724
- return {
8725
- signature,
8726
- rawSignature: base64Response
8727
- };
8728
- } catch (error) {
8729
- return {
8730
- signature: base64Response,
8731
- rawSignature: base64Response
8732
- };
8733
- }
8734
- }
8735
- function parseBitcoinSignatureResponse(base64Response) {
8736
- try {
8737
- const signatureBytes = base64urlDecode(base64Response);
8738
- const signature = index.bufferExports.Buffer.from(signatureBytes).toString("hex");
8739
- return {
8740
- signature,
8741
- rawSignature: base64Response
8742
- };
8743
- } catch (error) {
8744
- return {
8745
- signature: base64Response,
8746
- rawSignature: base64Response
8747
- };
8748
- }
8749
- }
8750
- function parseSolanaSignedTransaction(base64RawTransaction) {
8751
- try {
8752
- const transactionBytes = base64urlDecode(base64RawTransaction);
8753
- return deserializeSolanaTransaction(transactionBytes);
8754
- } catch (error) {
8755
- return null;
8756
- }
8757
- }
8758
- function deserializeSolanaTransaction(transactionBytes) {
8759
- try {
8760
- const transaction = web3_js.Transaction.from(transactionBytes);
8761
- return transaction;
8762
- } catch (legacyError) {
8763
- if (legacyError instanceof Error && legacyError.message.includes("Versioned messages")) {
8764
- const versionedTransaction = web3_js.VersionedTransaction.deserialize(transactionBytes);
8765
- return versionedTransaction;
8766
- }
8767
- throw legacyError;
8768
- }
8769
- }
11344
+ var eventemitter3 = {exports: {}};
11345
+
11346
+ var hasRequiredEventemitter3;
11347
+
11348
+ function requireEventemitter3 () {
11349
+ if (hasRequiredEventemitter3) return eventemitter3.exports;
11350
+ hasRequiredEventemitter3 = 1;
11351
+ (function (module) {
11352
+
11353
+ var has = Object.prototype.hasOwnProperty
11354
+ , prefix = '~';
11355
+
11356
+ /**
11357
+ * Constructor to create a storage for our `EE` objects.
11358
+ * An `Events` instance is a plain object whose properties are event names.
11359
+ *
11360
+ * @constructor
11361
+ * @private
11362
+ */
11363
+ function Events() {}
11364
+
11365
+ //
11366
+ // We try to not inherit from `Object.prototype`. In some engines creating an
11367
+ // instance in this way is faster than calling `Object.create(null)` directly.
11368
+ // If `Object.create(null)` is not supported we prefix the event names with a
11369
+ // character to make sure that the built-in object properties are not
11370
+ // overridden or used as an attack vector.
11371
+ //
11372
+ if (Object.create) {
11373
+ Events.prototype = Object.create(null);
11374
+
11375
+ //
11376
+ // This hack is needed because the `__proto__` property is still inherited in
11377
+ // some old browsers like Android 4, iPhone 5.1, Opera 11 and Safari 5.
11378
+ //
11379
+ if (!new Events().__proto__) prefix = false;
11380
+ }
11381
+
11382
+ /**
11383
+ * Representation of a single event listener.
11384
+ *
11385
+ * @param {Function} fn The listener function.
11386
+ * @param {*} context The context to invoke the listener with.
11387
+ * @param {Boolean} [once=false] Specify if the listener is a one-time listener.
11388
+ * @constructor
11389
+ * @private
11390
+ */
11391
+ function EE(fn, context, once) {
11392
+ this.fn = fn;
11393
+ this.context = context;
11394
+ this.once = once || false;
11395
+ }
11396
+
11397
+ /**
11398
+ * Add a listener for a given event.
11399
+ *
11400
+ * @param {EventEmitter} emitter Reference to the `EventEmitter` instance.
11401
+ * @param {(String|Symbol)} event The event name.
11402
+ * @param {Function} fn The listener function.
11403
+ * @param {*} context The context to invoke the listener with.
11404
+ * @param {Boolean} once Specify if the listener is a one-time listener.
11405
+ * @returns {EventEmitter}
11406
+ * @private
11407
+ */
11408
+ function addListener(emitter, event, fn, context, once) {
11409
+ if (typeof fn !== 'function') {
11410
+ throw new TypeError('The listener must be a function');
11411
+ }
11412
+
11413
+ var listener = new EE(fn, context || emitter, once)
11414
+ , evt = prefix ? prefix + event : event;
11415
+
11416
+ if (!emitter._events[evt]) emitter._events[evt] = listener, emitter._eventsCount++;
11417
+ else if (!emitter._events[evt].fn) emitter._events[evt].push(listener);
11418
+ else emitter._events[evt] = [emitter._events[evt], listener];
11419
+
11420
+ return emitter;
11421
+ }
11422
+
11423
+ /**
11424
+ * Clear event by name.
11425
+ *
11426
+ * @param {EventEmitter} emitter Reference to the `EventEmitter` instance.
11427
+ * @param {(String|Symbol)} evt The Event name.
11428
+ * @private
11429
+ */
11430
+ function clearEvent(emitter, evt) {
11431
+ if (--emitter._eventsCount === 0) emitter._events = new Events();
11432
+ else delete emitter._events[evt];
11433
+ }
11434
+
11435
+ /**
11436
+ * Minimal `EventEmitter` interface that is molded against the Node.js
11437
+ * `EventEmitter` interface.
11438
+ *
11439
+ * @constructor
11440
+ * @public
11441
+ */
11442
+ function EventEmitter() {
11443
+ this._events = new Events();
11444
+ this._eventsCount = 0;
11445
+ }
11446
+
11447
+ /**
11448
+ * Return an array listing the events for which the emitter has registered
11449
+ * listeners.
11450
+ *
11451
+ * @returns {Array}
11452
+ * @public
11453
+ */
11454
+ EventEmitter.prototype.eventNames = function eventNames() {
11455
+ var names = []
11456
+ , events
11457
+ , name;
11458
+
11459
+ if (this._eventsCount === 0) return names;
11460
+
11461
+ for (name in (events = this._events)) {
11462
+ if (has.call(events, name)) names.push(prefix ? name.slice(1) : name);
11463
+ }
11464
+
11465
+ if (Object.getOwnPropertySymbols) {
11466
+ return names.concat(Object.getOwnPropertySymbols(events));
11467
+ }
11468
+
11469
+ return names;
11470
+ };
11471
+
11472
+ /**
11473
+ * Return the listeners registered for a given event.
11474
+ *
11475
+ * @param {(String|Symbol)} event The event name.
11476
+ * @returns {Array} The registered listeners.
11477
+ * @public
11478
+ */
11479
+ EventEmitter.prototype.listeners = function listeners(event) {
11480
+ var evt = prefix ? prefix + event : event
11481
+ , handlers = this._events[evt];
11482
+
11483
+ if (!handlers) return [];
11484
+ if (handlers.fn) return [handlers.fn];
11485
+
11486
+ for (var i = 0, l = handlers.length, ee = new Array(l); i < l; i++) {
11487
+ ee[i] = handlers[i].fn;
11488
+ }
11489
+
11490
+ return ee;
11491
+ };
11492
+
11493
+ /**
11494
+ * Return the number of listeners listening to a given event.
11495
+ *
11496
+ * @param {(String|Symbol)} event The event name.
11497
+ * @returns {Number} The number of listeners.
11498
+ * @public
11499
+ */
11500
+ EventEmitter.prototype.listenerCount = function listenerCount(event) {
11501
+ var evt = prefix ? prefix + event : event
11502
+ , listeners = this._events[evt];
11503
+
11504
+ if (!listeners) return 0;
11505
+ if (listeners.fn) return 1;
11506
+ return listeners.length;
11507
+ };
11508
+
11509
+ /**
11510
+ * Calls each of the listeners registered for a given event.
11511
+ *
11512
+ * @param {(String|Symbol)} event The event name.
11513
+ * @returns {Boolean} `true` if the event had listeners, else `false`.
11514
+ * @public
11515
+ */
11516
+ EventEmitter.prototype.emit = function emit(event, a1, a2, a3, a4, a5) {
11517
+ var evt = prefix ? prefix + event : event;
11518
+
11519
+ if (!this._events[evt]) return false;
11520
+
11521
+ var listeners = this._events[evt]
11522
+ , len = arguments.length
11523
+ , args
11524
+ , i;
11525
+
11526
+ if (listeners.fn) {
11527
+ if (listeners.once) this.removeListener(event, listeners.fn, undefined, true);
11528
+
11529
+ switch (len) {
11530
+ case 1: return listeners.fn.call(listeners.context), true;
11531
+ case 2: return listeners.fn.call(listeners.context, a1), true;
11532
+ case 3: return listeners.fn.call(listeners.context, a1, a2), true;
11533
+ case 4: return listeners.fn.call(listeners.context, a1, a2, a3), true;
11534
+ case 5: return listeners.fn.call(listeners.context, a1, a2, a3, a4), true;
11535
+ case 6: return listeners.fn.call(listeners.context, a1, a2, a3, a4, a5), true;
11536
+ }
11537
+
11538
+ for (i = 1, args = new Array(len -1); i < len; i++) {
11539
+ args[i - 1] = arguments[i];
11540
+ }
11541
+
11542
+ listeners.fn.apply(listeners.context, args);
11543
+ } else {
11544
+ var length = listeners.length
11545
+ , j;
11546
+
11547
+ for (i = 0; i < length; i++) {
11548
+ if (listeners[i].once) this.removeListener(event, listeners[i].fn, undefined, true);
11549
+
11550
+ switch (len) {
11551
+ case 1: listeners[i].fn.call(listeners[i].context); break;
11552
+ case 2: listeners[i].fn.call(listeners[i].context, a1); break;
11553
+ case 3: listeners[i].fn.call(listeners[i].context, a1, a2); break;
11554
+ case 4: listeners[i].fn.call(listeners[i].context, a1, a2, a3); break;
11555
+ default:
11556
+ if (!args) for (j = 1, args = new Array(len -1); j < len; j++) {
11557
+ args[j - 1] = arguments[j];
11558
+ }
11559
+
11560
+ listeners[i].fn.apply(listeners[i].context, args);
11561
+ }
11562
+ }
11563
+ }
11564
+
11565
+ return true;
11566
+ };
11567
+
11568
+ /**
11569
+ * Add a listener for a given event.
11570
+ *
11571
+ * @param {(String|Symbol)} event The event name.
11572
+ * @param {Function} fn The listener function.
11573
+ * @param {*} [context=this] The context to invoke the listener with.
11574
+ * @returns {EventEmitter} `this`.
11575
+ * @public
11576
+ */
11577
+ EventEmitter.prototype.on = function on(event, fn, context) {
11578
+ return addListener(this, event, fn, context, false);
11579
+ };
11580
+
11581
+ /**
11582
+ * Add a one-time listener for a given event.
11583
+ *
11584
+ * @param {(String|Symbol)} event The event name.
11585
+ * @param {Function} fn The listener function.
11586
+ * @param {*} [context=this] The context to invoke the listener with.
11587
+ * @returns {EventEmitter} `this`.
11588
+ * @public
11589
+ */
11590
+ EventEmitter.prototype.once = function once(event, fn, context) {
11591
+ return addListener(this, event, fn, context, true);
11592
+ };
11593
+
11594
+ /**
11595
+ * Remove the listeners of a given event.
11596
+ *
11597
+ * @param {(String|Symbol)} event The event name.
11598
+ * @param {Function} fn Only remove the listeners that match this function.
11599
+ * @param {*} context Only remove the listeners that have this context.
11600
+ * @param {Boolean} once Only remove one-time listeners.
11601
+ * @returns {EventEmitter} `this`.
11602
+ * @public
11603
+ */
11604
+ EventEmitter.prototype.removeListener = function removeListener(event, fn, context, once) {
11605
+ var evt = prefix ? prefix + event : event;
8770
11606
 
8771
- // src/index.ts
8772
- async function parseToKmsTransaction(transaction, networkId) {
8773
- const networkPrefix = networkId.split(":")[0].toLowerCase();
8774
- switch (networkPrefix) {
8775
- case "solana":
8776
- return parseSolanaTransactionToBase64Url(transaction);
8777
- case "ethereum":
8778
- case "eip155":
8779
- case "polygon":
8780
- case "optimism":
8781
- case "arbitrum":
8782
- case "base":
8783
- return parseEVMTransactionToHex(transaction);
8784
- case "sui":
8785
- return await parseSuiTransactionToBase64Url(transaction);
8786
- case "bitcoin":
8787
- return parseBitcoinTransactionToBase64Url(transaction);
8788
- default:
8789
- throw new Error(`Unsupported network: ${networkPrefix}`);
8790
- }
8791
- }
8792
- function parseSolanaTransactionToBase64Url(transaction) {
8793
- if (transaction?.messageBytes != null) {
8794
- return {
8795
- parsed: base64urlEncode(transaction.messageBytes),
8796
- originalFormat: "@solana/kit"
8797
- };
8798
- }
8799
- if (typeof transaction?.serialize === "function") {
8800
- const serialized = transaction.serialize({
8801
- requireAllSignatures: false,
8802
- verifySignatures: false
8803
- });
8804
- return {
8805
- parsed: base64urlEncode(serialized),
8806
- originalFormat: "@solana/web3.js"
8807
- };
8808
- }
8809
- if (transaction instanceof Uint8Array) {
8810
- return {
8811
- parsed: base64urlEncode(transaction),
8812
- originalFormat: "bytes"
8813
- };
8814
- }
8815
- if (typeof transaction === "string") {
8816
- try {
8817
- const bytes = index.bufferExports.Buffer.from(transaction, "base64");
8818
- return {
8819
- parsed: base64urlEncode(new Uint8Array(bytes)),
8820
- originalFormat: "base64"
8821
- };
8822
- } catch {
8823
- throw new Error("Unsupported Solana transaction format");
8824
- }
8825
- }
8826
- throw new Error("Unsupported Solana transaction format");
8827
- }
8828
- function parseEVMTransactionToHex(transaction) {
8829
- if (typeof transaction === "string" && transaction.startsWith("0x")) {
8830
- return {
8831
- parsed: transaction,
8832
- originalFormat: "hex"
8833
- };
8834
- }
8835
- if (transaction?.serialize && typeof transaction.serialize === "function") {
8836
- const serialized = transaction.serialize();
8837
- const hex = serialized.startsWith("0x") ? serialized : "0x" + serialized;
8838
- return {
8839
- parsed: hex,
8840
- originalFormat: "ethers"
8841
- };
8842
- }
8843
- if (transaction instanceof Uint8Array) {
8844
- const hex = "0x" + index.bufferExports.Buffer.from(transaction).toString("hex");
8845
- return {
8846
- parsed: hex,
8847
- originalFormat: "bytes"
8848
- };
8849
- }
8850
- if (transaction && typeof transaction === "object" && (transaction.to || transaction.data || transaction.from)) {
8851
- try {
8852
- const { from, gas, ...txForSerialization } = transaction;
8853
- if (gas) {
8854
- txForSerialization.gasLimit = gas;
8855
- }
8856
- if (!txForSerialization.gasLimit) {
8857
- if (txForSerialization.to && txForSerialization.value && !txForSerialization.data) {
8858
- txForSerialization.gasLimit = "0x5208";
8859
- }
8860
- }
8861
- if (txForSerialization.to && typeof txForSerialization.to === "string") {
8862
- try {
8863
- txForSerialization.to = getAddress(txForSerialization.to);
8864
- } catch {
8865
- txForSerialization.to = txForSerialization.to.toLowerCase();
8866
- }
8867
- }
8868
- const serialized = Transaction.from(txForSerialization).unsignedSerialized;
8869
- const hex = serialized.startsWith("0x") ? serialized : "0x" + serialized;
8870
- return {
8871
- parsed: hex,
8872
- originalFormat: "json"
8873
- };
8874
- } catch (error) {
8875
- const errorMessage = error instanceof Error ? error.message : "Unknown error";
8876
- const txKeys = transaction ? Object.keys(transaction).join(", ") : "N/A";
8877
- const txValues = transaction ? JSON.stringify(transaction, null, 2) : "N/A";
8878
- throw new Error(
8879
- `Failed to RLP encode EVM transaction: ${errorMessage}.
8880
- Transaction keys: [${txKeys}].
8881
- Transaction: ${txValues}
8882
- Please ensure the transaction object includes required fields (to, value, chainId, gasLimit or gasPrice, etc.)`
8883
- );
8884
- }
8885
- }
8886
- throw new Error(
8887
- "Unsupported EVM transaction format. Expected hex string, bytes, or transaction object with 'to', 'data', or 'from' fields."
8888
- );
8889
- }
8890
- async function parseSuiTransactionToBase64Url(transaction) {
8891
- if (transaction?.serialize && typeof transaction.serialize === "function") {
8892
- const serialized = transaction.serialize();
8893
- return {
8894
- parsed: base64urlEncode(serialized),
8895
- originalFormat: "sui-sdk"
8896
- };
8897
- }
8898
- if (transaction instanceof Uint8Array) {
8899
- return {
8900
- parsed: base64urlEncode(transaction),
8901
- originalFormat: "bytes"
8902
- };
8903
- }
8904
- if (transaction?.build && typeof transaction.build === "function") {
8905
- const built = await transaction.build();
8906
- if (built?.serialize && typeof built.serialize === "function") {
8907
- const serialized = built.serialize();
8908
- return {
8909
- parsed: base64urlEncode(serialized),
8910
- originalFormat: "transaction-block"
8911
- };
8912
- }
8913
- }
8914
- throw new Error("Unsupported Sui transaction format");
8915
- }
8916
- function parseBitcoinTransactionToBase64Url(transaction) {
8917
- if (transaction?.toBuffer && typeof transaction.toBuffer === "function") {
8918
- const buffer = transaction.toBuffer();
8919
- return {
8920
- parsed: base64urlEncode(new Uint8Array(buffer)),
8921
- originalFormat: "bitcoinjs-lib"
8922
- };
8923
- }
8924
- if (transaction instanceof Uint8Array) {
8925
- return {
8926
- parsed: base64urlEncode(transaction),
8927
- originalFormat: "bytes"
8928
- };
8929
- }
8930
- if (typeof transaction === "string") {
8931
- const bytes = new Uint8Array(index.bufferExports.Buffer.from(transaction, "hex"));
8932
- return {
8933
- parsed: base64urlEncode(bytes),
8934
- originalFormat: "hex"
8935
- };
8936
- }
8937
- throw new Error("Unsupported Bitcoin transaction format");
11607
+ if (!this._events[evt]) return this;
11608
+ if (!fn) {
11609
+ clearEvent(this, evt);
11610
+ return this;
11611
+ }
11612
+
11613
+ var listeners = this._events[evt];
11614
+
11615
+ if (listeners.fn) {
11616
+ if (
11617
+ listeners.fn === fn &&
11618
+ (!once || listeners.once) &&
11619
+ (!context || listeners.context === context)
11620
+ ) {
11621
+ clearEvent(this, evt);
11622
+ }
11623
+ } else {
11624
+ for (var i = 0, events = [], length = listeners.length; i < length; i++) {
11625
+ if (
11626
+ listeners[i].fn !== fn ||
11627
+ (once && !listeners[i].once) ||
11628
+ (context && listeners[i].context !== context)
11629
+ ) {
11630
+ events.push(listeners[i]);
11631
+ }
11632
+ }
11633
+
11634
+ //
11635
+ // Reset the array, or remove it completely if we have no more listeners.
11636
+ //
11637
+ if (events.length) this._events[evt] = events.length === 1 ? events[0] : events;
11638
+ else clearEvent(this, evt);
11639
+ }
11640
+
11641
+ return this;
11642
+ };
11643
+
11644
+ /**
11645
+ * Remove all listeners, or those of the specified event.
11646
+ *
11647
+ * @param {(String|Symbol)} [event] The event name.
11648
+ * @returns {EventEmitter} `this`.
11649
+ * @public
11650
+ */
11651
+ EventEmitter.prototype.removeAllListeners = function removeAllListeners(event) {
11652
+ var evt;
11653
+
11654
+ if (event) {
11655
+ evt = prefix ? prefix + event : event;
11656
+ if (this._events[evt]) clearEvent(this, evt);
11657
+ } else {
11658
+ this._events = new Events();
11659
+ this._eventsCount = 0;
11660
+ }
11661
+
11662
+ return this;
11663
+ };
11664
+
11665
+ //
11666
+ // Alias methods names because people roll like that.
11667
+ //
11668
+ EventEmitter.prototype.off = EventEmitter.prototype.removeListener;
11669
+ EventEmitter.prototype.addListener = EventEmitter.prototype.on;
11670
+
11671
+ //
11672
+ // Expose the prefix.
11673
+ //
11674
+ EventEmitter.prefixed = prefix;
11675
+
11676
+ //
11677
+ // Allow `EventEmitter` to be imported as module namespace.
11678
+ //
11679
+ EventEmitter.EventEmitter = EventEmitter;
11680
+
11681
+ //
11682
+ // Expose the module.
11683
+ //
11684
+ {
11685
+ module.exports = EventEmitter;
11686
+ }
11687
+ } (eventemitter3));
11688
+ return eventemitter3.exports;
8938
11689
  }
8939
11690
 
11691
+ var eventemitter3Exports = requireEventemitter3();
11692
+ var EventEmitter2 = /*@__PURE__*/index_native.getDefaultExportFromCjs(eventemitter3Exports);
11693
+
8940
11694
  // src/embedded-provider.ts
8941
11695
 
8942
11696
  // src/constants.ts
@@ -8948,7 +11702,7 @@ var EmbeddedSolanaChain = class {
8948
11702
  this.currentNetworkId = NetworkId.SOLANA_MAINNET;
8949
11703
  this._connected = false;
8950
11704
  this._publicKey = null;
8951
- this.eventEmitter = new EventEmitter3();
11705
+ this.eventEmitter = new EventEmitter2();
8952
11706
  this.setupEventListeners();
8953
11707
  this.syncInitialState();
8954
11708
  }
@@ -9078,7 +11832,7 @@ var EmbeddedEthereumChain = class {
9078
11832
  this.currentNetworkId = NetworkId.ETHEREUM_MAINNET;
9079
11833
  this._connected = false;
9080
11834
  this._accounts = [];
9081
- this.eventEmitter = new EventEmitter3();
11835
+ this.eventEmitter = new EventEmitter2();
9082
11836
  this.setupEventListeners();
9083
11837
  this.syncInitialState();
9084
11838
  }
@@ -15778,4 +18532,4 @@ exports.useModal = useModal;
15778
18532
  exports.usePhantom = usePhantom;
15779
18533
  exports.useSolana = useSolana;
15780
18534
  exports.useTheme = useTheme;
15781
- //# sourceMappingURL=index-BzeiIIwF.js.map
18535
+ //# sourceMappingURL=index-DYBdUxnT.js.map