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