@pooflabs/web 0.0.36 → 0.0.37
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/{index-Bfy2Olqg.js → index-B08xJEBy.js} +2423 -1227
- package/dist/index-B08xJEBy.js.map +1 -0
- package/dist/{index-BwuRyd6v.js → index-B3jRsGVB.js} +6140 -5614
- package/dist/index-B3jRsGVB.js.map +1 -0
- package/dist/{index-DuYoGtxT.esm.js → index-BshwKDlr.esm.js} +6137 -5614
- package/dist/index-BshwKDlr.esm.js.map +1 -0
- package/dist/{index-BnwDqQL8.esm.js → index-DD_zltED.esm.js} +2418 -1222
- package/dist/index-DD_zltED.esm.js.map +1 -0
- package/dist/index.esm.js +1 -1
- package/dist/index.js +1 -1
- package/package.json +2 -2
- package/dist/index-Bfy2Olqg.js.map +0 -1
- package/dist/index-BnwDqQL8.esm.js.map +0 -1
- package/dist/index-BwuRyd6v.js.map +0 -1
- package/dist/index-DuYoGtxT.esm.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-
|
|
5
|
+
var index = require('./index-B3jRsGVB.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
|
var src;
|
|
1022
3426
|
var hasRequiredSrc;
|
|
1023
3427
|
|
|
@@ -1150,17 +3554,17 @@ function requireSrc () {
|
|
|
1150
3554
|
return src;
|
|
1151
3555
|
}
|
|
1152
3556
|
|
|
1153
|
-
var bs58
|
|
3557
|
+
var bs58;
|
|
1154
3558
|
var hasRequiredBs58;
|
|
1155
3559
|
|
|
1156
3560
|
function requireBs58 () {
|
|
1157
|
-
if (hasRequiredBs58) return bs58
|
|
3561
|
+
if (hasRequiredBs58) return bs58;
|
|
1158
3562
|
hasRequiredBs58 = 1;
|
|
1159
3563
|
const basex = requireSrc();
|
|
1160
3564
|
const ALPHABET = '123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz';
|
|
1161
3565
|
|
|
1162
|
-
bs58
|
|
1163
|
-
return bs58
|
|
3566
|
+
bs58 = basex(ALPHABET);
|
|
3567
|
+
return bs58;
|
|
1164
3568
|
}
|
|
1165
3569
|
|
|
1166
3570
|
requireBs58();
|
|
@@ -2875,356 +5279,6 @@ function createAutoConfirmPlugin() {
|
|
|
2875
5279
|
};
|
|
2876
5280
|
}
|
|
2877
5281
|
|
|
2878
|
-
var eventemitter3$1 = {exports: {}};
|
|
2879
|
-
|
|
2880
|
-
var hasRequiredEventemitter3$1;
|
|
2881
|
-
|
|
2882
|
-
function requireEventemitter3$1 () {
|
|
2883
|
-
if (hasRequiredEventemitter3$1) return eventemitter3$1.exports;
|
|
2884
|
-
hasRequiredEventemitter3$1 = 1;
|
|
2885
|
-
(function (module) {
|
|
2886
|
-
|
|
2887
|
-
var has = Object.prototype.hasOwnProperty
|
|
2888
|
-
, prefix = '~';
|
|
2889
|
-
|
|
2890
|
-
/**
|
|
2891
|
-
* Constructor to create a storage for our `EE` objects.
|
|
2892
|
-
* An `Events` instance is a plain object whose properties are event names.
|
|
2893
|
-
*
|
|
2894
|
-
* @constructor
|
|
2895
|
-
* @private
|
|
2896
|
-
*/
|
|
2897
|
-
function Events() {}
|
|
2898
|
-
|
|
2899
|
-
//
|
|
2900
|
-
// We try to not inherit from `Object.prototype`. In some engines creating an
|
|
2901
|
-
// instance in this way is faster than calling `Object.create(null)` directly.
|
|
2902
|
-
// If `Object.create(null)` is not supported we prefix the event names with a
|
|
2903
|
-
// character to make sure that the built-in object properties are not
|
|
2904
|
-
// overridden or used as an attack vector.
|
|
2905
|
-
//
|
|
2906
|
-
if (Object.create) {
|
|
2907
|
-
Events.prototype = Object.create(null);
|
|
2908
|
-
|
|
2909
|
-
//
|
|
2910
|
-
// This hack is needed because the `__proto__` property is still inherited in
|
|
2911
|
-
// some old browsers like Android 4, iPhone 5.1, Opera 11 and Safari 5.
|
|
2912
|
-
//
|
|
2913
|
-
if (!new Events().__proto__) prefix = false;
|
|
2914
|
-
}
|
|
2915
|
-
|
|
2916
|
-
/**
|
|
2917
|
-
* Representation of a single event listener.
|
|
2918
|
-
*
|
|
2919
|
-
* @param {Function} fn The listener function.
|
|
2920
|
-
* @param {*} context The context to invoke the listener with.
|
|
2921
|
-
* @param {Boolean} [once=false] Specify if the listener is a one-time listener.
|
|
2922
|
-
* @constructor
|
|
2923
|
-
* @private
|
|
2924
|
-
*/
|
|
2925
|
-
function EE(fn, context, once) {
|
|
2926
|
-
this.fn = fn;
|
|
2927
|
-
this.context = context;
|
|
2928
|
-
this.once = once || false;
|
|
2929
|
-
}
|
|
2930
|
-
|
|
2931
|
-
/**
|
|
2932
|
-
* Add a listener for a given event.
|
|
2933
|
-
*
|
|
2934
|
-
* @param {EventEmitter} emitter Reference to the `EventEmitter` instance.
|
|
2935
|
-
* @param {(String|Symbol)} event The event name.
|
|
2936
|
-
* @param {Function} fn The listener function.
|
|
2937
|
-
* @param {*} context The context to invoke the listener with.
|
|
2938
|
-
* @param {Boolean} once Specify if the listener is a one-time listener.
|
|
2939
|
-
* @returns {EventEmitter}
|
|
2940
|
-
* @private
|
|
2941
|
-
*/
|
|
2942
|
-
function addListener(emitter, event, fn, context, once) {
|
|
2943
|
-
if (typeof fn !== 'function') {
|
|
2944
|
-
throw new TypeError('The listener must be a function');
|
|
2945
|
-
}
|
|
2946
|
-
|
|
2947
|
-
var listener = new EE(fn, context || emitter, once)
|
|
2948
|
-
, evt = prefix ? prefix + event : event;
|
|
2949
|
-
|
|
2950
|
-
if (!emitter._events[evt]) emitter._events[evt] = listener, emitter._eventsCount++;
|
|
2951
|
-
else if (!emitter._events[evt].fn) emitter._events[evt].push(listener);
|
|
2952
|
-
else emitter._events[evt] = [emitter._events[evt], listener];
|
|
2953
|
-
|
|
2954
|
-
return emitter;
|
|
2955
|
-
}
|
|
2956
|
-
|
|
2957
|
-
/**
|
|
2958
|
-
* Clear event by name.
|
|
2959
|
-
*
|
|
2960
|
-
* @param {EventEmitter} emitter Reference to the `EventEmitter` instance.
|
|
2961
|
-
* @param {(String|Symbol)} evt The Event name.
|
|
2962
|
-
* @private
|
|
2963
|
-
*/
|
|
2964
|
-
function clearEvent(emitter, evt) {
|
|
2965
|
-
if (--emitter._eventsCount === 0) emitter._events = new Events();
|
|
2966
|
-
else delete emitter._events[evt];
|
|
2967
|
-
}
|
|
2968
|
-
|
|
2969
|
-
/**
|
|
2970
|
-
* Minimal `EventEmitter` interface that is molded against the Node.js
|
|
2971
|
-
* `EventEmitter` interface.
|
|
2972
|
-
*
|
|
2973
|
-
* @constructor
|
|
2974
|
-
* @public
|
|
2975
|
-
*/
|
|
2976
|
-
function EventEmitter() {
|
|
2977
|
-
this._events = new Events();
|
|
2978
|
-
this._eventsCount = 0;
|
|
2979
|
-
}
|
|
2980
|
-
|
|
2981
|
-
/**
|
|
2982
|
-
* Return an array listing the events for which the emitter has registered
|
|
2983
|
-
* listeners.
|
|
2984
|
-
*
|
|
2985
|
-
* @returns {Array}
|
|
2986
|
-
* @public
|
|
2987
|
-
*/
|
|
2988
|
-
EventEmitter.prototype.eventNames = function eventNames() {
|
|
2989
|
-
var names = []
|
|
2990
|
-
, events
|
|
2991
|
-
, name;
|
|
2992
|
-
|
|
2993
|
-
if (this._eventsCount === 0) return names;
|
|
2994
|
-
|
|
2995
|
-
for (name in (events = this._events)) {
|
|
2996
|
-
if (has.call(events, name)) names.push(prefix ? name.slice(1) : name);
|
|
2997
|
-
}
|
|
2998
|
-
|
|
2999
|
-
if (Object.getOwnPropertySymbols) {
|
|
3000
|
-
return names.concat(Object.getOwnPropertySymbols(events));
|
|
3001
|
-
}
|
|
3002
|
-
|
|
3003
|
-
return names;
|
|
3004
|
-
};
|
|
3005
|
-
|
|
3006
|
-
/**
|
|
3007
|
-
* Return the listeners registered for a given event.
|
|
3008
|
-
*
|
|
3009
|
-
* @param {(String|Symbol)} event The event name.
|
|
3010
|
-
* @returns {Array} The registered listeners.
|
|
3011
|
-
* @public
|
|
3012
|
-
*/
|
|
3013
|
-
EventEmitter.prototype.listeners = function listeners(event) {
|
|
3014
|
-
var evt = prefix ? prefix + event : event
|
|
3015
|
-
, handlers = this._events[evt];
|
|
3016
|
-
|
|
3017
|
-
if (!handlers) return [];
|
|
3018
|
-
if (handlers.fn) return [handlers.fn];
|
|
3019
|
-
|
|
3020
|
-
for (var i = 0, l = handlers.length, ee = new Array(l); i < l; i++) {
|
|
3021
|
-
ee[i] = handlers[i].fn;
|
|
3022
|
-
}
|
|
3023
|
-
|
|
3024
|
-
return ee;
|
|
3025
|
-
};
|
|
3026
|
-
|
|
3027
|
-
/**
|
|
3028
|
-
* Return the number of listeners listening to a given event.
|
|
3029
|
-
*
|
|
3030
|
-
* @param {(String|Symbol)} event The event name.
|
|
3031
|
-
* @returns {Number} The number of listeners.
|
|
3032
|
-
* @public
|
|
3033
|
-
*/
|
|
3034
|
-
EventEmitter.prototype.listenerCount = function listenerCount(event) {
|
|
3035
|
-
var evt = prefix ? prefix + event : event
|
|
3036
|
-
, listeners = this._events[evt];
|
|
3037
|
-
|
|
3038
|
-
if (!listeners) return 0;
|
|
3039
|
-
if (listeners.fn) return 1;
|
|
3040
|
-
return listeners.length;
|
|
3041
|
-
};
|
|
3042
|
-
|
|
3043
|
-
/**
|
|
3044
|
-
* Calls each of the listeners registered for a given event.
|
|
3045
|
-
*
|
|
3046
|
-
* @param {(String|Symbol)} event The event name.
|
|
3047
|
-
* @returns {Boolean} `true` if the event had listeners, else `false`.
|
|
3048
|
-
* @public
|
|
3049
|
-
*/
|
|
3050
|
-
EventEmitter.prototype.emit = function emit(event, a1, a2, a3, a4, a5) {
|
|
3051
|
-
var evt = prefix ? prefix + event : event;
|
|
3052
|
-
|
|
3053
|
-
if (!this._events[evt]) return false;
|
|
3054
|
-
|
|
3055
|
-
var listeners = this._events[evt]
|
|
3056
|
-
, len = arguments.length
|
|
3057
|
-
, args
|
|
3058
|
-
, i;
|
|
3059
|
-
|
|
3060
|
-
if (listeners.fn) {
|
|
3061
|
-
if (listeners.once) this.removeListener(event, listeners.fn, undefined, true);
|
|
3062
|
-
|
|
3063
|
-
switch (len) {
|
|
3064
|
-
case 1: return listeners.fn.call(listeners.context), true;
|
|
3065
|
-
case 2: return listeners.fn.call(listeners.context, a1), true;
|
|
3066
|
-
case 3: return listeners.fn.call(listeners.context, a1, a2), true;
|
|
3067
|
-
case 4: return listeners.fn.call(listeners.context, a1, a2, a3), true;
|
|
3068
|
-
case 5: return listeners.fn.call(listeners.context, a1, a2, a3, a4), true;
|
|
3069
|
-
case 6: return listeners.fn.call(listeners.context, a1, a2, a3, a4, a5), true;
|
|
3070
|
-
}
|
|
3071
|
-
|
|
3072
|
-
for (i = 1, args = new Array(len -1); i < len; i++) {
|
|
3073
|
-
args[i - 1] = arguments[i];
|
|
3074
|
-
}
|
|
3075
|
-
|
|
3076
|
-
listeners.fn.apply(listeners.context, args);
|
|
3077
|
-
} else {
|
|
3078
|
-
var length = listeners.length
|
|
3079
|
-
, j;
|
|
3080
|
-
|
|
3081
|
-
for (i = 0; i < length; i++) {
|
|
3082
|
-
if (listeners[i].once) this.removeListener(event, listeners[i].fn, undefined, true);
|
|
3083
|
-
|
|
3084
|
-
switch (len) {
|
|
3085
|
-
case 1: listeners[i].fn.call(listeners[i].context); break;
|
|
3086
|
-
case 2: listeners[i].fn.call(listeners[i].context, a1); break;
|
|
3087
|
-
case 3: listeners[i].fn.call(listeners[i].context, a1, a2); break;
|
|
3088
|
-
case 4: listeners[i].fn.call(listeners[i].context, a1, a2, a3); break;
|
|
3089
|
-
default:
|
|
3090
|
-
if (!args) for (j = 1, args = new Array(len -1); j < len; j++) {
|
|
3091
|
-
args[j - 1] = arguments[j];
|
|
3092
|
-
}
|
|
3093
|
-
|
|
3094
|
-
listeners[i].fn.apply(listeners[i].context, args);
|
|
3095
|
-
}
|
|
3096
|
-
}
|
|
3097
|
-
}
|
|
3098
|
-
|
|
3099
|
-
return true;
|
|
3100
|
-
};
|
|
3101
|
-
|
|
3102
|
-
/**
|
|
3103
|
-
* Add a listener for a given event.
|
|
3104
|
-
*
|
|
3105
|
-
* @param {(String|Symbol)} event The event name.
|
|
3106
|
-
* @param {Function} fn The listener function.
|
|
3107
|
-
* @param {*} [context=this] The context to invoke the listener with.
|
|
3108
|
-
* @returns {EventEmitter} `this`.
|
|
3109
|
-
* @public
|
|
3110
|
-
*/
|
|
3111
|
-
EventEmitter.prototype.on = function on(event, fn, context) {
|
|
3112
|
-
return addListener(this, event, fn, context, false);
|
|
3113
|
-
};
|
|
3114
|
-
|
|
3115
|
-
/**
|
|
3116
|
-
* Add a one-time listener for a given event.
|
|
3117
|
-
*
|
|
3118
|
-
* @param {(String|Symbol)} event The event name.
|
|
3119
|
-
* @param {Function} fn The listener function.
|
|
3120
|
-
* @param {*} [context=this] The context to invoke the listener with.
|
|
3121
|
-
* @returns {EventEmitter} `this`.
|
|
3122
|
-
* @public
|
|
3123
|
-
*/
|
|
3124
|
-
EventEmitter.prototype.once = function once(event, fn, context) {
|
|
3125
|
-
return addListener(this, event, fn, context, true);
|
|
3126
|
-
};
|
|
3127
|
-
|
|
3128
|
-
/**
|
|
3129
|
-
* Remove the listeners of a given event.
|
|
3130
|
-
*
|
|
3131
|
-
* @param {(String|Symbol)} event The event name.
|
|
3132
|
-
* @param {Function} fn Only remove the listeners that match this function.
|
|
3133
|
-
* @param {*} context Only remove the listeners that have this context.
|
|
3134
|
-
* @param {Boolean} once Only remove one-time listeners.
|
|
3135
|
-
* @returns {EventEmitter} `this`.
|
|
3136
|
-
* @public
|
|
3137
|
-
*/
|
|
3138
|
-
EventEmitter.prototype.removeListener = function removeListener(event, fn, context, once) {
|
|
3139
|
-
var evt = prefix ? prefix + event : event;
|
|
3140
|
-
|
|
3141
|
-
if (!this._events[evt]) return this;
|
|
3142
|
-
if (!fn) {
|
|
3143
|
-
clearEvent(this, evt);
|
|
3144
|
-
return this;
|
|
3145
|
-
}
|
|
3146
|
-
|
|
3147
|
-
var listeners = this._events[evt];
|
|
3148
|
-
|
|
3149
|
-
if (listeners.fn) {
|
|
3150
|
-
if (
|
|
3151
|
-
listeners.fn === fn &&
|
|
3152
|
-
(!once || listeners.once) &&
|
|
3153
|
-
(!context || listeners.context === context)
|
|
3154
|
-
) {
|
|
3155
|
-
clearEvent(this, evt);
|
|
3156
|
-
}
|
|
3157
|
-
} else {
|
|
3158
|
-
for (var i = 0, events = [], length = listeners.length; i < length; i++) {
|
|
3159
|
-
if (
|
|
3160
|
-
listeners[i].fn !== fn ||
|
|
3161
|
-
(once && !listeners[i].once) ||
|
|
3162
|
-
(context && listeners[i].context !== context)
|
|
3163
|
-
) {
|
|
3164
|
-
events.push(listeners[i]);
|
|
3165
|
-
}
|
|
3166
|
-
}
|
|
3167
|
-
|
|
3168
|
-
//
|
|
3169
|
-
// Reset the array, or remove it completely if we have no more listeners.
|
|
3170
|
-
//
|
|
3171
|
-
if (events.length) this._events[evt] = events.length === 1 ? events[0] : events;
|
|
3172
|
-
else clearEvent(this, evt);
|
|
3173
|
-
}
|
|
3174
|
-
|
|
3175
|
-
return this;
|
|
3176
|
-
};
|
|
3177
|
-
|
|
3178
|
-
/**
|
|
3179
|
-
* Remove all listeners, or those of the specified event.
|
|
3180
|
-
*
|
|
3181
|
-
* @param {(String|Symbol)} [event] The event name.
|
|
3182
|
-
* @returns {EventEmitter} `this`.
|
|
3183
|
-
* @public
|
|
3184
|
-
*/
|
|
3185
|
-
EventEmitter.prototype.removeAllListeners = function removeAllListeners(event) {
|
|
3186
|
-
var evt;
|
|
3187
|
-
|
|
3188
|
-
if (event) {
|
|
3189
|
-
evt = prefix ? prefix + event : event;
|
|
3190
|
-
if (this._events[evt]) clearEvent(this, evt);
|
|
3191
|
-
} else {
|
|
3192
|
-
this._events = new Events();
|
|
3193
|
-
this._eventsCount = 0;
|
|
3194
|
-
}
|
|
3195
|
-
|
|
3196
|
-
return this;
|
|
3197
|
-
};
|
|
3198
|
-
|
|
3199
|
-
//
|
|
3200
|
-
// Alias methods names because people roll like that.
|
|
3201
|
-
//
|
|
3202
|
-
EventEmitter.prototype.off = EventEmitter.prototype.removeListener;
|
|
3203
|
-
EventEmitter.prototype.addListener = EventEmitter.prototype.on;
|
|
3204
|
-
|
|
3205
|
-
//
|
|
3206
|
-
// Expose the prefix.
|
|
3207
|
-
//
|
|
3208
|
-
EventEmitter.prefixed = prefix;
|
|
3209
|
-
|
|
3210
|
-
//
|
|
3211
|
-
// Allow `EventEmitter` to be imported as module namespace.
|
|
3212
|
-
//
|
|
3213
|
-
EventEmitter.EventEmitter = EventEmitter;
|
|
3214
|
-
|
|
3215
|
-
//
|
|
3216
|
-
// Expose the module.
|
|
3217
|
-
//
|
|
3218
|
-
{
|
|
3219
|
-
module.exports = EventEmitter;
|
|
3220
|
-
}
|
|
3221
|
-
} (eventemitter3$1));
|
|
3222
|
-
return eventemitter3$1.exports;
|
|
3223
|
-
}
|
|
3224
|
-
|
|
3225
|
-
var eventemitter3Exports$1 = requireEventemitter3$1();
|
|
3226
|
-
var EventEmitter4 = /*@__PURE__*/index.getDefaultExportFromCjs(eventemitter3Exports$1);
|
|
3227
|
-
|
|
3228
5282
|
// src/index.ts
|
|
3229
5283
|
var isBrowser = typeof window !== "undefined" && typeof window.btoa !== "undefined";
|
|
3230
5284
|
function base64urlEncode(data) {
|
|
@@ -8388,133 +10442,6 @@ class Transaction {
|
|
|
8388
10442
|
}
|
|
8389
10443
|
}
|
|
8390
10444
|
|
|
8391
|
-
// base-x encoding / decoding
|
|
8392
|
-
// Copyright (c) 2018 base-x contributors
|
|
8393
|
-
// Copyright (c) 2014-2018 The Bitcoin Core developers (base58.cpp)
|
|
8394
|
-
// Distributed under the MIT software license, see the accompanying
|
|
8395
|
-
// file LICENSE or http://www.opensource.org/licenses/mit-license.php.
|
|
8396
|
-
function base$3 (ALPHABET) {
|
|
8397
|
-
if (ALPHABET.length >= 255) { throw new TypeError('Alphabet too long') }
|
|
8398
|
-
const BASE_MAP = new Uint8Array(256);
|
|
8399
|
-
for (let j = 0; j < BASE_MAP.length; j++) {
|
|
8400
|
-
BASE_MAP[j] = 255;
|
|
8401
|
-
}
|
|
8402
|
-
for (let i = 0; i < ALPHABET.length; i++) {
|
|
8403
|
-
const x = ALPHABET.charAt(i);
|
|
8404
|
-
const xc = x.charCodeAt(0);
|
|
8405
|
-
if (BASE_MAP[xc] !== 255) { throw new TypeError(x + ' is ambiguous') }
|
|
8406
|
-
BASE_MAP[xc] = i;
|
|
8407
|
-
}
|
|
8408
|
-
const BASE = ALPHABET.length;
|
|
8409
|
-
const LEADER = ALPHABET.charAt(0);
|
|
8410
|
-
const FACTOR = Math.log(BASE) / Math.log(256); // log(BASE) / log(256), rounded up
|
|
8411
|
-
const iFACTOR = Math.log(256) / Math.log(BASE); // log(256) / log(BASE), rounded up
|
|
8412
|
-
function encode (source) {
|
|
8413
|
-
// eslint-disable-next-line no-empty
|
|
8414
|
-
if (source instanceof Uint8Array) ; else if (ArrayBuffer.isView(source)) {
|
|
8415
|
-
source = new Uint8Array(source.buffer, source.byteOffset, source.byteLength);
|
|
8416
|
-
} else if (Array.isArray(source)) {
|
|
8417
|
-
source = Uint8Array.from(source);
|
|
8418
|
-
}
|
|
8419
|
-
if (!(source instanceof Uint8Array)) { throw new TypeError('Expected Uint8Array') }
|
|
8420
|
-
if (source.length === 0) { return '' }
|
|
8421
|
-
// Skip & count leading zeroes.
|
|
8422
|
-
let zeroes = 0;
|
|
8423
|
-
let length = 0;
|
|
8424
|
-
let pbegin = 0;
|
|
8425
|
-
const pend = source.length;
|
|
8426
|
-
while (pbegin !== pend && source[pbegin] === 0) {
|
|
8427
|
-
pbegin++;
|
|
8428
|
-
zeroes++;
|
|
8429
|
-
}
|
|
8430
|
-
// Allocate enough space in big-endian base58 representation.
|
|
8431
|
-
const size = ((pend - pbegin) * iFACTOR + 1) >>> 0;
|
|
8432
|
-
const b58 = new Uint8Array(size);
|
|
8433
|
-
// Process the bytes.
|
|
8434
|
-
while (pbegin !== pend) {
|
|
8435
|
-
let carry = source[pbegin];
|
|
8436
|
-
// Apply "b58 = b58 * 256 + ch".
|
|
8437
|
-
let i = 0;
|
|
8438
|
-
for (let it1 = size - 1; (carry !== 0 || i < length) && (it1 !== -1); it1--, i++) {
|
|
8439
|
-
carry += (256 * b58[it1]) >>> 0;
|
|
8440
|
-
b58[it1] = (carry % BASE) >>> 0;
|
|
8441
|
-
carry = (carry / BASE) >>> 0;
|
|
8442
|
-
}
|
|
8443
|
-
if (carry !== 0) { throw new Error('Non-zero carry') }
|
|
8444
|
-
length = i;
|
|
8445
|
-
pbegin++;
|
|
8446
|
-
}
|
|
8447
|
-
// Skip leading zeroes in base58 result.
|
|
8448
|
-
let it2 = size - length;
|
|
8449
|
-
while (it2 !== size && b58[it2] === 0) {
|
|
8450
|
-
it2++;
|
|
8451
|
-
}
|
|
8452
|
-
// Translate the result into a string.
|
|
8453
|
-
let str = LEADER.repeat(zeroes);
|
|
8454
|
-
for (; it2 < size; ++it2) { str += ALPHABET.charAt(b58[it2]); }
|
|
8455
|
-
return str
|
|
8456
|
-
}
|
|
8457
|
-
function decodeUnsafe (source) {
|
|
8458
|
-
if (typeof source !== 'string') { throw new TypeError('Expected String') }
|
|
8459
|
-
if (source.length === 0) { return new Uint8Array() }
|
|
8460
|
-
let psz = 0;
|
|
8461
|
-
// Skip and count leading '1's.
|
|
8462
|
-
let zeroes = 0;
|
|
8463
|
-
let length = 0;
|
|
8464
|
-
while (source[psz] === LEADER) {
|
|
8465
|
-
zeroes++;
|
|
8466
|
-
psz++;
|
|
8467
|
-
}
|
|
8468
|
-
// Allocate enough space in big-endian base256 representation.
|
|
8469
|
-
const size = (((source.length - psz) * FACTOR) + 1) >>> 0; // log(58) / log(256), rounded up.
|
|
8470
|
-
const b256 = new Uint8Array(size);
|
|
8471
|
-
// Process the characters.
|
|
8472
|
-
while (psz < source.length) {
|
|
8473
|
-
// Find code of next character
|
|
8474
|
-
const charCode = source.charCodeAt(psz);
|
|
8475
|
-
// Base map can not be indexed using char code
|
|
8476
|
-
if (charCode > 255) { return }
|
|
8477
|
-
// Decode character
|
|
8478
|
-
let carry = BASE_MAP[charCode];
|
|
8479
|
-
// Invalid character
|
|
8480
|
-
if (carry === 255) { return }
|
|
8481
|
-
let i = 0;
|
|
8482
|
-
for (let it3 = size - 1; (carry !== 0 || i < length) && (it3 !== -1); it3--, i++) {
|
|
8483
|
-
carry += (BASE * b256[it3]) >>> 0;
|
|
8484
|
-
b256[it3] = (carry % 256) >>> 0;
|
|
8485
|
-
carry = (carry / 256) >>> 0;
|
|
8486
|
-
}
|
|
8487
|
-
if (carry !== 0) { throw new Error('Non-zero carry') }
|
|
8488
|
-
length = i;
|
|
8489
|
-
psz++;
|
|
8490
|
-
}
|
|
8491
|
-
// Skip leading zeroes in b256.
|
|
8492
|
-
let it4 = size - length;
|
|
8493
|
-
while (it4 !== size && b256[it4] === 0) {
|
|
8494
|
-
it4++;
|
|
8495
|
-
}
|
|
8496
|
-
const vch = new Uint8Array(zeroes + (size - it4));
|
|
8497
|
-
let j = zeroes;
|
|
8498
|
-
while (it4 !== size) {
|
|
8499
|
-
vch[j++] = b256[it4++];
|
|
8500
|
-
}
|
|
8501
|
-
return vch
|
|
8502
|
-
}
|
|
8503
|
-
function decode (string) {
|
|
8504
|
-
const buffer = decodeUnsafe(string);
|
|
8505
|
-
if (buffer) { return buffer }
|
|
8506
|
-
throw new Error('Non-base' + BASE + ' character')
|
|
8507
|
-
}
|
|
8508
|
-
return {
|
|
8509
|
-
encode,
|
|
8510
|
-
decodeUnsafe,
|
|
8511
|
-
decode
|
|
8512
|
-
}
|
|
8513
|
-
}
|
|
8514
|
-
|
|
8515
|
-
var ALPHABET$3 = '123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz';
|
|
8516
|
-
var bs58$2 = base$3(ALPHABET$3);
|
|
8517
|
-
|
|
8518
10445
|
// src/index.ts
|
|
8519
10446
|
function parseSignMessageResponse(base64Response, networkId) {
|
|
8520
10447
|
const networkPrefix = networkId.split(":")[0].toLowerCase();
|
|
@@ -8561,7 +10488,7 @@ function parseTransactionResponse(base64RawTransaction, networkId, hash) {
|
|
|
8561
10488
|
function parseSolanaSignatureResponse(base64Response) {
|
|
8562
10489
|
try {
|
|
8563
10490
|
const signatureBytes = base64urlDecode(base64Response);
|
|
8564
|
-
const signature = bs58
|
|
10491
|
+
const signature = index.bs58.encode(signatureBytes);
|
|
8565
10492
|
return {
|
|
8566
10493
|
signature,
|
|
8567
10494
|
rawSignature: base64Response
|
|
@@ -8801,610 +10728,6 @@ function parseBitcoinTransactionToBase64Url(transaction) {
|
|
|
8801
10728
|
throw new Error("Unsupported Bitcoin transaction format");
|
|
8802
10729
|
}
|
|
8803
10730
|
|
|
8804
|
-
// base-x encoding / decoding
|
|
8805
|
-
// Copyright (c) 2018 base-x contributors
|
|
8806
|
-
// Copyright (c) 2014-2018 The Bitcoin Core developers (base58.cpp)
|
|
8807
|
-
// Distributed under the MIT software license, see the accompanying
|
|
8808
|
-
// file LICENSE or http://www.opensource.org/licenses/mit-license.php.
|
|
8809
|
-
function base$2 (ALPHABET) {
|
|
8810
|
-
if (ALPHABET.length >= 255) { throw new TypeError('Alphabet too long') }
|
|
8811
|
-
const BASE_MAP = new Uint8Array(256);
|
|
8812
|
-
for (let j = 0; j < BASE_MAP.length; j++) {
|
|
8813
|
-
BASE_MAP[j] = 255;
|
|
8814
|
-
}
|
|
8815
|
-
for (let i = 0; i < ALPHABET.length; i++) {
|
|
8816
|
-
const x = ALPHABET.charAt(i);
|
|
8817
|
-
const xc = x.charCodeAt(0);
|
|
8818
|
-
if (BASE_MAP[xc] !== 255) { throw new TypeError(x + ' is ambiguous') }
|
|
8819
|
-
BASE_MAP[xc] = i;
|
|
8820
|
-
}
|
|
8821
|
-
const BASE = ALPHABET.length;
|
|
8822
|
-
const LEADER = ALPHABET.charAt(0);
|
|
8823
|
-
const FACTOR = Math.log(BASE) / Math.log(256); // log(BASE) / log(256), rounded up
|
|
8824
|
-
const iFACTOR = Math.log(256) / Math.log(BASE); // log(256) / log(BASE), rounded up
|
|
8825
|
-
function encode (source) {
|
|
8826
|
-
// eslint-disable-next-line no-empty
|
|
8827
|
-
if (source instanceof Uint8Array) ; else if (ArrayBuffer.isView(source)) {
|
|
8828
|
-
source = new Uint8Array(source.buffer, source.byteOffset, source.byteLength);
|
|
8829
|
-
} else if (Array.isArray(source)) {
|
|
8830
|
-
source = Uint8Array.from(source);
|
|
8831
|
-
}
|
|
8832
|
-
if (!(source instanceof Uint8Array)) { throw new TypeError('Expected Uint8Array') }
|
|
8833
|
-
if (source.length === 0) { return '' }
|
|
8834
|
-
// Skip & count leading zeroes.
|
|
8835
|
-
let zeroes = 0;
|
|
8836
|
-
let length = 0;
|
|
8837
|
-
let pbegin = 0;
|
|
8838
|
-
const pend = source.length;
|
|
8839
|
-
while (pbegin !== pend && source[pbegin] === 0) {
|
|
8840
|
-
pbegin++;
|
|
8841
|
-
zeroes++;
|
|
8842
|
-
}
|
|
8843
|
-
// Allocate enough space in big-endian base58 representation.
|
|
8844
|
-
const size = ((pend - pbegin) * iFACTOR + 1) >>> 0;
|
|
8845
|
-
const b58 = new Uint8Array(size);
|
|
8846
|
-
// Process the bytes.
|
|
8847
|
-
while (pbegin !== pend) {
|
|
8848
|
-
let carry = source[pbegin];
|
|
8849
|
-
// Apply "b58 = b58 * 256 + ch".
|
|
8850
|
-
let i = 0;
|
|
8851
|
-
for (let it1 = size - 1; (carry !== 0 || i < length) && (it1 !== -1); it1--, i++) {
|
|
8852
|
-
carry += (256 * b58[it1]) >>> 0;
|
|
8853
|
-
b58[it1] = (carry % BASE) >>> 0;
|
|
8854
|
-
carry = (carry / BASE) >>> 0;
|
|
8855
|
-
}
|
|
8856
|
-
if (carry !== 0) { throw new Error('Non-zero carry') }
|
|
8857
|
-
length = i;
|
|
8858
|
-
pbegin++;
|
|
8859
|
-
}
|
|
8860
|
-
// Skip leading zeroes in base58 result.
|
|
8861
|
-
let it2 = size - length;
|
|
8862
|
-
while (it2 !== size && b58[it2] === 0) {
|
|
8863
|
-
it2++;
|
|
8864
|
-
}
|
|
8865
|
-
// Translate the result into a string.
|
|
8866
|
-
let str = LEADER.repeat(zeroes);
|
|
8867
|
-
for (; it2 < size; ++it2) { str += ALPHABET.charAt(b58[it2]); }
|
|
8868
|
-
return str
|
|
8869
|
-
}
|
|
8870
|
-
function decodeUnsafe (source) {
|
|
8871
|
-
if (typeof source !== 'string') { throw new TypeError('Expected String') }
|
|
8872
|
-
if (source.length === 0) { return new Uint8Array() }
|
|
8873
|
-
let psz = 0;
|
|
8874
|
-
// Skip and count leading '1's.
|
|
8875
|
-
let zeroes = 0;
|
|
8876
|
-
let length = 0;
|
|
8877
|
-
while (source[psz] === LEADER) {
|
|
8878
|
-
zeroes++;
|
|
8879
|
-
psz++;
|
|
8880
|
-
}
|
|
8881
|
-
// Allocate enough space in big-endian base256 representation.
|
|
8882
|
-
const size = (((source.length - psz) * FACTOR) + 1) >>> 0; // log(58) / log(256), rounded up.
|
|
8883
|
-
const b256 = new Uint8Array(size);
|
|
8884
|
-
// Process the characters.
|
|
8885
|
-
while (psz < source.length) {
|
|
8886
|
-
// Find code of next character
|
|
8887
|
-
const charCode = source.charCodeAt(psz);
|
|
8888
|
-
// Base map can not be indexed using char code
|
|
8889
|
-
if (charCode > 255) { return }
|
|
8890
|
-
// Decode character
|
|
8891
|
-
let carry = BASE_MAP[charCode];
|
|
8892
|
-
// Invalid character
|
|
8893
|
-
if (carry === 255) { return }
|
|
8894
|
-
let i = 0;
|
|
8895
|
-
for (let it3 = size - 1; (carry !== 0 || i < length) && (it3 !== -1); it3--, i++) {
|
|
8896
|
-
carry += (BASE * b256[it3]) >>> 0;
|
|
8897
|
-
b256[it3] = (carry % 256) >>> 0;
|
|
8898
|
-
carry = (carry / 256) >>> 0;
|
|
8899
|
-
}
|
|
8900
|
-
if (carry !== 0) { throw new Error('Non-zero carry') }
|
|
8901
|
-
length = i;
|
|
8902
|
-
psz++;
|
|
8903
|
-
}
|
|
8904
|
-
// Skip leading zeroes in b256.
|
|
8905
|
-
let it4 = size - length;
|
|
8906
|
-
while (it4 !== size && b256[it4] === 0) {
|
|
8907
|
-
it4++;
|
|
8908
|
-
}
|
|
8909
|
-
const vch = new Uint8Array(zeroes + (size - it4));
|
|
8910
|
-
let j = zeroes;
|
|
8911
|
-
while (it4 !== size) {
|
|
8912
|
-
vch[j++] = b256[it4++];
|
|
8913
|
-
}
|
|
8914
|
-
return vch
|
|
8915
|
-
}
|
|
8916
|
-
function decode (string) {
|
|
8917
|
-
const buffer = decodeUnsafe(string);
|
|
8918
|
-
if (buffer) { return buffer }
|
|
8919
|
-
throw new Error('Non-base' + BASE + ' character')
|
|
8920
|
-
}
|
|
8921
|
-
return {
|
|
8922
|
-
encode,
|
|
8923
|
-
decodeUnsafe,
|
|
8924
|
-
decode
|
|
8925
|
-
}
|
|
8926
|
-
}
|
|
8927
|
-
|
|
8928
|
-
var ALPHABET$2 = '123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz';
|
|
8929
|
-
var bs58$1 = base$2(ALPHABET$2);
|
|
8930
|
-
|
|
8931
|
-
// base-x encoding / decoding
|
|
8932
|
-
// Copyright (c) 2018 base-x contributors
|
|
8933
|
-
// Copyright (c) 2014-2018 The Bitcoin Core developers (base58.cpp)
|
|
8934
|
-
// Distributed under the MIT software license, see the accompanying
|
|
8935
|
-
// file LICENSE or http://www.opensource.org/licenses/mit-license.php.
|
|
8936
|
-
function base$1 (ALPHABET) {
|
|
8937
|
-
if (ALPHABET.length >= 255) { throw new TypeError('Alphabet too long') }
|
|
8938
|
-
const BASE_MAP = new Uint8Array(256);
|
|
8939
|
-
for (let j = 0; j < BASE_MAP.length; j++) {
|
|
8940
|
-
BASE_MAP[j] = 255;
|
|
8941
|
-
}
|
|
8942
|
-
for (let i = 0; i < ALPHABET.length; i++) {
|
|
8943
|
-
const x = ALPHABET.charAt(i);
|
|
8944
|
-
const xc = x.charCodeAt(0);
|
|
8945
|
-
if (BASE_MAP[xc] !== 255) { throw new TypeError(x + ' is ambiguous') }
|
|
8946
|
-
BASE_MAP[xc] = i;
|
|
8947
|
-
}
|
|
8948
|
-
const BASE = ALPHABET.length;
|
|
8949
|
-
const LEADER = ALPHABET.charAt(0);
|
|
8950
|
-
const FACTOR = Math.log(BASE) / Math.log(256); // log(BASE) / log(256), rounded up
|
|
8951
|
-
const iFACTOR = Math.log(256) / Math.log(BASE); // log(256) / log(BASE), rounded up
|
|
8952
|
-
function encode (source) {
|
|
8953
|
-
// eslint-disable-next-line no-empty
|
|
8954
|
-
if (source instanceof Uint8Array) ; else if (ArrayBuffer.isView(source)) {
|
|
8955
|
-
source = new Uint8Array(source.buffer, source.byteOffset, source.byteLength);
|
|
8956
|
-
} else if (Array.isArray(source)) {
|
|
8957
|
-
source = Uint8Array.from(source);
|
|
8958
|
-
}
|
|
8959
|
-
if (!(source instanceof Uint8Array)) { throw new TypeError('Expected Uint8Array') }
|
|
8960
|
-
if (source.length === 0) { return '' }
|
|
8961
|
-
// Skip & count leading zeroes.
|
|
8962
|
-
let zeroes = 0;
|
|
8963
|
-
let length = 0;
|
|
8964
|
-
let pbegin = 0;
|
|
8965
|
-
const pend = source.length;
|
|
8966
|
-
while (pbegin !== pend && source[pbegin] === 0) {
|
|
8967
|
-
pbegin++;
|
|
8968
|
-
zeroes++;
|
|
8969
|
-
}
|
|
8970
|
-
// Allocate enough space in big-endian base58 representation.
|
|
8971
|
-
const size = ((pend - pbegin) * iFACTOR + 1) >>> 0;
|
|
8972
|
-
const b58 = new Uint8Array(size);
|
|
8973
|
-
// Process the bytes.
|
|
8974
|
-
while (pbegin !== pend) {
|
|
8975
|
-
let carry = source[pbegin];
|
|
8976
|
-
// Apply "b58 = b58 * 256 + ch".
|
|
8977
|
-
let i = 0;
|
|
8978
|
-
for (let it1 = size - 1; (carry !== 0 || i < length) && (it1 !== -1); it1--, i++) {
|
|
8979
|
-
carry += (256 * b58[it1]) >>> 0;
|
|
8980
|
-
b58[it1] = (carry % BASE) >>> 0;
|
|
8981
|
-
carry = (carry / BASE) >>> 0;
|
|
8982
|
-
}
|
|
8983
|
-
if (carry !== 0) { throw new Error('Non-zero carry') }
|
|
8984
|
-
length = i;
|
|
8985
|
-
pbegin++;
|
|
8986
|
-
}
|
|
8987
|
-
// Skip leading zeroes in base58 result.
|
|
8988
|
-
let it2 = size - length;
|
|
8989
|
-
while (it2 !== size && b58[it2] === 0) {
|
|
8990
|
-
it2++;
|
|
8991
|
-
}
|
|
8992
|
-
// Translate the result into a string.
|
|
8993
|
-
let str = LEADER.repeat(zeroes);
|
|
8994
|
-
for (; it2 < size; ++it2) { str += ALPHABET.charAt(b58[it2]); }
|
|
8995
|
-
return str
|
|
8996
|
-
}
|
|
8997
|
-
function decodeUnsafe (source) {
|
|
8998
|
-
if (typeof source !== 'string') { throw new TypeError('Expected String') }
|
|
8999
|
-
if (source.length === 0) { return new Uint8Array() }
|
|
9000
|
-
let psz = 0;
|
|
9001
|
-
// Skip and count leading '1's.
|
|
9002
|
-
let zeroes = 0;
|
|
9003
|
-
let length = 0;
|
|
9004
|
-
while (source[psz] === LEADER) {
|
|
9005
|
-
zeroes++;
|
|
9006
|
-
psz++;
|
|
9007
|
-
}
|
|
9008
|
-
// Allocate enough space in big-endian base256 representation.
|
|
9009
|
-
const size = (((source.length - psz) * FACTOR) + 1) >>> 0; // log(58) / log(256), rounded up.
|
|
9010
|
-
const b256 = new Uint8Array(size);
|
|
9011
|
-
// Process the characters.
|
|
9012
|
-
while (psz < source.length) {
|
|
9013
|
-
// Find code of next character
|
|
9014
|
-
const charCode = source.charCodeAt(psz);
|
|
9015
|
-
// Base map can not be indexed using char code
|
|
9016
|
-
if (charCode > 255) { return }
|
|
9017
|
-
// Decode character
|
|
9018
|
-
let carry = BASE_MAP[charCode];
|
|
9019
|
-
// Invalid character
|
|
9020
|
-
if (carry === 255) { return }
|
|
9021
|
-
let i = 0;
|
|
9022
|
-
for (let it3 = size - 1; (carry !== 0 || i < length) && (it3 !== -1); it3--, i++) {
|
|
9023
|
-
carry += (BASE * b256[it3]) >>> 0;
|
|
9024
|
-
b256[it3] = (carry % 256) >>> 0;
|
|
9025
|
-
carry = (carry / 256) >>> 0;
|
|
9026
|
-
}
|
|
9027
|
-
if (carry !== 0) { throw new Error('Non-zero carry') }
|
|
9028
|
-
length = i;
|
|
9029
|
-
psz++;
|
|
9030
|
-
}
|
|
9031
|
-
// Skip leading zeroes in b256.
|
|
9032
|
-
let it4 = size - length;
|
|
9033
|
-
while (it4 !== size && b256[it4] === 0) {
|
|
9034
|
-
it4++;
|
|
9035
|
-
}
|
|
9036
|
-
const vch = new Uint8Array(zeroes + (size - it4));
|
|
9037
|
-
let j = zeroes;
|
|
9038
|
-
while (it4 !== size) {
|
|
9039
|
-
vch[j++] = b256[it4++];
|
|
9040
|
-
}
|
|
9041
|
-
return vch
|
|
9042
|
-
}
|
|
9043
|
-
function decode (string) {
|
|
9044
|
-
const buffer = decodeUnsafe(string);
|
|
9045
|
-
if (buffer) { return buffer }
|
|
9046
|
-
throw new Error('Non-base' + BASE + ' character')
|
|
9047
|
-
}
|
|
9048
|
-
return {
|
|
9049
|
-
encode,
|
|
9050
|
-
decodeUnsafe,
|
|
9051
|
-
decode
|
|
9052
|
-
}
|
|
9053
|
-
}
|
|
9054
|
-
|
|
9055
|
-
var ALPHABET$1 = '123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz';
|
|
9056
|
-
var bs582 = base$1(ALPHABET$1);
|
|
9057
|
-
|
|
9058
|
-
var eventemitter3 = {exports: {}};
|
|
9059
|
-
|
|
9060
|
-
var hasRequiredEventemitter3;
|
|
9061
|
-
|
|
9062
|
-
function requireEventemitter3 () {
|
|
9063
|
-
if (hasRequiredEventemitter3) return eventemitter3.exports;
|
|
9064
|
-
hasRequiredEventemitter3 = 1;
|
|
9065
|
-
(function (module) {
|
|
9066
|
-
|
|
9067
|
-
var has = Object.prototype.hasOwnProperty
|
|
9068
|
-
, prefix = '~';
|
|
9069
|
-
|
|
9070
|
-
/**
|
|
9071
|
-
* Constructor to create a storage for our `EE` objects.
|
|
9072
|
-
* An `Events` instance is a plain object whose properties are event names.
|
|
9073
|
-
*
|
|
9074
|
-
* @constructor
|
|
9075
|
-
* @private
|
|
9076
|
-
*/
|
|
9077
|
-
function Events() {}
|
|
9078
|
-
|
|
9079
|
-
//
|
|
9080
|
-
// We try to not inherit from `Object.prototype`. In some engines creating an
|
|
9081
|
-
// instance in this way is faster than calling `Object.create(null)` directly.
|
|
9082
|
-
// If `Object.create(null)` is not supported we prefix the event names with a
|
|
9083
|
-
// character to make sure that the built-in object properties are not
|
|
9084
|
-
// overridden or used as an attack vector.
|
|
9085
|
-
//
|
|
9086
|
-
if (Object.create) {
|
|
9087
|
-
Events.prototype = Object.create(null);
|
|
9088
|
-
|
|
9089
|
-
//
|
|
9090
|
-
// This hack is needed because the `__proto__` property is still inherited in
|
|
9091
|
-
// some old browsers like Android 4, iPhone 5.1, Opera 11 and Safari 5.
|
|
9092
|
-
//
|
|
9093
|
-
if (!new Events().__proto__) prefix = false;
|
|
9094
|
-
}
|
|
9095
|
-
|
|
9096
|
-
/**
|
|
9097
|
-
* Representation of a single event listener.
|
|
9098
|
-
*
|
|
9099
|
-
* @param {Function} fn The listener function.
|
|
9100
|
-
* @param {*} context The context to invoke the listener with.
|
|
9101
|
-
* @param {Boolean} [once=false] Specify if the listener is a one-time listener.
|
|
9102
|
-
* @constructor
|
|
9103
|
-
* @private
|
|
9104
|
-
*/
|
|
9105
|
-
function EE(fn, context, once) {
|
|
9106
|
-
this.fn = fn;
|
|
9107
|
-
this.context = context;
|
|
9108
|
-
this.once = once || false;
|
|
9109
|
-
}
|
|
9110
|
-
|
|
9111
|
-
/**
|
|
9112
|
-
* Add a listener for a given event.
|
|
9113
|
-
*
|
|
9114
|
-
* @param {EventEmitter} emitter Reference to the `EventEmitter` instance.
|
|
9115
|
-
* @param {(String|Symbol)} event The event name.
|
|
9116
|
-
* @param {Function} fn The listener function.
|
|
9117
|
-
* @param {*} context The context to invoke the listener with.
|
|
9118
|
-
* @param {Boolean} once Specify if the listener is a one-time listener.
|
|
9119
|
-
* @returns {EventEmitter}
|
|
9120
|
-
* @private
|
|
9121
|
-
*/
|
|
9122
|
-
function addListener(emitter, event, fn, context, once) {
|
|
9123
|
-
if (typeof fn !== 'function') {
|
|
9124
|
-
throw new TypeError('The listener must be a function');
|
|
9125
|
-
}
|
|
9126
|
-
|
|
9127
|
-
var listener = new EE(fn, context || emitter, once)
|
|
9128
|
-
, evt = prefix ? prefix + event : event;
|
|
9129
|
-
|
|
9130
|
-
if (!emitter._events[evt]) emitter._events[evt] = listener, emitter._eventsCount++;
|
|
9131
|
-
else if (!emitter._events[evt].fn) emitter._events[evt].push(listener);
|
|
9132
|
-
else emitter._events[evt] = [emitter._events[evt], listener];
|
|
9133
|
-
|
|
9134
|
-
return emitter;
|
|
9135
|
-
}
|
|
9136
|
-
|
|
9137
|
-
/**
|
|
9138
|
-
* Clear event by name.
|
|
9139
|
-
*
|
|
9140
|
-
* @param {EventEmitter} emitter Reference to the `EventEmitter` instance.
|
|
9141
|
-
* @param {(String|Symbol)} evt The Event name.
|
|
9142
|
-
* @private
|
|
9143
|
-
*/
|
|
9144
|
-
function clearEvent(emitter, evt) {
|
|
9145
|
-
if (--emitter._eventsCount === 0) emitter._events = new Events();
|
|
9146
|
-
else delete emitter._events[evt];
|
|
9147
|
-
}
|
|
9148
|
-
|
|
9149
|
-
/**
|
|
9150
|
-
* Minimal `EventEmitter` interface that is molded against the Node.js
|
|
9151
|
-
* `EventEmitter` interface.
|
|
9152
|
-
*
|
|
9153
|
-
* @constructor
|
|
9154
|
-
* @public
|
|
9155
|
-
*/
|
|
9156
|
-
function EventEmitter() {
|
|
9157
|
-
this._events = new Events();
|
|
9158
|
-
this._eventsCount = 0;
|
|
9159
|
-
}
|
|
9160
|
-
|
|
9161
|
-
/**
|
|
9162
|
-
* Return an array listing the events for which the emitter has registered
|
|
9163
|
-
* listeners.
|
|
9164
|
-
*
|
|
9165
|
-
* @returns {Array}
|
|
9166
|
-
* @public
|
|
9167
|
-
*/
|
|
9168
|
-
EventEmitter.prototype.eventNames = function eventNames() {
|
|
9169
|
-
var names = []
|
|
9170
|
-
, events
|
|
9171
|
-
, name;
|
|
9172
|
-
|
|
9173
|
-
if (this._eventsCount === 0) return names;
|
|
9174
|
-
|
|
9175
|
-
for (name in (events = this._events)) {
|
|
9176
|
-
if (has.call(events, name)) names.push(prefix ? name.slice(1) : name);
|
|
9177
|
-
}
|
|
9178
|
-
|
|
9179
|
-
if (Object.getOwnPropertySymbols) {
|
|
9180
|
-
return names.concat(Object.getOwnPropertySymbols(events));
|
|
9181
|
-
}
|
|
9182
|
-
|
|
9183
|
-
return names;
|
|
9184
|
-
};
|
|
9185
|
-
|
|
9186
|
-
/**
|
|
9187
|
-
* Return the listeners registered for a given event.
|
|
9188
|
-
*
|
|
9189
|
-
* @param {(String|Symbol)} event The event name.
|
|
9190
|
-
* @returns {Array} The registered listeners.
|
|
9191
|
-
* @public
|
|
9192
|
-
*/
|
|
9193
|
-
EventEmitter.prototype.listeners = function listeners(event) {
|
|
9194
|
-
var evt = prefix ? prefix + event : event
|
|
9195
|
-
, handlers = this._events[evt];
|
|
9196
|
-
|
|
9197
|
-
if (!handlers) return [];
|
|
9198
|
-
if (handlers.fn) return [handlers.fn];
|
|
9199
|
-
|
|
9200
|
-
for (var i = 0, l = handlers.length, ee = new Array(l); i < l; i++) {
|
|
9201
|
-
ee[i] = handlers[i].fn;
|
|
9202
|
-
}
|
|
9203
|
-
|
|
9204
|
-
return ee;
|
|
9205
|
-
};
|
|
9206
|
-
|
|
9207
|
-
/**
|
|
9208
|
-
* Return the number of listeners listening to a given event.
|
|
9209
|
-
*
|
|
9210
|
-
* @param {(String|Symbol)} event The event name.
|
|
9211
|
-
* @returns {Number} The number of listeners.
|
|
9212
|
-
* @public
|
|
9213
|
-
*/
|
|
9214
|
-
EventEmitter.prototype.listenerCount = function listenerCount(event) {
|
|
9215
|
-
var evt = prefix ? prefix + event : event
|
|
9216
|
-
, listeners = this._events[evt];
|
|
9217
|
-
|
|
9218
|
-
if (!listeners) return 0;
|
|
9219
|
-
if (listeners.fn) return 1;
|
|
9220
|
-
return listeners.length;
|
|
9221
|
-
};
|
|
9222
|
-
|
|
9223
|
-
/**
|
|
9224
|
-
* Calls each of the listeners registered for a given event.
|
|
9225
|
-
*
|
|
9226
|
-
* @param {(String|Symbol)} event The event name.
|
|
9227
|
-
* @returns {Boolean} `true` if the event had listeners, else `false`.
|
|
9228
|
-
* @public
|
|
9229
|
-
*/
|
|
9230
|
-
EventEmitter.prototype.emit = function emit(event, a1, a2, a3, a4, a5) {
|
|
9231
|
-
var evt = prefix ? prefix + event : event;
|
|
9232
|
-
|
|
9233
|
-
if (!this._events[evt]) return false;
|
|
9234
|
-
|
|
9235
|
-
var listeners = this._events[evt]
|
|
9236
|
-
, len = arguments.length
|
|
9237
|
-
, args
|
|
9238
|
-
, i;
|
|
9239
|
-
|
|
9240
|
-
if (listeners.fn) {
|
|
9241
|
-
if (listeners.once) this.removeListener(event, listeners.fn, undefined, true);
|
|
9242
|
-
|
|
9243
|
-
switch (len) {
|
|
9244
|
-
case 1: return listeners.fn.call(listeners.context), true;
|
|
9245
|
-
case 2: return listeners.fn.call(listeners.context, a1), true;
|
|
9246
|
-
case 3: return listeners.fn.call(listeners.context, a1, a2), true;
|
|
9247
|
-
case 4: return listeners.fn.call(listeners.context, a1, a2, a3), true;
|
|
9248
|
-
case 5: return listeners.fn.call(listeners.context, a1, a2, a3, a4), true;
|
|
9249
|
-
case 6: return listeners.fn.call(listeners.context, a1, a2, a3, a4, a5), true;
|
|
9250
|
-
}
|
|
9251
|
-
|
|
9252
|
-
for (i = 1, args = new Array(len -1); i < len; i++) {
|
|
9253
|
-
args[i - 1] = arguments[i];
|
|
9254
|
-
}
|
|
9255
|
-
|
|
9256
|
-
listeners.fn.apply(listeners.context, args);
|
|
9257
|
-
} else {
|
|
9258
|
-
var length = listeners.length
|
|
9259
|
-
, j;
|
|
9260
|
-
|
|
9261
|
-
for (i = 0; i < length; i++) {
|
|
9262
|
-
if (listeners[i].once) this.removeListener(event, listeners[i].fn, undefined, true);
|
|
9263
|
-
|
|
9264
|
-
switch (len) {
|
|
9265
|
-
case 1: listeners[i].fn.call(listeners[i].context); break;
|
|
9266
|
-
case 2: listeners[i].fn.call(listeners[i].context, a1); break;
|
|
9267
|
-
case 3: listeners[i].fn.call(listeners[i].context, a1, a2); break;
|
|
9268
|
-
case 4: listeners[i].fn.call(listeners[i].context, a1, a2, a3); break;
|
|
9269
|
-
default:
|
|
9270
|
-
if (!args) for (j = 1, args = new Array(len -1); j < len; j++) {
|
|
9271
|
-
args[j - 1] = arguments[j];
|
|
9272
|
-
}
|
|
9273
|
-
|
|
9274
|
-
listeners[i].fn.apply(listeners[i].context, args);
|
|
9275
|
-
}
|
|
9276
|
-
}
|
|
9277
|
-
}
|
|
9278
|
-
|
|
9279
|
-
return true;
|
|
9280
|
-
};
|
|
9281
|
-
|
|
9282
|
-
/**
|
|
9283
|
-
* Add a listener for a given event.
|
|
9284
|
-
*
|
|
9285
|
-
* @param {(String|Symbol)} event The event name.
|
|
9286
|
-
* @param {Function} fn The listener function.
|
|
9287
|
-
* @param {*} [context=this] The context to invoke the listener with.
|
|
9288
|
-
* @returns {EventEmitter} `this`.
|
|
9289
|
-
* @public
|
|
9290
|
-
*/
|
|
9291
|
-
EventEmitter.prototype.on = function on(event, fn, context) {
|
|
9292
|
-
return addListener(this, event, fn, context, false);
|
|
9293
|
-
};
|
|
9294
|
-
|
|
9295
|
-
/**
|
|
9296
|
-
* Add a one-time listener for a given event.
|
|
9297
|
-
*
|
|
9298
|
-
* @param {(String|Symbol)} event The event name.
|
|
9299
|
-
* @param {Function} fn The listener function.
|
|
9300
|
-
* @param {*} [context=this] The context to invoke the listener with.
|
|
9301
|
-
* @returns {EventEmitter} `this`.
|
|
9302
|
-
* @public
|
|
9303
|
-
*/
|
|
9304
|
-
EventEmitter.prototype.once = function once(event, fn, context) {
|
|
9305
|
-
return addListener(this, event, fn, context, true);
|
|
9306
|
-
};
|
|
9307
|
-
|
|
9308
|
-
/**
|
|
9309
|
-
* Remove the listeners of a given event.
|
|
9310
|
-
*
|
|
9311
|
-
* @param {(String|Symbol)} event The event name.
|
|
9312
|
-
* @param {Function} fn Only remove the listeners that match this function.
|
|
9313
|
-
* @param {*} context Only remove the listeners that have this context.
|
|
9314
|
-
* @param {Boolean} once Only remove one-time listeners.
|
|
9315
|
-
* @returns {EventEmitter} `this`.
|
|
9316
|
-
* @public
|
|
9317
|
-
*/
|
|
9318
|
-
EventEmitter.prototype.removeListener = function removeListener(event, fn, context, once) {
|
|
9319
|
-
var evt = prefix ? prefix + event : event;
|
|
9320
|
-
|
|
9321
|
-
if (!this._events[evt]) return this;
|
|
9322
|
-
if (!fn) {
|
|
9323
|
-
clearEvent(this, evt);
|
|
9324
|
-
return this;
|
|
9325
|
-
}
|
|
9326
|
-
|
|
9327
|
-
var listeners = this._events[evt];
|
|
9328
|
-
|
|
9329
|
-
if (listeners.fn) {
|
|
9330
|
-
if (
|
|
9331
|
-
listeners.fn === fn &&
|
|
9332
|
-
(!once || listeners.once) &&
|
|
9333
|
-
(!context || listeners.context === context)
|
|
9334
|
-
) {
|
|
9335
|
-
clearEvent(this, evt);
|
|
9336
|
-
}
|
|
9337
|
-
} else {
|
|
9338
|
-
for (var i = 0, events = [], length = listeners.length; i < length; i++) {
|
|
9339
|
-
if (
|
|
9340
|
-
listeners[i].fn !== fn ||
|
|
9341
|
-
(once && !listeners[i].once) ||
|
|
9342
|
-
(context && listeners[i].context !== context)
|
|
9343
|
-
) {
|
|
9344
|
-
events.push(listeners[i]);
|
|
9345
|
-
}
|
|
9346
|
-
}
|
|
9347
|
-
|
|
9348
|
-
//
|
|
9349
|
-
// Reset the array, or remove it completely if we have no more listeners.
|
|
9350
|
-
//
|
|
9351
|
-
if (events.length) this._events[evt] = events.length === 1 ? events[0] : events;
|
|
9352
|
-
else clearEvent(this, evt);
|
|
9353
|
-
}
|
|
9354
|
-
|
|
9355
|
-
return this;
|
|
9356
|
-
};
|
|
9357
|
-
|
|
9358
|
-
/**
|
|
9359
|
-
* Remove all listeners, or those of the specified event.
|
|
9360
|
-
*
|
|
9361
|
-
* @param {(String|Symbol)} [event] The event name.
|
|
9362
|
-
* @returns {EventEmitter} `this`.
|
|
9363
|
-
* @public
|
|
9364
|
-
*/
|
|
9365
|
-
EventEmitter.prototype.removeAllListeners = function removeAllListeners(event) {
|
|
9366
|
-
var evt;
|
|
9367
|
-
|
|
9368
|
-
if (event) {
|
|
9369
|
-
evt = prefix ? prefix + event : event;
|
|
9370
|
-
if (this._events[evt]) clearEvent(this, evt);
|
|
9371
|
-
} else {
|
|
9372
|
-
this._events = new Events();
|
|
9373
|
-
this._eventsCount = 0;
|
|
9374
|
-
}
|
|
9375
|
-
|
|
9376
|
-
return this;
|
|
9377
|
-
};
|
|
9378
|
-
|
|
9379
|
-
//
|
|
9380
|
-
// Alias methods names because people roll like that.
|
|
9381
|
-
//
|
|
9382
|
-
EventEmitter.prototype.off = EventEmitter.prototype.removeListener;
|
|
9383
|
-
EventEmitter.prototype.addListener = EventEmitter.prototype.on;
|
|
9384
|
-
|
|
9385
|
-
//
|
|
9386
|
-
// Expose the prefix.
|
|
9387
|
-
//
|
|
9388
|
-
EventEmitter.prefixed = prefix;
|
|
9389
|
-
|
|
9390
|
-
//
|
|
9391
|
-
// Allow `EventEmitter` to be imported as module namespace.
|
|
9392
|
-
//
|
|
9393
|
-
EventEmitter.EventEmitter = EventEmitter;
|
|
9394
|
-
|
|
9395
|
-
//
|
|
9396
|
-
// Expose the module.
|
|
9397
|
-
//
|
|
9398
|
-
{
|
|
9399
|
-
module.exports = EventEmitter;
|
|
9400
|
-
}
|
|
9401
|
-
} (eventemitter3));
|
|
9402
|
-
return eventemitter3.exports;
|
|
9403
|
-
}
|
|
9404
|
-
|
|
9405
|
-
var eventemitter3Exports = requireEventemitter3();
|
|
9406
|
-
var EventEmitter2 = /*@__PURE__*/index.getDefaultExportFromCjs(eventemitter3Exports);
|
|
9407
|
-
|
|
9408
10731
|
// src/embedded-provider.ts
|
|
9409
10732
|
|
|
9410
10733
|
// src/constants.ts
|
|
@@ -9416,7 +10739,7 @@ var EmbeddedSolanaChain = class {
|
|
|
9416
10739
|
this.currentNetworkId = NetworkId.SOLANA_MAINNET;
|
|
9417
10740
|
this._connected = false;
|
|
9418
10741
|
this._publicKey = null;
|
|
9419
|
-
this.eventEmitter = new
|
|
10742
|
+
this.eventEmitter = new index.EventEmitter4();
|
|
9420
10743
|
this.setupEventListeners();
|
|
9421
10744
|
this.syncInitialState();
|
|
9422
10745
|
}
|
|
@@ -9440,7 +10763,7 @@ var EmbeddedSolanaChain = class {
|
|
|
9440
10763
|
message: messageStr,
|
|
9441
10764
|
networkId: this.currentNetworkId
|
|
9442
10765
|
});
|
|
9443
|
-
const signature = typeof result.signature === "string" ? new Uint8Array(
|
|
10766
|
+
const signature = typeof result.signature === "string" ? new Uint8Array(index.bs58.decode(result.signature)) : result.signature;
|
|
9444
10767
|
return {
|
|
9445
10768
|
signature,
|
|
9446
10769
|
publicKey: this._publicKey || ""
|
|
@@ -9546,7 +10869,7 @@ var EmbeddedEthereumChain = class {
|
|
|
9546
10869
|
this.currentNetworkId = NetworkId.ETHEREUM_MAINNET;
|
|
9547
10870
|
this._connected = false;
|
|
9548
10871
|
this._accounts = [];
|
|
9549
|
-
this.eventEmitter = new
|
|
10872
|
+
this.eventEmitter = new index.EventEmitter4();
|
|
9550
10873
|
this.setupEventListeners();
|
|
9551
10874
|
this.syncInitialState();
|
|
9552
10875
|
}
|
|
@@ -10123,7 +11446,7 @@ var EmbeddedProvider$1 = class EmbeddedProvider {
|
|
|
10123
11446
|
publicKey: stamperInfo.publicKey,
|
|
10124
11447
|
platform: platformName
|
|
10125
11448
|
});
|
|
10126
|
-
const base64urlPublicKey = base64urlEncode(
|
|
11449
|
+
const base64urlPublicKey = base64urlEncode(index.bs58.decode(stamperInfo.publicKey));
|
|
10127
11450
|
const username = `user-${randomUUID()}`;
|
|
10128
11451
|
const { organizationId } = await tempClient.createOrganization(organizationName, [
|
|
10129
11452
|
{
|
|
@@ -10711,133 +12034,6 @@ var EmbeddedProvider$1 = class EmbeddedProvider {
|
|
|
10711
12034
|
}
|
|
10712
12035
|
};
|
|
10713
12036
|
|
|
10714
|
-
// base-x encoding / decoding
|
|
10715
|
-
// Copyright (c) 2018 base-x contributors
|
|
10716
|
-
// Copyright (c) 2014-2018 The Bitcoin Core developers (base58.cpp)
|
|
10717
|
-
// Distributed under the MIT software license, see the accompanying
|
|
10718
|
-
// file LICENSE or http://www.opensource.org/licenses/mit-license.php.
|
|
10719
|
-
function base (ALPHABET) {
|
|
10720
|
-
if (ALPHABET.length >= 255) { throw new TypeError('Alphabet too long') }
|
|
10721
|
-
const BASE_MAP = new Uint8Array(256);
|
|
10722
|
-
for (let j = 0; j < BASE_MAP.length; j++) {
|
|
10723
|
-
BASE_MAP[j] = 255;
|
|
10724
|
-
}
|
|
10725
|
-
for (let i = 0; i < ALPHABET.length; i++) {
|
|
10726
|
-
const x = ALPHABET.charAt(i);
|
|
10727
|
-
const xc = x.charCodeAt(0);
|
|
10728
|
-
if (BASE_MAP[xc] !== 255) { throw new TypeError(x + ' is ambiguous') }
|
|
10729
|
-
BASE_MAP[xc] = i;
|
|
10730
|
-
}
|
|
10731
|
-
const BASE = ALPHABET.length;
|
|
10732
|
-
const LEADER = ALPHABET.charAt(0);
|
|
10733
|
-
const FACTOR = Math.log(BASE) / Math.log(256); // log(BASE) / log(256), rounded up
|
|
10734
|
-
const iFACTOR = Math.log(256) / Math.log(BASE); // log(256) / log(BASE), rounded up
|
|
10735
|
-
function encode (source) {
|
|
10736
|
-
// eslint-disable-next-line no-empty
|
|
10737
|
-
if (source instanceof Uint8Array) ; else if (ArrayBuffer.isView(source)) {
|
|
10738
|
-
source = new Uint8Array(source.buffer, source.byteOffset, source.byteLength);
|
|
10739
|
-
} else if (Array.isArray(source)) {
|
|
10740
|
-
source = Uint8Array.from(source);
|
|
10741
|
-
}
|
|
10742
|
-
if (!(source instanceof Uint8Array)) { throw new TypeError('Expected Uint8Array') }
|
|
10743
|
-
if (source.length === 0) { return '' }
|
|
10744
|
-
// Skip & count leading zeroes.
|
|
10745
|
-
let zeroes = 0;
|
|
10746
|
-
let length = 0;
|
|
10747
|
-
let pbegin = 0;
|
|
10748
|
-
const pend = source.length;
|
|
10749
|
-
while (pbegin !== pend && source[pbegin] === 0) {
|
|
10750
|
-
pbegin++;
|
|
10751
|
-
zeroes++;
|
|
10752
|
-
}
|
|
10753
|
-
// Allocate enough space in big-endian base58 representation.
|
|
10754
|
-
const size = ((pend - pbegin) * iFACTOR + 1) >>> 0;
|
|
10755
|
-
const b58 = new Uint8Array(size);
|
|
10756
|
-
// Process the bytes.
|
|
10757
|
-
while (pbegin !== pend) {
|
|
10758
|
-
let carry = source[pbegin];
|
|
10759
|
-
// Apply "b58 = b58 * 256 + ch".
|
|
10760
|
-
let i = 0;
|
|
10761
|
-
for (let it1 = size - 1; (carry !== 0 || i < length) && (it1 !== -1); it1--, i++) {
|
|
10762
|
-
carry += (256 * b58[it1]) >>> 0;
|
|
10763
|
-
b58[it1] = (carry % BASE) >>> 0;
|
|
10764
|
-
carry = (carry / BASE) >>> 0;
|
|
10765
|
-
}
|
|
10766
|
-
if (carry !== 0) { throw new Error('Non-zero carry') }
|
|
10767
|
-
length = i;
|
|
10768
|
-
pbegin++;
|
|
10769
|
-
}
|
|
10770
|
-
// Skip leading zeroes in base58 result.
|
|
10771
|
-
let it2 = size - length;
|
|
10772
|
-
while (it2 !== size && b58[it2] === 0) {
|
|
10773
|
-
it2++;
|
|
10774
|
-
}
|
|
10775
|
-
// Translate the result into a string.
|
|
10776
|
-
let str = LEADER.repeat(zeroes);
|
|
10777
|
-
for (; it2 < size; ++it2) { str += ALPHABET.charAt(b58[it2]); }
|
|
10778
|
-
return str
|
|
10779
|
-
}
|
|
10780
|
-
function decodeUnsafe (source) {
|
|
10781
|
-
if (typeof source !== 'string') { throw new TypeError('Expected String') }
|
|
10782
|
-
if (source.length === 0) { return new Uint8Array() }
|
|
10783
|
-
let psz = 0;
|
|
10784
|
-
// Skip and count leading '1's.
|
|
10785
|
-
let zeroes = 0;
|
|
10786
|
-
let length = 0;
|
|
10787
|
-
while (source[psz] === LEADER) {
|
|
10788
|
-
zeroes++;
|
|
10789
|
-
psz++;
|
|
10790
|
-
}
|
|
10791
|
-
// Allocate enough space in big-endian base256 representation.
|
|
10792
|
-
const size = (((source.length - psz) * FACTOR) + 1) >>> 0; // log(58) / log(256), rounded up.
|
|
10793
|
-
const b256 = new Uint8Array(size);
|
|
10794
|
-
// Process the characters.
|
|
10795
|
-
while (psz < source.length) {
|
|
10796
|
-
// Find code of next character
|
|
10797
|
-
const charCode = source.charCodeAt(psz);
|
|
10798
|
-
// Base map can not be indexed using char code
|
|
10799
|
-
if (charCode > 255) { return }
|
|
10800
|
-
// Decode character
|
|
10801
|
-
let carry = BASE_MAP[charCode];
|
|
10802
|
-
// Invalid character
|
|
10803
|
-
if (carry === 255) { return }
|
|
10804
|
-
let i = 0;
|
|
10805
|
-
for (let it3 = size - 1; (carry !== 0 || i < length) && (it3 !== -1); it3--, i++) {
|
|
10806
|
-
carry += (BASE * b256[it3]) >>> 0;
|
|
10807
|
-
b256[it3] = (carry % 256) >>> 0;
|
|
10808
|
-
carry = (carry / 256) >>> 0;
|
|
10809
|
-
}
|
|
10810
|
-
if (carry !== 0) { throw new Error('Non-zero carry') }
|
|
10811
|
-
length = i;
|
|
10812
|
-
psz++;
|
|
10813
|
-
}
|
|
10814
|
-
// Skip leading zeroes in b256.
|
|
10815
|
-
let it4 = size - length;
|
|
10816
|
-
while (it4 !== size && b256[it4] === 0) {
|
|
10817
|
-
it4++;
|
|
10818
|
-
}
|
|
10819
|
-
const vch = new Uint8Array(zeroes + (size - it4));
|
|
10820
|
-
let j = zeroes;
|
|
10821
|
-
while (it4 !== size) {
|
|
10822
|
-
vch[j++] = b256[it4++];
|
|
10823
|
-
}
|
|
10824
|
-
return vch
|
|
10825
|
-
}
|
|
10826
|
-
function decode (string) {
|
|
10827
|
-
const buffer = decodeUnsafe(string);
|
|
10828
|
-
if (buffer) { return buffer }
|
|
10829
|
-
throw new Error('Non-base' + BASE + ' character')
|
|
10830
|
-
}
|
|
10831
|
-
return {
|
|
10832
|
-
encode,
|
|
10833
|
-
decodeUnsafe,
|
|
10834
|
-
decode
|
|
10835
|
-
}
|
|
10836
|
-
}
|
|
10837
|
-
|
|
10838
|
-
var ALPHABET = '123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz';
|
|
10839
|
-
var bs58 = base(ALPHABET);
|
|
10840
|
-
|
|
10841
12037
|
// src/index.ts
|
|
10842
12038
|
var IndexedDbStamper = class {
|
|
10843
12039
|
// Optional for PKI, required for OIDC
|
|
@@ -10911,14 +12107,14 @@ var IndexedDbStamper = class {
|
|
|
10911
12107
|
const salt = params.type === "OIDC" ? params.salt : this.salt;
|
|
10912
12108
|
const stampData = stampType === "PKI" ? {
|
|
10913
12109
|
// Decode base58 public key to bytes, then encode as base64url (consistent with ApiKeyStamper)
|
|
10914
|
-
publicKey: base64urlEncode(bs58.decode(this.activeKeyPairRecord.keyInfo.publicKey)),
|
|
12110
|
+
publicKey: base64urlEncode(index.bs58.decode(this.activeKeyPairRecord.keyInfo.publicKey)),
|
|
10915
12111
|
signature: signatureBase64url,
|
|
10916
12112
|
kind: "PKI",
|
|
10917
12113
|
algorithm: this.algorithm
|
|
10918
12114
|
} : {
|
|
10919
12115
|
kind: "OIDC",
|
|
10920
12116
|
idToken,
|
|
10921
|
-
publicKey: base64urlEncode(bs58.decode(this.activeKeyPairRecord.keyInfo.publicKey)),
|
|
12117
|
+
publicKey: base64urlEncode(index.bs58.decode(this.activeKeyPairRecord.keyInfo.publicKey)),
|
|
10922
12118
|
salt,
|
|
10923
12119
|
algorithm: this.algorithm,
|
|
10924
12120
|
signature: signatureBase64url
|
|
@@ -11021,7 +12217,7 @@ var IndexedDbStamper = class {
|
|
|
11021
12217
|
["sign", "verify"]
|
|
11022
12218
|
);
|
|
11023
12219
|
const rawPublicKeyBuffer = await crypto.subtle.exportKey("raw", keyPair.publicKey);
|
|
11024
|
-
const publicKeyBase58 = bs58.encode(new Uint8Array(rawPublicKeyBuffer));
|
|
12220
|
+
const publicKeyBase58 = index.bs58.encode(new Uint8Array(rawPublicKeyBuffer));
|
|
11025
12221
|
const keyIdBuffer = await crypto.subtle.digest("SHA-256", rawPublicKeyBuffer);
|
|
11026
12222
|
const keyId = base64urlEncode(new Uint8Array(keyIdBuffer)).substring(0, 16);
|
|
11027
12223
|
const now = Date.now();
|
|
@@ -11521,7 +12717,7 @@ async function discoverWallets(addressTypes) {
|
|
|
11521
12717
|
}
|
|
11522
12718
|
var InjectedWalletSolanaChain = class {
|
|
11523
12719
|
constructor(provider, walletId, walletName) {
|
|
11524
|
-
this.eventEmitter = new EventEmitter4();
|
|
12720
|
+
this.eventEmitter = new index.EventEmitter4();
|
|
11525
12721
|
this._connected = false;
|
|
11526
12722
|
this._publicKey = null;
|
|
11527
12723
|
this.provider = provider;
|
|
@@ -11938,7 +13134,7 @@ var WalletStandardSolanaAdapter = class {
|
|
|
11938
13134
|
throw new Error("No signature found in signAndSendTransaction result");
|
|
11939
13135
|
}
|
|
11940
13136
|
const signatureBytes = this.parseUint8Array(signatureOutput.signature);
|
|
11941
|
-
const signature = bs58
|
|
13137
|
+
const signature = index.bs58.encode(signatureBytes);
|
|
11942
13138
|
return { signature };
|
|
11943
13139
|
} catch (error) {
|
|
11944
13140
|
debug.error(DebugCategory.INJECTED_PROVIDER, "Wallet Standard Solana signAndSendTransaction failed", {
|
|
@@ -12060,7 +13256,7 @@ var WalletStandardSolanaAdapter = class {
|
|
|
12060
13256
|
};
|
|
12061
13257
|
var InjectedWalletEthereumChain = class {
|
|
12062
13258
|
constructor(provider, walletId, walletName) {
|
|
12063
|
-
this.eventEmitter = new EventEmitter4();
|
|
13259
|
+
this.eventEmitter = new index.EventEmitter4();
|
|
12064
13260
|
this._connected = false;
|
|
12065
13261
|
this._chainId = "0x1";
|
|
12066
13262
|
this._accounts = [];
|
|
@@ -12452,7 +13648,7 @@ var InjectedWalletEthereumChain = class {
|
|
|
12452
13648
|
var PhantomSolanaChain = class {
|
|
12453
13649
|
constructor(phantom) {
|
|
12454
13650
|
this._publicKey = null;
|
|
12455
|
-
this.eventEmitter = new EventEmitter4();
|
|
13651
|
+
this.eventEmitter = new index.EventEmitter4();
|
|
12456
13652
|
this.phantom = phantom;
|
|
12457
13653
|
this.setupEventListeners();
|
|
12458
13654
|
}
|
|
@@ -12559,7 +13755,7 @@ var PhantomEthereumChain = class {
|
|
|
12559
13755
|
constructor(phantom) {
|
|
12560
13756
|
this._chainId = "0x1";
|
|
12561
13757
|
this._accounts = [];
|
|
12562
|
-
this.eventEmitter = new EventEmitter4();
|
|
13758
|
+
this.eventEmitter = new index.EventEmitter4();
|
|
12563
13759
|
this.phantom = phantom;
|
|
12564
13760
|
this.setupEventListeners();
|
|
12565
13761
|
}
|
|
@@ -16540,4 +17736,4 @@ exports.useModal = useModal;
|
|
|
16540
17736
|
exports.usePhantom = usePhantom;
|
|
16541
17737
|
exports.useSolana = useSolana;
|
|
16542
17738
|
exports.useTheme = useTheme;
|
|
16543
|
-
//# sourceMappingURL=index-
|
|
17739
|
+
//# sourceMappingURL=index-B08xJEBy.js.map
|