@pooflabs/web 0.0.81-rc5 → 0.0.82
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/auth/index.d.ts +10 -1
- package/dist/auth/providers/phantom-wallet-provider.d.ts +20 -21
- package/dist/global.d.ts +3 -1
- package/dist/{index-Fjyk5jYL.js → index-BicMkamC.js} +483 -522
- package/dist/index-BicMkamC.js.map +1 -0
- package/dist/{index-Bkr4BRoP.esm.js → index-BsY_Lgiu.esm.js} +482 -522
- package/dist/index-BsY_Lgiu.esm.js.map +1 -0
- package/dist/index-CHWmdXHE.esm.js +6 -0
- package/dist/index-CHWmdXHE.esm.js.map +1 -0
- package/dist/{index-DB9nDInp.esm.js → index-CK_2Zn89.esm.js} +3825 -563
- package/dist/index-CK_2Zn89.esm.js.map +1 -0
- package/dist/{index-D_ta2S2c.js → index-Ci3m3diI.js} +3825 -563
- package/dist/index-Ci3m3diI.js.map +1 -0
- package/dist/{index-CZhJBWap.esm.js → index-DWf2AOhe.esm.js} +3824 -562
- package/dist/index-DWf2AOhe.esm.js.map +1 -0
- package/dist/{index-Bg_ApFIo.js → index-DlKo76M3.js} +3826 -564
- package/dist/index-DlKo76M3.js.map +1 -0
- package/dist/index-Dz0bPXrU.js +8 -0
- package/dist/index-Dz0bPXrU.js.map +1 -0
- package/dist/{index.browser-DHi7UhqF.js → index.browser-BkMiHSON.js} +2 -2
- package/dist/{index.browser-DHi7UhqF.js.map → index.browser-BkMiHSON.js.map} +1 -1
- package/dist/{index.browser-Disp7Kcb.esm.js → index.browser-C9bFQZyQ.esm.js} +128 -5
- package/dist/index.browser-C9bFQZyQ.esm.js.map +1 -0
- package/dist/{index.browser-iqs5DlRU.esm.js → index.browser-DCOvqSUT.esm.js} +2 -2
- package/dist/{index.browser-iqs5DlRU.esm.js.map → index.browser-DCOvqSUT.esm.js.map} +1 -1
- package/dist/{index.browser-BTlliHCf.esm.js → index.browser-Dbq5Qf1G.esm.js} +128 -5
- package/dist/index.browser-Dbq5Qf1G.esm.js.map +1 -0
- package/dist/{index.browser-DvTeEO2r.js → index.browser-Df7yN8D5.js} +129 -6
- package/dist/index.browser-Df7yN8D5.js.map +1 -0
- package/dist/{index.browser-DRTQuf0J.js → index.browser-dszs5oe5.js} +129 -6
- package/dist/index.browser-dszs5oe5.js.map +1 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.esm.js +1 -1
- package/dist/index.js +1 -1
- package/dist/{index.native-DJWuqJTZ.js → index.native-11supFRU.js} +2742 -240
- package/dist/index.native-11supFRU.js.map +1 -0
- package/dist/{index.native-DYgJWWY4.esm.js → index.native-CLaHKvDv.esm.js} +2740 -241
- package/dist/index.native-CLaHKvDv.esm.js.map +1 -0
- package/dist/index.native.esm.js +1 -1
- package/dist/index.native.js +1 -1
- package/dist/{phantom-wallet-provider-DSFGWSOJ.esm.js → phantom-wallet-provider-BN47klTp.esm.js} +148 -239
- package/dist/phantom-wallet-provider-BN47klTp.esm.js.map +1 -0
- package/dist/{phantom-wallet-provider-fofd8BMo.js → phantom-wallet-provider-Xb070-O6.js} +148 -239
- package/dist/phantom-wallet-provider-Xb070-O6.js.map +1 -0
- package/dist/{privy-wallet-provider-Csv34Kcc.js → privy-wallet-provider-Ch22rj_G.js} +3 -3
- package/dist/privy-wallet-provider-Ch22rj_G.js.map +1 -0
- package/dist/{privy-wallet-provider-TRToDe4Q.esm.js → privy-wallet-provider-DUJS5viU.esm.js} +3 -3
- package/dist/privy-wallet-provider-DUJS5viU.esm.js.map +1 -0
- package/dist/{solana-mobile-wallet-provider-L7nRuxhv.esm.js → solana-mobile-wallet-provider-BF04Xp8P.esm.js} +4 -83
- package/dist/solana-mobile-wallet-provider-BF04Xp8P.esm.js.map +1 -0
- package/dist/{solana-mobile-wallet-provider-Cp65LfNb.js → solana-mobile-wallet-provider-BXm94fqW.js} +4 -83
- package/dist/solana-mobile-wallet-provider-BXm94fqW.js.map +1 -0
- package/package.json +3 -3
- package/dist/index-Bdcc5821.js +0 -2375
- package/dist/index-Bdcc5821.js.map +0 -1
- package/dist/index-Bg_ApFIo.js.map +0 -1
- package/dist/index-Bkr4BRoP.esm.js.map +0 -1
- package/dist/index-CZhJBWap.esm.js.map +0 -1
- package/dist/index-CrOVJFX9.esm.js +0 -2373
- package/dist/index-CrOVJFX9.esm.js.map +0 -1
- package/dist/index-DB9nDInp.esm.js.map +0 -1
- package/dist/index-D_ta2S2c.js.map +0 -1
- package/dist/index-Fjyk5jYL.js.map +0 -1
- package/dist/index.browser-BTlliHCf.esm.js.map +0 -1
- package/dist/index.browser-DRTQuf0J.js.map +0 -1
- package/dist/index.browser-Disp7Kcb.esm.js.map +0 -1
- package/dist/index.browser-DvTeEO2r.js.map +0 -1
- package/dist/index.native-DJWuqJTZ.js.map +0 -1
- package/dist/index.native-DYgJWWY4.esm.js.map +0 -1
- package/dist/phantom-wallet-provider-DSFGWSOJ.esm.js.map +0 -1
- package/dist/phantom-wallet-provider-fofd8BMo.js.map +0 -1
- package/dist/privy-wallet-provider-Csv34Kcc.js.map +0 -1
- package/dist/privy-wallet-provider-TRToDe4Q.esm.js.map +0 -1
- package/dist/solana-mobile-wallet-provider-Cp65LfNb.js.map +0 -1
- package/dist/solana-mobile-wallet-provider-L7nRuxhv.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-BicMkamC.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,269 +1018,2673 @@ function isSolanaChain(networkId) {
|
|
|
1018
1018
|
return network === "solana";
|
|
1019
1019
|
}
|
|
1020
1020
|
|
|
1021
|
-
var
|
|
1022
|
-
var hasRequiredSrc;
|
|
1021
|
+
var naclFast = {exports: {}};
|
|
1023
1022
|
|
|
1024
|
-
|
|
1025
|
-
if (hasRequiredSrc) return src;
|
|
1026
|
-
hasRequiredSrc = 1;
|
|
1027
|
-
// base-x encoding / decoding
|
|
1028
|
-
// Copyright (c) 2018 base-x contributors
|
|
1029
|
-
// Copyright (c) 2014-2018 The Bitcoin Core developers (base58.cpp)
|
|
1030
|
-
// Distributed under the MIT software license, see the accompanying
|
|
1031
|
-
// file LICENSE or http://www.opensource.org/licenses/mit-license.php.
|
|
1032
|
-
function base (ALPHABET) {
|
|
1033
|
-
if (ALPHABET.length >= 255) { throw new TypeError('Alphabet too long') }
|
|
1034
|
-
var BASE_MAP = new Uint8Array(256);
|
|
1035
|
-
for (var j = 0; j < BASE_MAP.length; j++) {
|
|
1036
|
-
BASE_MAP[j] = 255;
|
|
1037
|
-
}
|
|
1038
|
-
for (var i = 0; i < ALPHABET.length; i++) {
|
|
1039
|
-
var x = ALPHABET.charAt(i);
|
|
1040
|
-
var xc = x.charCodeAt(0);
|
|
1041
|
-
if (BASE_MAP[xc] !== 255) { throw new TypeError(x + ' is ambiguous') }
|
|
1042
|
-
BASE_MAP[xc] = i;
|
|
1043
|
-
}
|
|
1044
|
-
var BASE = ALPHABET.length;
|
|
1045
|
-
var LEADER = ALPHABET.charAt(0);
|
|
1046
|
-
var FACTOR = Math.log(BASE) / Math.log(256); // log(BASE) / log(256), rounded up
|
|
1047
|
-
var iFACTOR = Math.log(256) / Math.log(BASE); // log(256) / log(BASE), rounded up
|
|
1048
|
-
function encode (source) {
|
|
1049
|
-
if (source instanceof Uint8Array) ; else if (ArrayBuffer.isView(source)) {
|
|
1050
|
-
source = new Uint8Array(source.buffer, source.byteOffset, source.byteLength);
|
|
1051
|
-
} else if (Array.isArray(source)) {
|
|
1052
|
-
source = Uint8Array.from(source);
|
|
1053
|
-
}
|
|
1054
|
-
if (!(source instanceof Uint8Array)) { throw new TypeError('Expected Uint8Array') }
|
|
1055
|
-
if (source.length === 0) { return '' }
|
|
1056
|
-
// Skip & count leading zeroes.
|
|
1057
|
-
var zeroes = 0;
|
|
1058
|
-
var length = 0;
|
|
1059
|
-
var pbegin = 0;
|
|
1060
|
-
var pend = source.length;
|
|
1061
|
-
while (pbegin !== pend && source[pbegin] === 0) {
|
|
1062
|
-
pbegin++;
|
|
1063
|
-
zeroes++;
|
|
1064
|
-
}
|
|
1065
|
-
// Allocate enough space in big-endian base58 representation.
|
|
1066
|
-
var size = ((pend - pbegin) * iFACTOR + 1) >>> 0;
|
|
1067
|
-
var b58 = new Uint8Array(size);
|
|
1068
|
-
// Process the bytes.
|
|
1069
|
-
while (pbegin !== pend) {
|
|
1070
|
-
var carry = source[pbegin];
|
|
1071
|
-
// Apply "b58 = b58 * 256 + ch".
|
|
1072
|
-
var i = 0;
|
|
1073
|
-
for (var it1 = size - 1; (carry !== 0 || i < length) && (it1 !== -1); it1--, i++) {
|
|
1074
|
-
carry += (256 * b58[it1]) >>> 0;
|
|
1075
|
-
b58[it1] = (carry % BASE) >>> 0;
|
|
1076
|
-
carry = (carry / BASE) >>> 0;
|
|
1077
|
-
}
|
|
1078
|
-
if (carry !== 0) { throw new Error('Non-zero carry') }
|
|
1079
|
-
length = i;
|
|
1080
|
-
pbegin++;
|
|
1081
|
-
}
|
|
1082
|
-
// Skip leading zeroes in base58 result.
|
|
1083
|
-
var it2 = size - length;
|
|
1084
|
-
while (it2 !== size && b58[it2] === 0) {
|
|
1085
|
-
it2++;
|
|
1086
|
-
}
|
|
1087
|
-
// Translate the result into a string.
|
|
1088
|
-
var str = LEADER.repeat(zeroes);
|
|
1089
|
-
for (; it2 < size; ++it2) { str += ALPHABET.charAt(b58[it2]); }
|
|
1090
|
-
return str
|
|
1091
|
-
}
|
|
1092
|
-
function decodeUnsafe (source) {
|
|
1093
|
-
if (typeof source !== 'string') { throw new TypeError('Expected String') }
|
|
1094
|
-
if (source.length === 0) { return new Uint8Array() }
|
|
1095
|
-
var psz = 0;
|
|
1096
|
-
// Skip and count leading '1's.
|
|
1097
|
-
var zeroes = 0;
|
|
1098
|
-
var length = 0;
|
|
1099
|
-
while (source[psz] === LEADER) {
|
|
1100
|
-
zeroes++;
|
|
1101
|
-
psz++;
|
|
1102
|
-
}
|
|
1103
|
-
// Allocate enough space in big-endian base256 representation.
|
|
1104
|
-
var size = (((source.length - psz) * FACTOR) + 1) >>> 0; // log(58) / log(256), rounded up.
|
|
1105
|
-
var b256 = new Uint8Array(size);
|
|
1106
|
-
// Process the characters.
|
|
1107
|
-
while (source[psz]) {
|
|
1108
|
-
// Find code of next character
|
|
1109
|
-
var charCode = source.charCodeAt(psz);
|
|
1110
|
-
// Base map can not be indexed using char code
|
|
1111
|
-
if (charCode > 255) { return }
|
|
1112
|
-
// Decode character
|
|
1113
|
-
var carry = BASE_MAP[charCode];
|
|
1114
|
-
// Invalid character
|
|
1115
|
-
if (carry === 255) { return }
|
|
1116
|
-
var i = 0;
|
|
1117
|
-
for (var it3 = size - 1; (carry !== 0 || i < length) && (it3 !== -1); it3--, i++) {
|
|
1118
|
-
carry += (BASE * b256[it3]) >>> 0;
|
|
1119
|
-
b256[it3] = (carry % 256) >>> 0;
|
|
1120
|
-
carry = (carry / 256) >>> 0;
|
|
1121
|
-
}
|
|
1122
|
-
if (carry !== 0) { throw new Error('Non-zero carry') }
|
|
1123
|
-
length = i;
|
|
1124
|
-
psz++;
|
|
1125
|
-
}
|
|
1126
|
-
// Skip leading zeroes in b256.
|
|
1127
|
-
var it4 = size - length;
|
|
1128
|
-
while (it4 !== size && b256[it4] === 0) {
|
|
1129
|
-
it4++;
|
|
1130
|
-
}
|
|
1131
|
-
var vch = new Uint8Array(zeroes + (size - it4));
|
|
1132
|
-
var j = zeroes;
|
|
1133
|
-
while (it4 !== size) {
|
|
1134
|
-
vch[j++] = b256[it4++];
|
|
1135
|
-
}
|
|
1136
|
-
return vch
|
|
1137
|
-
}
|
|
1138
|
-
function decode (string) {
|
|
1139
|
-
var buffer = decodeUnsafe(string);
|
|
1140
|
-
if (buffer) { return buffer }
|
|
1141
|
-
throw new Error('Non-base' + BASE + ' character')
|
|
1142
|
-
}
|
|
1143
|
-
return {
|
|
1144
|
-
encode: encode,
|
|
1145
|
-
decodeUnsafe: decodeUnsafe,
|
|
1146
|
-
decode: decode
|
|
1147
|
-
}
|
|
1148
|
-
}
|
|
1149
|
-
src = base;
|
|
1150
|
-
return src;
|
|
1151
|
-
}
|
|
1023
|
+
var hasRequiredNaclFast;
|
|
1152
1024
|
|
|
1153
|
-
|
|
1154
|
-
|
|
1025
|
+
function requireNaclFast () {
|
|
1026
|
+
if (hasRequiredNaclFast) return naclFast.exports;
|
|
1027
|
+
hasRequiredNaclFast = 1;
|
|
1028
|
+
(function (module) {
|
|
1029
|
+
(function(nacl) {
|
|
1155
1030
|
|
|
1156
|
-
|
|
1157
|
-
|
|
1158
|
-
|
|
1159
|
-
|
|
1160
|
-
|
|
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/
|
|
1161
1036
|
|
|
1162
|
-
|
|
1163
|
-
|
|
1164
|
-
|
|
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
|
+
};
|
|
1165
1042
|
|
|
1166
|
-
|
|
1043
|
+
// Pluggable, initialized in high-level API below.
|
|
1044
|
+
var randombytes = function(/* x, n */) { throw new Error('no PRNG'); };
|
|
1167
1045
|
|
|
1168
|
-
|
|
1169
|
-
var
|
|
1170
|
-
|
|
1171
|
-
|
|
1172
|
-
|
|
1173
|
-
|
|
1174
|
-
|
|
1175
|
-
|
|
1176
|
-
|
|
1177
|
-
|
|
1178
|
-
|
|
1179
|
-
|
|
1180
|
-
|
|
1181
|
-
|
|
1182
|
-
|
|
1183
|
-
|
|
1184
|
-
|
|
1185
|
-
|
|
1186
|
-
|
|
1187
|
-
|
|
1188
|
-
|
|
1189
|
-
|
|
1190
|
-
|
|
1191
|
-
|
|
1192
|
-
|
|
1193
|
-
|
|
1194
|
-
|
|
1195
|
-
|
|
1196
|
-
|
|
1197
|
-
|
|
1198
|
-
|
|
1199
|
-
|
|
1200
|
-
|
|
1201
|
-
|
|
1202
|
-
|
|
1203
|
-
|
|
1204
|
-
|
|
1205
|
-
|
|
1206
|
-
|
|
1207
|
-
[
|
|
1208
|
-
|
|
1209
|
-
|
|
1210
|
-
|
|
1211
|
-
|
|
1212
|
-
[
|
|
1213
|
-
|
|
1214
|
-
|
|
1215
|
-
|
|
1216
|
-
|
|
1217
|
-
|
|
1218
|
-
|
|
1219
|
-
|
|
1220
|
-
|
|
1221
|
-
|
|
1222
|
-
|
|
1223
|
-
|
|
1224
|
-
|
|
1225
|
-
|
|
1226
|
-
|
|
1227
|
-
|
|
1228
|
-
|
|
1229
|
-
|
|
1230
|
-
|
|
1231
|
-
|
|
1232
|
-
|
|
1233
|
-
|
|
1234
|
-
|
|
1235
|
-
|
|
1236
|
-
|
|
1237
|
-
|
|
1238
|
-
|
|
1239
|
-
|
|
1240
|
-
|
|
1241
|
-
|
|
1242
|
-
|
|
1243
|
-
|
|
1244
|
-
|
|
1245
|
-
|
|
1246
|
-
|
|
1247
|
-
|
|
1248
|
-
|
|
1249
|
-
|
|
1250
|
-
|
|
1251
|
-
|
|
1252
|
-
|
|
1253
|
-
|
|
1254
|
-
|
|
1255
|
-
|
|
1256
|
-
|
|
1257
|
-
|
|
1258
|
-
|
|
1259
|
-
|
|
1260
|
-
|
|
1261
|
-
|
|
1262
|
-
|
|
1263
|
-
|
|
1264
|
-
|
|
1265
|
-
|
|
1266
|
-
|
|
1267
|
-
|
|
1268
|
-
|
|
1269
|
-
|
|
1270
|
-
|
|
1271
|
-
|
|
1272
|
-
|
|
1273
|
-
|
|
1274
|
-
|
|
1275
|
-
|
|
1276
|
-
|
|
1277
|
-
|
|
1278
|
-
|
|
1279
|
-
|
|
1280
|
-
|
|
1281
|
-
|
|
1282
|
-
|
|
1283
|
-
|
|
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
|
+
|
|
3425
|
+
var src;
|
|
3426
|
+
var hasRequiredSrc;
|
|
3427
|
+
|
|
3428
|
+
function requireSrc () {
|
|
3429
|
+
if (hasRequiredSrc) return src;
|
|
3430
|
+
hasRequiredSrc = 1;
|
|
3431
|
+
// base-x encoding / decoding
|
|
3432
|
+
// Copyright (c) 2018 base-x contributors
|
|
3433
|
+
// Copyright (c) 2014-2018 The Bitcoin Core developers (base58.cpp)
|
|
3434
|
+
// Distributed under the MIT software license, see the accompanying
|
|
3435
|
+
// file LICENSE or http://www.opensource.org/licenses/mit-license.php.
|
|
3436
|
+
function base (ALPHABET) {
|
|
3437
|
+
if (ALPHABET.length >= 255) { throw new TypeError('Alphabet too long') }
|
|
3438
|
+
var BASE_MAP = new Uint8Array(256);
|
|
3439
|
+
for (var j = 0; j < BASE_MAP.length; j++) {
|
|
3440
|
+
BASE_MAP[j] = 255;
|
|
3441
|
+
}
|
|
3442
|
+
for (var i = 0; i < ALPHABET.length; i++) {
|
|
3443
|
+
var x = ALPHABET.charAt(i);
|
|
3444
|
+
var xc = x.charCodeAt(0);
|
|
3445
|
+
if (BASE_MAP[xc] !== 255) { throw new TypeError(x + ' is ambiguous') }
|
|
3446
|
+
BASE_MAP[xc] = i;
|
|
3447
|
+
}
|
|
3448
|
+
var BASE = ALPHABET.length;
|
|
3449
|
+
var LEADER = ALPHABET.charAt(0);
|
|
3450
|
+
var FACTOR = Math.log(BASE) / Math.log(256); // log(BASE) / log(256), rounded up
|
|
3451
|
+
var iFACTOR = Math.log(256) / Math.log(BASE); // log(256) / log(BASE), rounded up
|
|
3452
|
+
function encode (source) {
|
|
3453
|
+
if (source instanceof Uint8Array) ; else if (ArrayBuffer.isView(source)) {
|
|
3454
|
+
source = new Uint8Array(source.buffer, source.byteOffset, source.byteLength);
|
|
3455
|
+
} else if (Array.isArray(source)) {
|
|
3456
|
+
source = Uint8Array.from(source);
|
|
3457
|
+
}
|
|
3458
|
+
if (!(source instanceof Uint8Array)) { throw new TypeError('Expected Uint8Array') }
|
|
3459
|
+
if (source.length === 0) { return '' }
|
|
3460
|
+
// Skip & count leading zeroes.
|
|
3461
|
+
var zeroes = 0;
|
|
3462
|
+
var length = 0;
|
|
3463
|
+
var pbegin = 0;
|
|
3464
|
+
var pend = source.length;
|
|
3465
|
+
while (pbegin !== pend && source[pbegin] === 0) {
|
|
3466
|
+
pbegin++;
|
|
3467
|
+
zeroes++;
|
|
3468
|
+
}
|
|
3469
|
+
// Allocate enough space in big-endian base58 representation.
|
|
3470
|
+
var size = ((pend - pbegin) * iFACTOR + 1) >>> 0;
|
|
3471
|
+
var b58 = new Uint8Array(size);
|
|
3472
|
+
// Process the bytes.
|
|
3473
|
+
while (pbegin !== pend) {
|
|
3474
|
+
var carry = source[pbegin];
|
|
3475
|
+
// Apply "b58 = b58 * 256 + ch".
|
|
3476
|
+
var i = 0;
|
|
3477
|
+
for (var it1 = size - 1; (carry !== 0 || i < length) && (it1 !== -1); it1--, i++) {
|
|
3478
|
+
carry += (256 * b58[it1]) >>> 0;
|
|
3479
|
+
b58[it1] = (carry % BASE) >>> 0;
|
|
3480
|
+
carry = (carry / BASE) >>> 0;
|
|
3481
|
+
}
|
|
3482
|
+
if (carry !== 0) { throw new Error('Non-zero carry') }
|
|
3483
|
+
length = i;
|
|
3484
|
+
pbegin++;
|
|
3485
|
+
}
|
|
3486
|
+
// Skip leading zeroes in base58 result.
|
|
3487
|
+
var it2 = size - length;
|
|
3488
|
+
while (it2 !== size && b58[it2] === 0) {
|
|
3489
|
+
it2++;
|
|
3490
|
+
}
|
|
3491
|
+
// Translate the result into a string.
|
|
3492
|
+
var str = LEADER.repeat(zeroes);
|
|
3493
|
+
for (; it2 < size; ++it2) { str += ALPHABET.charAt(b58[it2]); }
|
|
3494
|
+
return str
|
|
3495
|
+
}
|
|
3496
|
+
function decodeUnsafe (source) {
|
|
3497
|
+
if (typeof source !== 'string') { throw new TypeError('Expected String') }
|
|
3498
|
+
if (source.length === 0) { return new Uint8Array() }
|
|
3499
|
+
var psz = 0;
|
|
3500
|
+
// Skip and count leading '1's.
|
|
3501
|
+
var zeroes = 0;
|
|
3502
|
+
var length = 0;
|
|
3503
|
+
while (source[psz] === LEADER) {
|
|
3504
|
+
zeroes++;
|
|
3505
|
+
psz++;
|
|
3506
|
+
}
|
|
3507
|
+
// Allocate enough space in big-endian base256 representation.
|
|
3508
|
+
var size = (((source.length - psz) * FACTOR) + 1) >>> 0; // log(58) / log(256), rounded up.
|
|
3509
|
+
var b256 = new Uint8Array(size);
|
|
3510
|
+
// Process the characters.
|
|
3511
|
+
while (source[psz]) {
|
|
3512
|
+
// Find code of next character
|
|
3513
|
+
var charCode = source.charCodeAt(psz);
|
|
3514
|
+
// Base map can not be indexed using char code
|
|
3515
|
+
if (charCode > 255) { return }
|
|
3516
|
+
// Decode character
|
|
3517
|
+
var carry = BASE_MAP[charCode];
|
|
3518
|
+
// Invalid character
|
|
3519
|
+
if (carry === 255) { return }
|
|
3520
|
+
var i = 0;
|
|
3521
|
+
for (var it3 = size - 1; (carry !== 0 || i < length) && (it3 !== -1); it3--, i++) {
|
|
3522
|
+
carry += (BASE * b256[it3]) >>> 0;
|
|
3523
|
+
b256[it3] = (carry % 256) >>> 0;
|
|
3524
|
+
carry = (carry / 256) >>> 0;
|
|
3525
|
+
}
|
|
3526
|
+
if (carry !== 0) { throw new Error('Non-zero carry') }
|
|
3527
|
+
length = i;
|
|
3528
|
+
psz++;
|
|
3529
|
+
}
|
|
3530
|
+
// Skip leading zeroes in b256.
|
|
3531
|
+
var it4 = size - length;
|
|
3532
|
+
while (it4 !== size && b256[it4] === 0) {
|
|
3533
|
+
it4++;
|
|
3534
|
+
}
|
|
3535
|
+
var vch = new Uint8Array(zeroes + (size - it4));
|
|
3536
|
+
var j = zeroes;
|
|
3537
|
+
while (it4 !== size) {
|
|
3538
|
+
vch[j++] = b256[it4++];
|
|
3539
|
+
}
|
|
3540
|
+
return vch
|
|
3541
|
+
}
|
|
3542
|
+
function decode (string) {
|
|
3543
|
+
var buffer = decodeUnsafe(string);
|
|
3544
|
+
if (buffer) { return buffer }
|
|
3545
|
+
throw new Error('Non-base' + BASE + ' character')
|
|
3546
|
+
}
|
|
3547
|
+
return {
|
|
3548
|
+
encode: encode,
|
|
3549
|
+
decodeUnsafe: decodeUnsafe,
|
|
3550
|
+
decode: decode
|
|
3551
|
+
}
|
|
3552
|
+
}
|
|
3553
|
+
src = base;
|
|
3554
|
+
return src;
|
|
3555
|
+
}
|
|
3556
|
+
|
|
3557
|
+
var bs58$3;
|
|
3558
|
+
var hasRequiredBs58;
|
|
3559
|
+
|
|
3560
|
+
function requireBs58 () {
|
|
3561
|
+
if (hasRequiredBs58) return bs58$3;
|
|
3562
|
+
hasRequiredBs58 = 1;
|
|
3563
|
+
const basex = requireSrc();
|
|
3564
|
+
const ALPHABET = '123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz';
|
|
3565
|
+
|
|
3566
|
+
bs58$3 = basex(ALPHABET);
|
|
3567
|
+
return bs58$3;
|
|
3568
|
+
}
|
|
3569
|
+
|
|
3570
|
+
requireBs58();
|
|
3571
|
+
|
|
3572
|
+
// src/PhantomClient.ts
|
|
3573
|
+
var CAIP2_NETWORK_MAPPINGS = {
|
|
3574
|
+
// Solana networks
|
|
3575
|
+
[NetworkId.SOLANA_MAINNET]: {
|
|
3576
|
+
chain: "solana",
|
|
3577
|
+
network: "mainnet",
|
|
3578
|
+
description: "Solana Mainnet-Beta"
|
|
3579
|
+
},
|
|
3580
|
+
[NetworkId.SOLANA_DEVNET]: {
|
|
3581
|
+
chain: "solana",
|
|
3582
|
+
network: "devnet",
|
|
3583
|
+
description: "Solana Devnet"
|
|
3584
|
+
},
|
|
3585
|
+
[NetworkId.SOLANA_TESTNET]: {
|
|
3586
|
+
chain: "solana",
|
|
3587
|
+
network: "testnet",
|
|
3588
|
+
description: "Solana Testnet"
|
|
3589
|
+
},
|
|
3590
|
+
// Ethereum/EVM networks
|
|
3591
|
+
[NetworkId.ETHEREUM_MAINNET]: {
|
|
3592
|
+
chain: "ethereum",
|
|
3593
|
+
network: "mainnet",
|
|
3594
|
+
description: "Ethereum Mainnet"
|
|
3595
|
+
},
|
|
3596
|
+
[NetworkId.ETHEREUM_SEPOLIA]: {
|
|
3597
|
+
chain: "ethereum",
|
|
3598
|
+
network: "sepolia",
|
|
3599
|
+
description: "Sepolia Testnet"
|
|
3600
|
+
},
|
|
3601
|
+
[NetworkId.POLYGON_MAINNET]: {
|
|
3602
|
+
chain: "polygon",
|
|
3603
|
+
network: "mainnet",
|
|
3604
|
+
description: "Polygon Mainnet"
|
|
3605
|
+
},
|
|
3606
|
+
[NetworkId.POLYGON_AMOY]: {
|
|
3607
|
+
chain: "polygon",
|
|
3608
|
+
network: "amoy",
|
|
3609
|
+
description: "Polygon Amoy Testnet"
|
|
3610
|
+
},
|
|
3611
|
+
[NetworkId.BASE_MAINNET]: {
|
|
3612
|
+
chain: "base",
|
|
3613
|
+
network: "mainnet",
|
|
3614
|
+
description: "Base Mainnet"
|
|
3615
|
+
},
|
|
3616
|
+
[NetworkId.BASE_SEPOLIA]: {
|
|
3617
|
+
chain: "base",
|
|
3618
|
+
network: "sepolia",
|
|
3619
|
+
description: "Base Sepolia Testnet"
|
|
3620
|
+
},
|
|
3621
|
+
[NetworkId.ARBITRUM_ONE]: {
|
|
3622
|
+
chain: "arbitrum",
|
|
3623
|
+
network: "mainnet",
|
|
3624
|
+
description: "Arbitrum One"
|
|
3625
|
+
},
|
|
3626
|
+
[NetworkId.ARBITRUM_SEPOLIA]: {
|
|
3627
|
+
chain: "arbitrum",
|
|
3628
|
+
network: "sepolia",
|
|
3629
|
+
description: "Arbitrum Sepolia Testnet"
|
|
3630
|
+
},
|
|
3631
|
+
[NetworkId.MONAD_MAINNET]: {
|
|
3632
|
+
chain: "monad",
|
|
3633
|
+
network: "mainnet",
|
|
3634
|
+
description: "Monad Mainnet"
|
|
3635
|
+
},
|
|
3636
|
+
[NetworkId.MONAD_TESTNET]: {
|
|
3637
|
+
chain: "monad",
|
|
3638
|
+
network: "testnet",
|
|
3639
|
+
description: "Monad Testnet"
|
|
3640
|
+
},
|
|
3641
|
+
// Bitcoin networks (for future support)
|
|
3642
|
+
[NetworkId.BITCOIN_MAINNET]: {
|
|
3643
|
+
chain: "bitcoin",
|
|
3644
|
+
network: "mainnet",
|
|
3645
|
+
description: "Bitcoin Mainnet"
|
|
3646
|
+
},
|
|
3647
|
+
[NetworkId.BITCOIN_TESTNET]: {
|
|
3648
|
+
chain: "bitcoin",
|
|
3649
|
+
network: "testnet",
|
|
3650
|
+
description: "Bitcoin Testnet"
|
|
3651
|
+
},
|
|
3652
|
+
// Sui networks (for future support)
|
|
3653
|
+
[NetworkId.SUI_MAINNET]: {
|
|
3654
|
+
chain: "sui",
|
|
3655
|
+
network: "mainnet",
|
|
3656
|
+
description: "Sui Mainnet"
|
|
3657
|
+
},
|
|
3658
|
+
[NetworkId.SUI_TESTNET]: {
|
|
3659
|
+
chain: "sui",
|
|
3660
|
+
network: "testnet",
|
|
3661
|
+
description: "Sui Testnet"
|
|
3662
|
+
}
|
|
3663
|
+
};
|
|
3664
|
+
function deriveSubmissionConfig(networkId) {
|
|
3665
|
+
const mapping = CAIP2_NETWORK_MAPPINGS[networkId];
|
|
3666
|
+
if (!mapping) {
|
|
3667
|
+
return void 0;
|
|
3668
|
+
}
|
|
3669
|
+
return {
|
|
3670
|
+
chain: mapping.chain,
|
|
3671
|
+
network: mapping.network
|
|
3672
|
+
};
|
|
3673
|
+
}
|
|
3674
|
+
var DerivationPath = {
|
|
3675
|
+
// Solana - BIP44 standard for Solana (coin type 501)
|
|
3676
|
+
Solana: (accountIndex = 0) => `m/44'/501'/${accountIndex}'/0'`,
|
|
3677
|
+
// Ethereum - BIP44 standard for Ethereum and all EVM-compatible chains (coin type 60)
|
|
3678
|
+
Ethereum: (accountIndex = 0) => `m/44'/60'/0'/0/${accountIndex}`,
|
|
3679
|
+
// Bitcoin - BIP84 standard for Bitcoin (coin type 0)
|
|
3680
|
+
Bitcoin: (accountIndex = 0) => `m/84'/0'/${accountIndex}'/0`,
|
|
3681
|
+
// Sui - BIP44 standard for Sui (coin type 784)
|
|
3682
|
+
Sui: (accountIndex = 0) => `m/44'/784'/${accountIndex}'/0'/0'`
|
|
3683
|
+
};
|
|
3684
|
+
function getNetworkConfig(networkId, accountIndex = 0) {
|
|
3685
|
+
const network = networkId.split(":")[0].toLowerCase();
|
|
3686
|
+
switch (network) {
|
|
3687
|
+
case "solana":
|
|
1284
3688
|
return {
|
|
1285
3689
|
derivationPath: DerivationPath.Solana(accountIndex),
|
|
1286
3690
|
curve: DerivationInfoCurveEnum.ed25519,
|
|
@@ -3120,13 +5524,13 @@ function createAutoConfirmPlugin() {
|
|
|
3120
5524
|
};
|
|
3121
5525
|
}
|
|
3122
5526
|
|
|
3123
|
-
var eventemitter3 = {exports: {}};
|
|
5527
|
+
var eventemitter3$1 = {exports: {}};
|
|
3124
5528
|
|
|
3125
|
-
var hasRequiredEventemitter3;
|
|
5529
|
+
var hasRequiredEventemitter3$1;
|
|
3126
5530
|
|
|
3127
|
-
function requireEventemitter3 () {
|
|
3128
|
-
if (hasRequiredEventemitter3) return eventemitter3.exports;
|
|
3129
|
-
hasRequiredEventemitter3 = 1;
|
|
5531
|
+
function requireEventemitter3$1 () {
|
|
5532
|
+
if (hasRequiredEventemitter3$1) return eventemitter3$1.exports;
|
|
5533
|
+
hasRequiredEventemitter3$1 = 1;
|
|
3130
5534
|
(function (module) {
|
|
3131
5535
|
|
|
3132
5536
|
var has = Object.prototype.hasOwnProperty
|
|
@@ -3463,12 +5867,12 @@ function requireEventemitter3 () {
|
|
|
3463
5867
|
{
|
|
3464
5868
|
module.exports = EventEmitter;
|
|
3465
5869
|
}
|
|
3466
|
-
} (eventemitter3));
|
|
3467
|
-
return eventemitter3.exports;
|
|
5870
|
+
} (eventemitter3$1));
|
|
5871
|
+
return eventemitter3$1.exports;
|
|
3468
5872
|
}
|
|
3469
5873
|
|
|
3470
|
-
var eventemitter3Exports = requireEventemitter3();
|
|
3471
|
-
var EventEmitter3 = /*@__PURE__*/index.getDefaultExportFromCjs(eventemitter3Exports);
|
|
5874
|
+
var eventemitter3Exports$1 = requireEventemitter3$1();
|
|
5875
|
+
var EventEmitter3 = /*@__PURE__*/index.getDefaultExportFromCjs(eventemitter3Exports$1);
|
|
3472
5876
|
|
|
3473
5877
|
// src/index.ts
|
|
3474
5878
|
var isBrowser = typeof window !== "undefined" && typeof window.btoa !== "undefined";
|
|
@@ -8789,300 +11193,1031 @@ class Transaction {
|
|
|
8789
11193
|
assertArgument(result.isSigned(), "unsigned transaction cannot define '.hash'", "tx", tx);
|
|
8790
11194
|
assertArgument(result.hash === tx.hash, "hash mismatch", "tx", tx);
|
|
8791
11195
|
}
|
|
8792
|
-
if (tx.from != null) {
|
|
8793
|
-
assertArgument(result.isSigned(), "unsigned transaction cannot define '.from'", "tx", tx);
|
|
8794
|
-
assertArgument(result.from.toLowerCase() === (tx.from || "").toLowerCase(), "from mismatch", "tx", tx);
|
|
11196
|
+
if (tx.from != null) {
|
|
11197
|
+
assertArgument(result.isSigned(), "unsigned transaction cannot define '.from'", "tx", tx);
|
|
11198
|
+
assertArgument(result.from.toLowerCase() === (tx.from || "").toLowerCase(), "from mismatch", "tx", tx);
|
|
11199
|
+
}
|
|
11200
|
+
return result;
|
|
11201
|
+
}
|
|
11202
|
+
}
|
|
11203
|
+
|
|
11204
|
+
// base-x encoding / decoding
|
|
11205
|
+
// Copyright (c) 2018 base-x contributors
|
|
11206
|
+
// Copyright (c) 2014-2018 The Bitcoin Core developers (base58.cpp)
|
|
11207
|
+
// Distributed under the MIT software license, see the accompanying
|
|
11208
|
+
// file LICENSE or http://www.opensource.org/licenses/mit-license.php.
|
|
11209
|
+
function base$3 (ALPHABET) {
|
|
11210
|
+
if (ALPHABET.length >= 255) { throw new TypeError('Alphabet too long') }
|
|
11211
|
+
const BASE_MAP = new Uint8Array(256);
|
|
11212
|
+
for (let j = 0; j < BASE_MAP.length; j++) {
|
|
11213
|
+
BASE_MAP[j] = 255;
|
|
11214
|
+
}
|
|
11215
|
+
for (let i = 0; i < ALPHABET.length; i++) {
|
|
11216
|
+
const x = ALPHABET.charAt(i);
|
|
11217
|
+
const xc = x.charCodeAt(0);
|
|
11218
|
+
if (BASE_MAP[xc] !== 255) { throw new TypeError(x + ' is ambiguous') }
|
|
11219
|
+
BASE_MAP[xc] = i;
|
|
11220
|
+
}
|
|
11221
|
+
const BASE = ALPHABET.length;
|
|
11222
|
+
const LEADER = ALPHABET.charAt(0);
|
|
11223
|
+
const FACTOR = Math.log(BASE) / Math.log(256); // log(BASE) / log(256), rounded up
|
|
11224
|
+
const iFACTOR = Math.log(256) / Math.log(BASE); // log(256) / log(BASE), rounded up
|
|
11225
|
+
function encode (source) {
|
|
11226
|
+
// eslint-disable-next-line no-empty
|
|
11227
|
+
if (source instanceof Uint8Array) ; else if (ArrayBuffer.isView(source)) {
|
|
11228
|
+
source = new Uint8Array(source.buffer, source.byteOffset, source.byteLength);
|
|
11229
|
+
} else if (Array.isArray(source)) {
|
|
11230
|
+
source = Uint8Array.from(source);
|
|
11231
|
+
}
|
|
11232
|
+
if (!(source instanceof Uint8Array)) { throw new TypeError('Expected Uint8Array') }
|
|
11233
|
+
if (source.length === 0) { return '' }
|
|
11234
|
+
// Skip & count leading zeroes.
|
|
11235
|
+
let zeroes = 0;
|
|
11236
|
+
let length = 0;
|
|
11237
|
+
let pbegin = 0;
|
|
11238
|
+
const pend = source.length;
|
|
11239
|
+
while (pbegin !== pend && source[pbegin] === 0) {
|
|
11240
|
+
pbegin++;
|
|
11241
|
+
zeroes++;
|
|
11242
|
+
}
|
|
11243
|
+
// Allocate enough space in big-endian base58 representation.
|
|
11244
|
+
const size = ((pend - pbegin) * iFACTOR + 1) >>> 0;
|
|
11245
|
+
const b58 = new Uint8Array(size);
|
|
11246
|
+
// Process the bytes.
|
|
11247
|
+
while (pbegin !== pend) {
|
|
11248
|
+
let carry = source[pbegin];
|
|
11249
|
+
// Apply "b58 = b58 * 256 + ch".
|
|
11250
|
+
let i = 0;
|
|
11251
|
+
for (let it1 = size - 1; (carry !== 0 || i < length) && (it1 !== -1); it1--, i++) {
|
|
11252
|
+
carry += (256 * b58[it1]) >>> 0;
|
|
11253
|
+
b58[it1] = (carry % BASE) >>> 0;
|
|
11254
|
+
carry = (carry / BASE) >>> 0;
|
|
11255
|
+
}
|
|
11256
|
+
if (carry !== 0) { throw new Error('Non-zero carry') }
|
|
11257
|
+
length = i;
|
|
11258
|
+
pbegin++;
|
|
11259
|
+
}
|
|
11260
|
+
// Skip leading zeroes in base58 result.
|
|
11261
|
+
let it2 = size - length;
|
|
11262
|
+
while (it2 !== size && b58[it2] === 0) {
|
|
11263
|
+
it2++;
|
|
11264
|
+
}
|
|
11265
|
+
// Translate the result into a string.
|
|
11266
|
+
let str = LEADER.repeat(zeroes);
|
|
11267
|
+
for (; it2 < size; ++it2) { str += ALPHABET.charAt(b58[it2]); }
|
|
11268
|
+
return str
|
|
11269
|
+
}
|
|
11270
|
+
function decodeUnsafe (source) {
|
|
11271
|
+
if (typeof source !== 'string') { throw new TypeError('Expected String') }
|
|
11272
|
+
if (source.length === 0) { return new Uint8Array() }
|
|
11273
|
+
let psz = 0;
|
|
11274
|
+
// Skip and count leading '1's.
|
|
11275
|
+
let zeroes = 0;
|
|
11276
|
+
let length = 0;
|
|
11277
|
+
while (source[psz] === LEADER) {
|
|
11278
|
+
zeroes++;
|
|
11279
|
+
psz++;
|
|
11280
|
+
}
|
|
11281
|
+
// Allocate enough space in big-endian base256 representation.
|
|
11282
|
+
const size = (((source.length - psz) * FACTOR) + 1) >>> 0; // log(58) / log(256), rounded up.
|
|
11283
|
+
const b256 = new Uint8Array(size);
|
|
11284
|
+
// Process the characters.
|
|
11285
|
+
while (psz < source.length) {
|
|
11286
|
+
// Find code of next character
|
|
11287
|
+
const charCode = source.charCodeAt(psz);
|
|
11288
|
+
// Base map can not be indexed using char code
|
|
11289
|
+
if (charCode > 255) { return }
|
|
11290
|
+
// Decode character
|
|
11291
|
+
let carry = BASE_MAP[charCode];
|
|
11292
|
+
// Invalid character
|
|
11293
|
+
if (carry === 255) { return }
|
|
11294
|
+
let i = 0;
|
|
11295
|
+
for (let it3 = size - 1; (carry !== 0 || i < length) && (it3 !== -1); it3--, i++) {
|
|
11296
|
+
carry += (BASE * b256[it3]) >>> 0;
|
|
11297
|
+
b256[it3] = (carry % 256) >>> 0;
|
|
11298
|
+
carry = (carry / 256) >>> 0;
|
|
11299
|
+
}
|
|
11300
|
+
if (carry !== 0) { throw new Error('Non-zero carry') }
|
|
11301
|
+
length = i;
|
|
11302
|
+
psz++;
|
|
11303
|
+
}
|
|
11304
|
+
// Skip leading zeroes in b256.
|
|
11305
|
+
let it4 = size - length;
|
|
11306
|
+
while (it4 !== size && b256[it4] === 0) {
|
|
11307
|
+
it4++;
|
|
11308
|
+
}
|
|
11309
|
+
const vch = new Uint8Array(zeroes + (size - it4));
|
|
11310
|
+
let j = zeroes;
|
|
11311
|
+
while (it4 !== size) {
|
|
11312
|
+
vch[j++] = b256[it4++];
|
|
11313
|
+
}
|
|
11314
|
+
return vch
|
|
11315
|
+
}
|
|
11316
|
+
function decode (string) {
|
|
11317
|
+
const buffer = decodeUnsafe(string);
|
|
11318
|
+
if (buffer) { return buffer }
|
|
11319
|
+
throw new Error('Non-base' + BASE + ' character')
|
|
11320
|
+
}
|
|
11321
|
+
return {
|
|
11322
|
+
encode,
|
|
11323
|
+
decodeUnsafe,
|
|
11324
|
+
decode
|
|
11325
|
+
}
|
|
11326
|
+
}
|
|
11327
|
+
|
|
11328
|
+
var ALPHABET$3 = '123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz';
|
|
11329
|
+
var bs58$2 = base$3(ALPHABET$3);
|
|
11330
|
+
|
|
11331
|
+
// src/index.ts
|
|
11332
|
+
function parseSignMessageResponse(base64Response, networkId) {
|
|
11333
|
+
const networkPrefix = networkId.split(":")[0].toLowerCase();
|
|
11334
|
+
switch (networkPrefix) {
|
|
11335
|
+
case "solana":
|
|
11336
|
+
return parseSolanaSignatureResponse(base64Response);
|
|
11337
|
+
case "eip155":
|
|
11338
|
+
case "ethereum":
|
|
11339
|
+
return parseEVMSignatureResponse(base64Response);
|
|
11340
|
+
case "sui":
|
|
11341
|
+
return parseSuiSignatureResponse(base64Response);
|
|
11342
|
+
case "bip122":
|
|
11343
|
+
case "bitcoin":
|
|
11344
|
+
return parseBitcoinSignatureResponse(base64Response);
|
|
11345
|
+
default:
|
|
11346
|
+
return {
|
|
11347
|
+
signature: base64Response,
|
|
11348
|
+
rawSignature: base64Response
|
|
11349
|
+
};
|
|
11350
|
+
}
|
|
11351
|
+
}
|
|
11352
|
+
function parseTransactionResponse(base64RawTransaction, networkId, hash) {
|
|
11353
|
+
let rawTransaction = base64RawTransaction;
|
|
11354
|
+
if (isEthereumChain(networkId)) {
|
|
11355
|
+
try {
|
|
11356
|
+
const txBytes = base64urlDecode(base64RawTransaction);
|
|
11357
|
+
rawTransaction = "0x" + index.bufferExports.Buffer.from(txBytes).toString("hex");
|
|
11358
|
+
} catch (error) {
|
|
11359
|
+
rawTransaction = base64RawTransaction.startsWith("0x") ? base64RawTransaction : "0x" + base64RawTransaction;
|
|
11360
|
+
}
|
|
11361
|
+
}
|
|
11362
|
+
if (hash) {
|
|
11363
|
+
return {
|
|
11364
|
+
hash,
|
|
11365
|
+
rawTransaction,
|
|
11366
|
+
blockExplorer: getExplorerUrl(networkId, "transaction", hash)
|
|
11367
|
+
};
|
|
11368
|
+
} else {
|
|
11369
|
+
return {
|
|
11370
|
+
rawTransaction
|
|
11371
|
+
};
|
|
11372
|
+
}
|
|
11373
|
+
}
|
|
11374
|
+
function parseSolanaSignatureResponse(base64Response) {
|
|
11375
|
+
try {
|
|
11376
|
+
const signatureBytes = base64urlDecode(base64Response);
|
|
11377
|
+
const signature = bs58$2.encode(signatureBytes);
|
|
11378
|
+
return {
|
|
11379
|
+
signature,
|
|
11380
|
+
rawSignature: base64Response
|
|
11381
|
+
};
|
|
11382
|
+
} catch (error) {
|
|
11383
|
+
return {
|
|
11384
|
+
signature: base64Response,
|
|
11385
|
+
rawSignature: base64Response
|
|
11386
|
+
};
|
|
11387
|
+
}
|
|
11388
|
+
}
|
|
11389
|
+
function parseEVMSignatureResponse(base64Response) {
|
|
11390
|
+
const signatureBytes = base64urlDecode(base64Response);
|
|
11391
|
+
const signature = "0x" + index.bufferExports.Buffer.from(signatureBytes).toString("hex");
|
|
11392
|
+
return {
|
|
11393
|
+
signature,
|
|
11394
|
+
rawSignature: base64Response
|
|
11395
|
+
};
|
|
11396
|
+
}
|
|
11397
|
+
function parseSuiSignatureResponse(base64Response) {
|
|
11398
|
+
try {
|
|
11399
|
+
const signatureBytes = base64urlDecode(base64Response);
|
|
11400
|
+
const signature = index.bufferExports.Buffer.from(signatureBytes).toString("base64");
|
|
11401
|
+
return {
|
|
11402
|
+
signature,
|
|
11403
|
+
rawSignature: base64Response
|
|
11404
|
+
};
|
|
11405
|
+
} catch (error) {
|
|
11406
|
+
return {
|
|
11407
|
+
signature: base64Response,
|
|
11408
|
+
rawSignature: base64Response
|
|
11409
|
+
};
|
|
11410
|
+
}
|
|
11411
|
+
}
|
|
11412
|
+
function parseBitcoinSignatureResponse(base64Response) {
|
|
11413
|
+
try {
|
|
11414
|
+
const signatureBytes = base64urlDecode(base64Response);
|
|
11415
|
+
const signature = index.bufferExports.Buffer.from(signatureBytes).toString("hex");
|
|
11416
|
+
return {
|
|
11417
|
+
signature,
|
|
11418
|
+
rawSignature: base64Response
|
|
11419
|
+
};
|
|
11420
|
+
} catch (error) {
|
|
11421
|
+
return {
|
|
11422
|
+
signature: base64Response,
|
|
11423
|
+
rawSignature: base64Response
|
|
11424
|
+
};
|
|
11425
|
+
}
|
|
11426
|
+
}
|
|
11427
|
+
function parseSolanaSignedTransaction(base64RawTransaction) {
|
|
11428
|
+
try {
|
|
11429
|
+
const transactionBytes = base64urlDecode(base64RawTransaction);
|
|
11430
|
+
return deserializeSolanaTransaction(transactionBytes);
|
|
11431
|
+
} catch (error) {
|
|
11432
|
+
return null;
|
|
11433
|
+
}
|
|
11434
|
+
}
|
|
11435
|
+
function deserializeSolanaTransaction(transactionBytes) {
|
|
11436
|
+
try {
|
|
11437
|
+
const transaction = web3_js.Transaction.from(transactionBytes);
|
|
11438
|
+
return transaction;
|
|
11439
|
+
} catch (legacyError) {
|
|
11440
|
+
if (legacyError instanceof Error && legacyError.message.includes("Versioned messages")) {
|
|
11441
|
+
const versionedTransaction = web3_js.VersionedTransaction.deserialize(transactionBytes);
|
|
11442
|
+
return versionedTransaction;
|
|
11443
|
+
}
|
|
11444
|
+
throw legacyError;
|
|
11445
|
+
}
|
|
11446
|
+
}
|
|
11447
|
+
|
|
11448
|
+
// src/index.ts
|
|
11449
|
+
async function parseToKmsTransaction(transaction, networkId) {
|
|
11450
|
+
const networkPrefix = networkId.split(":")[0].toLowerCase();
|
|
11451
|
+
switch (networkPrefix) {
|
|
11452
|
+
case "solana":
|
|
11453
|
+
return parseSolanaTransactionToBase64Url(transaction);
|
|
11454
|
+
case "ethereum":
|
|
11455
|
+
case "eip155":
|
|
11456
|
+
case "polygon":
|
|
11457
|
+
case "optimism":
|
|
11458
|
+
case "arbitrum":
|
|
11459
|
+
case "base":
|
|
11460
|
+
return parseEVMTransactionToHex(transaction);
|
|
11461
|
+
case "sui":
|
|
11462
|
+
return await parseSuiTransactionToBase64Url(transaction);
|
|
11463
|
+
case "bitcoin":
|
|
11464
|
+
return parseBitcoinTransactionToBase64Url(transaction);
|
|
11465
|
+
default:
|
|
11466
|
+
throw new Error(`Unsupported network: ${networkPrefix}`);
|
|
11467
|
+
}
|
|
11468
|
+
}
|
|
11469
|
+
function parseSolanaTransactionToBase64Url(transaction) {
|
|
11470
|
+
if (transaction?.messageBytes != null) {
|
|
11471
|
+
return {
|
|
11472
|
+
parsed: base64urlEncode(transaction.messageBytes),
|
|
11473
|
+
originalFormat: "@solana/kit"
|
|
11474
|
+
};
|
|
11475
|
+
}
|
|
11476
|
+
if (typeof transaction?.serialize === "function") {
|
|
11477
|
+
const serialized = transaction.serialize({
|
|
11478
|
+
requireAllSignatures: false,
|
|
11479
|
+
verifySignatures: false
|
|
11480
|
+
});
|
|
11481
|
+
return {
|
|
11482
|
+
parsed: base64urlEncode(serialized),
|
|
11483
|
+
originalFormat: "@solana/web3.js"
|
|
11484
|
+
};
|
|
11485
|
+
}
|
|
11486
|
+
if (transaction instanceof Uint8Array) {
|
|
11487
|
+
return {
|
|
11488
|
+
parsed: base64urlEncode(transaction),
|
|
11489
|
+
originalFormat: "bytes"
|
|
11490
|
+
};
|
|
11491
|
+
}
|
|
11492
|
+
if (typeof transaction === "string") {
|
|
11493
|
+
try {
|
|
11494
|
+
const bytes = index.bufferExports.Buffer.from(transaction, "base64");
|
|
11495
|
+
return {
|
|
11496
|
+
parsed: base64urlEncode(new Uint8Array(bytes)),
|
|
11497
|
+
originalFormat: "base64"
|
|
11498
|
+
};
|
|
11499
|
+
} catch {
|
|
11500
|
+
throw new Error("Unsupported Solana transaction format");
|
|
11501
|
+
}
|
|
11502
|
+
}
|
|
11503
|
+
throw new Error("Unsupported Solana transaction format");
|
|
11504
|
+
}
|
|
11505
|
+
function parseEVMTransactionToHex(transaction) {
|
|
11506
|
+
if (typeof transaction === "string" && transaction.startsWith("0x")) {
|
|
11507
|
+
return {
|
|
11508
|
+
parsed: transaction,
|
|
11509
|
+
originalFormat: "hex"
|
|
11510
|
+
};
|
|
11511
|
+
}
|
|
11512
|
+
if (transaction?.serialize && typeof transaction.serialize === "function") {
|
|
11513
|
+
const serialized = transaction.serialize();
|
|
11514
|
+
const hex = serialized.startsWith("0x") ? serialized : "0x" + serialized;
|
|
11515
|
+
return {
|
|
11516
|
+
parsed: hex,
|
|
11517
|
+
originalFormat: "ethers"
|
|
11518
|
+
};
|
|
11519
|
+
}
|
|
11520
|
+
if (transaction instanceof Uint8Array) {
|
|
11521
|
+
const hex = "0x" + index.bufferExports.Buffer.from(transaction).toString("hex");
|
|
11522
|
+
return {
|
|
11523
|
+
parsed: hex,
|
|
11524
|
+
originalFormat: "bytes"
|
|
11525
|
+
};
|
|
11526
|
+
}
|
|
11527
|
+
if (transaction && typeof transaction === "object" && (transaction.to || transaction.data || transaction.from)) {
|
|
11528
|
+
try {
|
|
11529
|
+
const { from, gas, ...txForSerialization } = transaction;
|
|
11530
|
+
if (gas) {
|
|
11531
|
+
txForSerialization.gasLimit = gas;
|
|
11532
|
+
}
|
|
11533
|
+
if (!txForSerialization.gasLimit) {
|
|
11534
|
+
if (txForSerialization.to && txForSerialization.value && !txForSerialization.data) {
|
|
11535
|
+
txForSerialization.gasLimit = "0x5208";
|
|
11536
|
+
}
|
|
11537
|
+
}
|
|
11538
|
+
if (txForSerialization.to && typeof txForSerialization.to === "string") {
|
|
11539
|
+
try {
|
|
11540
|
+
txForSerialization.to = getAddress(txForSerialization.to);
|
|
11541
|
+
} catch {
|
|
11542
|
+
txForSerialization.to = txForSerialization.to.toLowerCase();
|
|
8795
11543
|
}
|
|
8796
|
-
|
|
11544
|
+
}
|
|
11545
|
+
const serialized = Transaction.from(txForSerialization).unsignedSerialized;
|
|
11546
|
+
const hex = serialized.startsWith("0x") ? serialized : "0x" + serialized;
|
|
11547
|
+
return {
|
|
11548
|
+
parsed: hex,
|
|
11549
|
+
originalFormat: "json"
|
|
11550
|
+
};
|
|
11551
|
+
} catch (error) {
|
|
11552
|
+
const errorMessage = error instanceof Error ? error.message : "Unknown error";
|
|
11553
|
+
const txKeys = transaction ? Object.keys(transaction).join(", ") : "N/A";
|
|
11554
|
+
const txValues = transaction ? JSON.stringify(transaction, null, 2) : "N/A";
|
|
11555
|
+
throw new Error(
|
|
11556
|
+
`Failed to RLP encode EVM transaction: ${errorMessage}.
|
|
11557
|
+
Transaction keys: [${txKeys}].
|
|
11558
|
+
Transaction: ${txValues}
|
|
11559
|
+
Please ensure the transaction object includes required fields (to, value, chainId, gasLimit or gasPrice, etc.)`
|
|
11560
|
+
);
|
|
11561
|
+
}
|
|
11562
|
+
}
|
|
11563
|
+
throw new Error(
|
|
11564
|
+
"Unsupported EVM transaction format. Expected hex string, bytes, or transaction object with 'to', 'data', or 'from' fields."
|
|
11565
|
+
);
|
|
11566
|
+
}
|
|
11567
|
+
async function parseSuiTransactionToBase64Url(transaction) {
|
|
11568
|
+
if (transaction?.serialize && typeof transaction.serialize === "function") {
|
|
11569
|
+
const serialized = transaction.serialize();
|
|
11570
|
+
return {
|
|
11571
|
+
parsed: base64urlEncode(serialized),
|
|
11572
|
+
originalFormat: "sui-sdk"
|
|
11573
|
+
};
|
|
11574
|
+
}
|
|
11575
|
+
if (transaction instanceof Uint8Array) {
|
|
11576
|
+
return {
|
|
11577
|
+
parsed: base64urlEncode(transaction),
|
|
11578
|
+
originalFormat: "bytes"
|
|
11579
|
+
};
|
|
11580
|
+
}
|
|
11581
|
+
if (transaction?.build && typeof transaction.build === "function") {
|
|
11582
|
+
const built = await transaction.build();
|
|
11583
|
+
if (built?.serialize && typeof built.serialize === "function") {
|
|
11584
|
+
const serialized = built.serialize();
|
|
11585
|
+
return {
|
|
11586
|
+
parsed: base64urlEncode(serialized),
|
|
11587
|
+
originalFormat: "transaction-block"
|
|
11588
|
+
};
|
|
11589
|
+
}
|
|
11590
|
+
}
|
|
11591
|
+
throw new Error("Unsupported Sui transaction format");
|
|
11592
|
+
}
|
|
11593
|
+
function parseBitcoinTransactionToBase64Url(transaction) {
|
|
11594
|
+
if (transaction?.toBuffer && typeof transaction.toBuffer === "function") {
|
|
11595
|
+
const buffer = transaction.toBuffer();
|
|
11596
|
+
return {
|
|
11597
|
+
parsed: base64urlEncode(new Uint8Array(buffer)),
|
|
11598
|
+
originalFormat: "bitcoinjs-lib"
|
|
11599
|
+
};
|
|
11600
|
+
}
|
|
11601
|
+
if (transaction instanceof Uint8Array) {
|
|
11602
|
+
return {
|
|
11603
|
+
parsed: base64urlEncode(transaction),
|
|
11604
|
+
originalFormat: "bytes"
|
|
11605
|
+
};
|
|
11606
|
+
}
|
|
11607
|
+
if (typeof transaction === "string") {
|
|
11608
|
+
const bytes = new Uint8Array(index.bufferExports.Buffer.from(transaction, "hex"));
|
|
11609
|
+
return {
|
|
11610
|
+
parsed: base64urlEncode(bytes),
|
|
11611
|
+
originalFormat: "hex"
|
|
11612
|
+
};
|
|
11613
|
+
}
|
|
11614
|
+
throw new Error("Unsupported Bitcoin transaction format");
|
|
11615
|
+
}
|
|
11616
|
+
|
|
11617
|
+
// base-x encoding / decoding
|
|
11618
|
+
// Copyright (c) 2018 base-x contributors
|
|
11619
|
+
// Copyright (c) 2014-2018 The Bitcoin Core developers (base58.cpp)
|
|
11620
|
+
// Distributed under the MIT software license, see the accompanying
|
|
11621
|
+
// file LICENSE or http://www.opensource.org/licenses/mit-license.php.
|
|
11622
|
+
function base$2 (ALPHABET) {
|
|
11623
|
+
if (ALPHABET.length >= 255) { throw new TypeError('Alphabet too long') }
|
|
11624
|
+
const BASE_MAP = new Uint8Array(256);
|
|
11625
|
+
for (let j = 0; j < BASE_MAP.length; j++) {
|
|
11626
|
+
BASE_MAP[j] = 255;
|
|
11627
|
+
}
|
|
11628
|
+
for (let i = 0; i < ALPHABET.length; i++) {
|
|
11629
|
+
const x = ALPHABET.charAt(i);
|
|
11630
|
+
const xc = x.charCodeAt(0);
|
|
11631
|
+
if (BASE_MAP[xc] !== 255) { throw new TypeError(x + ' is ambiguous') }
|
|
11632
|
+
BASE_MAP[xc] = i;
|
|
11633
|
+
}
|
|
11634
|
+
const BASE = ALPHABET.length;
|
|
11635
|
+
const LEADER = ALPHABET.charAt(0);
|
|
11636
|
+
const FACTOR = Math.log(BASE) / Math.log(256); // log(BASE) / log(256), rounded up
|
|
11637
|
+
const iFACTOR = Math.log(256) / Math.log(BASE); // log(256) / log(BASE), rounded up
|
|
11638
|
+
function encode (source) {
|
|
11639
|
+
// eslint-disable-next-line no-empty
|
|
11640
|
+
if (source instanceof Uint8Array) ; else if (ArrayBuffer.isView(source)) {
|
|
11641
|
+
source = new Uint8Array(source.buffer, source.byteOffset, source.byteLength);
|
|
11642
|
+
} else if (Array.isArray(source)) {
|
|
11643
|
+
source = Uint8Array.from(source);
|
|
11644
|
+
}
|
|
11645
|
+
if (!(source instanceof Uint8Array)) { throw new TypeError('Expected Uint8Array') }
|
|
11646
|
+
if (source.length === 0) { return '' }
|
|
11647
|
+
// Skip & count leading zeroes.
|
|
11648
|
+
let zeroes = 0;
|
|
11649
|
+
let length = 0;
|
|
11650
|
+
let pbegin = 0;
|
|
11651
|
+
const pend = source.length;
|
|
11652
|
+
while (pbegin !== pend && source[pbegin] === 0) {
|
|
11653
|
+
pbegin++;
|
|
11654
|
+
zeroes++;
|
|
11655
|
+
}
|
|
11656
|
+
// Allocate enough space in big-endian base58 representation.
|
|
11657
|
+
const size = ((pend - pbegin) * iFACTOR + 1) >>> 0;
|
|
11658
|
+
const b58 = new Uint8Array(size);
|
|
11659
|
+
// Process the bytes.
|
|
11660
|
+
while (pbegin !== pend) {
|
|
11661
|
+
let carry = source[pbegin];
|
|
11662
|
+
// Apply "b58 = b58 * 256 + ch".
|
|
11663
|
+
let i = 0;
|
|
11664
|
+
for (let it1 = size - 1; (carry !== 0 || i < length) && (it1 !== -1); it1--, i++) {
|
|
11665
|
+
carry += (256 * b58[it1]) >>> 0;
|
|
11666
|
+
b58[it1] = (carry % BASE) >>> 0;
|
|
11667
|
+
carry = (carry / BASE) >>> 0;
|
|
11668
|
+
}
|
|
11669
|
+
if (carry !== 0) { throw new Error('Non-zero carry') }
|
|
11670
|
+
length = i;
|
|
11671
|
+
pbegin++;
|
|
11672
|
+
}
|
|
11673
|
+
// Skip leading zeroes in base58 result.
|
|
11674
|
+
let it2 = size - length;
|
|
11675
|
+
while (it2 !== size && b58[it2] === 0) {
|
|
11676
|
+
it2++;
|
|
11677
|
+
}
|
|
11678
|
+
// Translate the result into a string.
|
|
11679
|
+
let str = LEADER.repeat(zeroes);
|
|
11680
|
+
for (; it2 < size; ++it2) { str += ALPHABET.charAt(b58[it2]); }
|
|
11681
|
+
return str
|
|
11682
|
+
}
|
|
11683
|
+
function decodeUnsafe (source) {
|
|
11684
|
+
if (typeof source !== 'string') { throw new TypeError('Expected String') }
|
|
11685
|
+
if (source.length === 0) { return new Uint8Array() }
|
|
11686
|
+
let psz = 0;
|
|
11687
|
+
// Skip and count leading '1's.
|
|
11688
|
+
let zeroes = 0;
|
|
11689
|
+
let length = 0;
|
|
11690
|
+
while (source[psz] === LEADER) {
|
|
11691
|
+
zeroes++;
|
|
11692
|
+
psz++;
|
|
11693
|
+
}
|
|
11694
|
+
// Allocate enough space in big-endian base256 representation.
|
|
11695
|
+
const size = (((source.length - psz) * FACTOR) + 1) >>> 0; // log(58) / log(256), rounded up.
|
|
11696
|
+
const b256 = new Uint8Array(size);
|
|
11697
|
+
// Process the characters.
|
|
11698
|
+
while (psz < source.length) {
|
|
11699
|
+
// Find code of next character
|
|
11700
|
+
const charCode = source.charCodeAt(psz);
|
|
11701
|
+
// Base map can not be indexed using char code
|
|
11702
|
+
if (charCode > 255) { return }
|
|
11703
|
+
// Decode character
|
|
11704
|
+
let carry = BASE_MAP[charCode];
|
|
11705
|
+
// Invalid character
|
|
11706
|
+
if (carry === 255) { return }
|
|
11707
|
+
let i = 0;
|
|
11708
|
+
for (let it3 = size - 1; (carry !== 0 || i < length) && (it3 !== -1); it3--, i++) {
|
|
11709
|
+
carry += (BASE * b256[it3]) >>> 0;
|
|
11710
|
+
b256[it3] = (carry % 256) >>> 0;
|
|
11711
|
+
carry = (carry / 256) >>> 0;
|
|
11712
|
+
}
|
|
11713
|
+
if (carry !== 0) { throw new Error('Non-zero carry') }
|
|
11714
|
+
length = i;
|
|
11715
|
+
psz++;
|
|
11716
|
+
}
|
|
11717
|
+
// Skip leading zeroes in b256.
|
|
11718
|
+
let it4 = size - length;
|
|
11719
|
+
while (it4 !== size && b256[it4] === 0) {
|
|
11720
|
+
it4++;
|
|
11721
|
+
}
|
|
11722
|
+
const vch = new Uint8Array(zeroes + (size - it4));
|
|
11723
|
+
let j = zeroes;
|
|
11724
|
+
while (it4 !== size) {
|
|
11725
|
+
vch[j++] = b256[it4++];
|
|
11726
|
+
}
|
|
11727
|
+
return vch
|
|
11728
|
+
}
|
|
11729
|
+
function decode (string) {
|
|
11730
|
+
const buffer = decodeUnsafe(string);
|
|
11731
|
+
if (buffer) { return buffer }
|
|
11732
|
+
throw new Error('Non-base' + BASE + ' character')
|
|
11733
|
+
}
|
|
11734
|
+
return {
|
|
11735
|
+
encode,
|
|
11736
|
+
decodeUnsafe,
|
|
11737
|
+
decode
|
|
11738
|
+
}
|
|
11739
|
+
}
|
|
11740
|
+
|
|
11741
|
+
var ALPHABET$2 = '123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz';
|
|
11742
|
+
var bs58$1 = base$2(ALPHABET$2);
|
|
11743
|
+
|
|
11744
|
+
// base-x encoding / decoding
|
|
11745
|
+
// Copyright (c) 2018 base-x contributors
|
|
11746
|
+
// Copyright (c) 2014-2018 The Bitcoin Core developers (base58.cpp)
|
|
11747
|
+
// Distributed under the MIT software license, see the accompanying
|
|
11748
|
+
// file LICENSE or http://www.opensource.org/licenses/mit-license.php.
|
|
11749
|
+
function base$1 (ALPHABET) {
|
|
11750
|
+
if (ALPHABET.length >= 255) { throw new TypeError('Alphabet too long') }
|
|
11751
|
+
const BASE_MAP = new Uint8Array(256);
|
|
11752
|
+
for (let j = 0; j < BASE_MAP.length; j++) {
|
|
11753
|
+
BASE_MAP[j] = 255;
|
|
11754
|
+
}
|
|
11755
|
+
for (let i = 0; i < ALPHABET.length; i++) {
|
|
11756
|
+
const x = ALPHABET.charAt(i);
|
|
11757
|
+
const xc = x.charCodeAt(0);
|
|
11758
|
+
if (BASE_MAP[xc] !== 255) { throw new TypeError(x + ' is ambiguous') }
|
|
11759
|
+
BASE_MAP[xc] = i;
|
|
11760
|
+
}
|
|
11761
|
+
const BASE = ALPHABET.length;
|
|
11762
|
+
const LEADER = ALPHABET.charAt(0);
|
|
11763
|
+
const FACTOR = Math.log(BASE) / Math.log(256); // log(BASE) / log(256), rounded up
|
|
11764
|
+
const iFACTOR = Math.log(256) / Math.log(BASE); // log(256) / log(BASE), rounded up
|
|
11765
|
+
function encode (source) {
|
|
11766
|
+
// eslint-disable-next-line no-empty
|
|
11767
|
+
if (source instanceof Uint8Array) ; else if (ArrayBuffer.isView(source)) {
|
|
11768
|
+
source = new Uint8Array(source.buffer, source.byteOffset, source.byteLength);
|
|
11769
|
+
} else if (Array.isArray(source)) {
|
|
11770
|
+
source = Uint8Array.from(source);
|
|
11771
|
+
}
|
|
11772
|
+
if (!(source instanceof Uint8Array)) { throw new TypeError('Expected Uint8Array') }
|
|
11773
|
+
if (source.length === 0) { return '' }
|
|
11774
|
+
// Skip & count leading zeroes.
|
|
11775
|
+
let zeroes = 0;
|
|
11776
|
+
let length = 0;
|
|
11777
|
+
let pbegin = 0;
|
|
11778
|
+
const pend = source.length;
|
|
11779
|
+
while (pbegin !== pend && source[pbegin] === 0) {
|
|
11780
|
+
pbegin++;
|
|
11781
|
+
zeroes++;
|
|
11782
|
+
}
|
|
11783
|
+
// Allocate enough space in big-endian base58 representation.
|
|
11784
|
+
const size = ((pend - pbegin) * iFACTOR + 1) >>> 0;
|
|
11785
|
+
const b58 = new Uint8Array(size);
|
|
11786
|
+
// Process the bytes.
|
|
11787
|
+
while (pbegin !== pend) {
|
|
11788
|
+
let carry = source[pbegin];
|
|
11789
|
+
// Apply "b58 = b58 * 256 + ch".
|
|
11790
|
+
let i = 0;
|
|
11791
|
+
for (let it1 = size - 1; (carry !== 0 || i < length) && (it1 !== -1); it1--, i++) {
|
|
11792
|
+
carry += (256 * b58[it1]) >>> 0;
|
|
11793
|
+
b58[it1] = (carry % BASE) >>> 0;
|
|
11794
|
+
carry = (carry / BASE) >>> 0;
|
|
11795
|
+
}
|
|
11796
|
+
if (carry !== 0) { throw new Error('Non-zero carry') }
|
|
11797
|
+
length = i;
|
|
11798
|
+
pbegin++;
|
|
11799
|
+
}
|
|
11800
|
+
// Skip leading zeroes in base58 result.
|
|
11801
|
+
let it2 = size - length;
|
|
11802
|
+
while (it2 !== size && b58[it2] === 0) {
|
|
11803
|
+
it2++;
|
|
11804
|
+
}
|
|
11805
|
+
// Translate the result into a string.
|
|
11806
|
+
let str = LEADER.repeat(zeroes);
|
|
11807
|
+
for (; it2 < size; ++it2) { str += ALPHABET.charAt(b58[it2]); }
|
|
11808
|
+
return str
|
|
11809
|
+
}
|
|
11810
|
+
function decodeUnsafe (source) {
|
|
11811
|
+
if (typeof source !== 'string') { throw new TypeError('Expected String') }
|
|
11812
|
+
if (source.length === 0) { return new Uint8Array() }
|
|
11813
|
+
let psz = 0;
|
|
11814
|
+
// Skip and count leading '1's.
|
|
11815
|
+
let zeroes = 0;
|
|
11816
|
+
let length = 0;
|
|
11817
|
+
while (source[psz] === LEADER) {
|
|
11818
|
+
zeroes++;
|
|
11819
|
+
psz++;
|
|
11820
|
+
}
|
|
11821
|
+
// Allocate enough space in big-endian base256 representation.
|
|
11822
|
+
const size = (((source.length - psz) * FACTOR) + 1) >>> 0; // log(58) / log(256), rounded up.
|
|
11823
|
+
const b256 = new Uint8Array(size);
|
|
11824
|
+
// Process the characters.
|
|
11825
|
+
while (psz < source.length) {
|
|
11826
|
+
// Find code of next character
|
|
11827
|
+
const charCode = source.charCodeAt(psz);
|
|
11828
|
+
// Base map can not be indexed using char code
|
|
11829
|
+
if (charCode > 255) { return }
|
|
11830
|
+
// Decode character
|
|
11831
|
+
let carry = BASE_MAP[charCode];
|
|
11832
|
+
// Invalid character
|
|
11833
|
+
if (carry === 255) { return }
|
|
11834
|
+
let i = 0;
|
|
11835
|
+
for (let it3 = size - 1; (carry !== 0 || i < length) && (it3 !== -1); it3--, i++) {
|
|
11836
|
+
carry += (BASE * b256[it3]) >>> 0;
|
|
11837
|
+
b256[it3] = (carry % 256) >>> 0;
|
|
11838
|
+
carry = (carry / 256) >>> 0;
|
|
11839
|
+
}
|
|
11840
|
+
if (carry !== 0) { throw new Error('Non-zero carry') }
|
|
11841
|
+
length = i;
|
|
11842
|
+
psz++;
|
|
11843
|
+
}
|
|
11844
|
+
// Skip leading zeroes in b256.
|
|
11845
|
+
let it4 = size - length;
|
|
11846
|
+
while (it4 !== size && b256[it4] === 0) {
|
|
11847
|
+
it4++;
|
|
8797
11848
|
}
|
|
11849
|
+
const vch = new Uint8Array(zeroes + (size - it4));
|
|
11850
|
+
let j = zeroes;
|
|
11851
|
+
while (it4 !== size) {
|
|
11852
|
+
vch[j++] = b256[it4++];
|
|
11853
|
+
}
|
|
11854
|
+
return vch
|
|
11855
|
+
}
|
|
11856
|
+
function decode (string) {
|
|
11857
|
+
const buffer = decodeUnsafe(string);
|
|
11858
|
+
if (buffer) { return buffer }
|
|
11859
|
+
throw new Error('Non-base' + BASE + ' character')
|
|
11860
|
+
}
|
|
11861
|
+
return {
|
|
11862
|
+
encode,
|
|
11863
|
+
decodeUnsafe,
|
|
11864
|
+
decode
|
|
11865
|
+
}
|
|
8798
11866
|
}
|
|
8799
11867
|
|
|
8800
|
-
|
|
8801
|
-
|
|
8802
|
-
|
|
8803
|
-
|
|
8804
|
-
|
|
8805
|
-
|
|
8806
|
-
|
|
8807
|
-
|
|
8808
|
-
|
|
8809
|
-
|
|
8810
|
-
|
|
8811
|
-
|
|
8812
|
-
|
|
8813
|
-
|
|
8814
|
-
|
|
8815
|
-
|
|
8816
|
-
|
|
8817
|
-
|
|
8818
|
-
|
|
8819
|
-
|
|
8820
|
-
|
|
8821
|
-
|
|
8822
|
-
|
|
8823
|
-
|
|
8824
|
-
|
|
8825
|
-
|
|
8826
|
-
|
|
8827
|
-
|
|
8828
|
-
|
|
8829
|
-
|
|
8830
|
-
|
|
8831
|
-
|
|
8832
|
-
|
|
8833
|
-
|
|
8834
|
-
|
|
8835
|
-
|
|
8836
|
-
|
|
8837
|
-
|
|
8838
|
-
|
|
8839
|
-
|
|
8840
|
-
|
|
8841
|
-
|
|
8842
|
-
|
|
8843
|
-
|
|
8844
|
-
|
|
8845
|
-
|
|
8846
|
-
|
|
8847
|
-
|
|
8848
|
-
|
|
8849
|
-
|
|
8850
|
-
|
|
8851
|
-
|
|
8852
|
-
|
|
8853
|
-
|
|
8854
|
-
|
|
8855
|
-
|
|
8856
|
-
|
|
8857
|
-
|
|
8858
|
-
|
|
8859
|
-
|
|
8860
|
-
|
|
8861
|
-
|
|
8862
|
-
|
|
8863
|
-
|
|
8864
|
-
|
|
8865
|
-
|
|
8866
|
-
|
|
8867
|
-
|
|
8868
|
-
|
|
8869
|
-
|
|
8870
|
-
|
|
8871
|
-
|
|
8872
|
-
|
|
8873
|
-
|
|
8874
|
-
|
|
8875
|
-
|
|
8876
|
-
|
|
8877
|
-
|
|
8878
|
-
|
|
8879
|
-
|
|
8880
|
-
}
|
|
8881
|
-
|
|
8882
|
-
|
|
8883
|
-
|
|
8884
|
-
|
|
8885
|
-
|
|
8886
|
-
|
|
8887
|
-
|
|
8888
|
-
|
|
8889
|
-
|
|
8890
|
-
|
|
8891
|
-
|
|
8892
|
-
|
|
8893
|
-
|
|
8894
|
-
|
|
8895
|
-
|
|
8896
|
-
|
|
8897
|
-
|
|
8898
|
-
|
|
8899
|
-
|
|
8900
|
-
|
|
8901
|
-
|
|
8902
|
-
|
|
8903
|
-
|
|
8904
|
-
|
|
8905
|
-
|
|
8906
|
-
|
|
8907
|
-
|
|
8908
|
-
|
|
8909
|
-
|
|
8910
|
-
|
|
8911
|
-
|
|
8912
|
-
|
|
8913
|
-
|
|
8914
|
-
|
|
8915
|
-
|
|
11868
|
+
var ALPHABET$1 = '123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz';
|
|
11869
|
+
var bs582 = base$1(ALPHABET$1);
|
|
11870
|
+
|
|
11871
|
+
var eventemitter3 = {exports: {}};
|
|
11872
|
+
|
|
11873
|
+
var hasRequiredEventemitter3;
|
|
11874
|
+
|
|
11875
|
+
function requireEventemitter3 () {
|
|
11876
|
+
if (hasRequiredEventemitter3) return eventemitter3.exports;
|
|
11877
|
+
hasRequiredEventemitter3 = 1;
|
|
11878
|
+
(function (module) {
|
|
11879
|
+
|
|
11880
|
+
var has = Object.prototype.hasOwnProperty
|
|
11881
|
+
, prefix = '~';
|
|
11882
|
+
|
|
11883
|
+
/**
|
|
11884
|
+
* Constructor to create a storage for our `EE` objects.
|
|
11885
|
+
* An `Events` instance is a plain object whose properties are event names.
|
|
11886
|
+
*
|
|
11887
|
+
* @constructor
|
|
11888
|
+
* @private
|
|
11889
|
+
*/
|
|
11890
|
+
function Events() {}
|
|
11891
|
+
|
|
11892
|
+
//
|
|
11893
|
+
// We try to not inherit from `Object.prototype`. In some engines creating an
|
|
11894
|
+
// instance in this way is faster than calling `Object.create(null)` directly.
|
|
11895
|
+
// If `Object.create(null)` is not supported we prefix the event names with a
|
|
11896
|
+
// character to make sure that the built-in object properties are not
|
|
11897
|
+
// overridden or used as an attack vector.
|
|
11898
|
+
//
|
|
11899
|
+
if (Object.create) {
|
|
11900
|
+
Events.prototype = Object.create(null);
|
|
11901
|
+
|
|
11902
|
+
//
|
|
11903
|
+
// This hack is needed because the `__proto__` property is still inherited in
|
|
11904
|
+
// some old browsers like Android 4, iPhone 5.1, Opera 11 and Safari 5.
|
|
11905
|
+
//
|
|
11906
|
+
if (!new Events().__proto__) prefix = false;
|
|
11907
|
+
}
|
|
11908
|
+
|
|
11909
|
+
/**
|
|
11910
|
+
* Representation of a single event listener.
|
|
11911
|
+
*
|
|
11912
|
+
* @param {Function} fn The listener function.
|
|
11913
|
+
* @param {*} context The context to invoke the listener with.
|
|
11914
|
+
* @param {Boolean} [once=false] Specify if the listener is a one-time listener.
|
|
11915
|
+
* @constructor
|
|
11916
|
+
* @private
|
|
11917
|
+
*/
|
|
11918
|
+
function EE(fn, context, once) {
|
|
11919
|
+
this.fn = fn;
|
|
11920
|
+
this.context = context;
|
|
11921
|
+
this.once = once || false;
|
|
11922
|
+
}
|
|
11923
|
+
|
|
11924
|
+
/**
|
|
11925
|
+
* Add a listener for a given event.
|
|
11926
|
+
*
|
|
11927
|
+
* @param {EventEmitter} emitter Reference to the `EventEmitter` instance.
|
|
11928
|
+
* @param {(String|Symbol)} event The event name.
|
|
11929
|
+
* @param {Function} fn The listener function.
|
|
11930
|
+
* @param {*} context The context to invoke the listener with.
|
|
11931
|
+
* @param {Boolean} once Specify if the listener is a one-time listener.
|
|
11932
|
+
* @returns {EventEmitter}
|
|
11933
|
+
* @private
|
|
11934
|
+
*/
|
|
11935
|
+
function addListener(emitter, event, fn, context, once) {
|
|
11936
|
+
if (typeof fn !== 'function') {
|
|
11937
|
+
throw new TypeError('The listener must be a function');
|
|
11938
|
+
}
|
|
11939
|
+
|
|
11940
|
+
var listener = new EE(fn, context || emitter, once)
|
|
11941
|
+
, evt = prefix ? prefix + event : event;
|
|
11942
|
+
|
|
11943
|
+
if (!emitter._events[evt]) emitter._events[evt] = listener, emitter._eventsCount++;
|
|
11944
|
+
else if (!emitter._events[evt].fn) emitter._events[evt].push(listener);
|
|
11945
|
+
else emitter._events[evt] = [emitter._events[evt], listener];
|
|
11946
|
+
|
|
11947
|
+
return emitter;
|
|
11948
|
+
}
|
|
11949
|
+
|
|
11950
|
+
/**
|
|
11951
|
+
* Clear event by name.
|
|
11952
|
+
*
|
|
11953
|
+
* @param {EventEmitter} emitter Reference to the `EventEmitter` instance.
|
|
11954
|
+
* @param {(String|Symbol)} evt The Event name.
|
|
11955
|
+
* @private
|
|
11956
|
+
*/
|
|
11957
|
+
function clearEvent(emitter, evt) {
|
|
11958
|
+
if (--emitter._eventsCount === 0) emitter._events = new Events();
|
|
11959
|
+
else delete emitter._events[evt];
|
|
11960
|
+
}
|
|
11961
|
+
|
|
11962
|
+
/**
|
|
11963
|
+
* Minimal `EventEmitter` interface that is molded against the Node.js
|
|
11964
|
+
* `EventEmitter` interface.
|
|
11965
|
+
*
|
|
11966
|
+
* @constructor
|
|
11967
|
+
* @public
|
|
11968
|
+
*/
|
|
11969
|
+
function EventEmitter() {
|
|
11970
|
+
this._events = new Events();
|
|
11971
|
+
this._eventsCount = 0;
|
|
11972
|
+
}
|
|
11973
|
+
|
|
11974
|
+
/**
|
|
11975
|
+
* Return an array listing the events for which the emitter has registered
|
|
11976
|
+
* listeners.
|
|
11977
|
+
*
|
|
11978
|
+
* @returns {Array}
|
|
11979
|
+
* @public
|
|
11980
|
+
*/
|
|
11981
|
+
EventEmitter.prototype.eventNames = function eventNames() {
|
|
11982
|
+
var names = []
|
|
11983
|
+
, events
|
|
11984
|
+
, name;
|
|
11985
|
+
|
|
11986
|
+
if (this._eventsCount === 0) return names;
|
|
11987
|
+
|
|
11988
|
+
for (name in (events = this._events)) {
|
|
11989
|
+
if (has.call(events, name)) names.push(prefix ? name.slice(1) : name);
|
|
11990
|
+
}
|
|
11991
|
+
|
|
11992
|
+
if (Object.getOwnPropertySymbols) {
|
|
11993
|
+
return names.concat(Object.getOwnPropertySymbols(events));
|
|
11994
|
+
}
|
|
11995
|
+
|
|
11996
|
+
return names;
|
|
11997
|
+
};
|
|
11998
|
+
|
|
11999
|
+
/**
|
|
12000
|
+
* Return the listeners registered for a given event.
|
|
12001
|
+
*
|
|
12002
|
+
* @param {(String|Symbol)} event The event name.
|
|
12003
|
+
* @returns {Array} The registered listeners.
|
|
12004
|
+
* @public
|
|
12005
|
+
*/
|
|
12006
|
+
EventEmitter.prototype.listeners = function listeners(event) {
|
|
12007
|
+
var evt = prefix ? prefix + event : event
|
|
12008
|
+
, handlers = this._events[evt];
|
|
12009
|
+
|
|
12010
|
+
if (!handlers) return [];
|
|
12011
|
+
if (handlers.fn) return [handlers.fn];
|
|
12012
|
+
|
|
12013
|
+
for (var i = 0, l = handlers.length, ee = new Array(l); i < l; i++) {
|
|
12014
|
+
ee[i] = handlers[i].fn;
|
|
12015
|
+
}
|
|
12016
|
+
|
|
12017
|
+
return ee;
|
|
12018
|
+
};
|
|
12019
|
+
|
|
12020
|
+
/**
|
|
12021
|
+
* Return the number of listeners listening to a given event.
|
|
12022
|
+
*
|
|
12023
|
+
* @param {(String|Symbol)} event The event name.
|
|
12024
|
+
* @returns {Number} The number of listeners.
|
|
12025
|
+
* @public
|
|
12026
|
+
*/
|
|
12027
|
+
EventEmitter.prototype.listenerCount = function listenerCount(event) {
|
|
12028
|
+
var evt = prefix ? prefix + event : event
|
|
12029
|
+
, listeners = this._events[evt];
|
|
12030
|
+
|
|
12031
|
+
if (!listeners) return 0;
|
|
12032
|
+
if (listeners.fn) return 1;
|
|
12033
|
+
return listeners.length;
|
|
12034
|
+
};
|
|
12035
|
+
|
|
12036
|
+
/**
|
|
12037
|
+
* Calls each of the listeners registered for a given event.
|
|
12038
|
+
*
|
|
12039
|
+
* @param {(String|Symbol)} event The event name.
|
|
12040
|
+
* @returns {Boolean} `true` if the event had listeners, else `false`.
|
|
12041
|
+
* @public
|
|
12042
|
+
*/
|
|
12043
|
+
EventEmitter.prototype.emit = function emit(event, a1, a2, a3, a4, a5) {
|
|
12044
|
+
var evt = prefix ? prefix + event : event;
|
|
12045
|
+
|
|
12046
|
+
if (!this._events[evt]) return false;
|
|
12047
|
+
|
|
12048
|
+
var listeners = this._events[evt]
|
|
12049
|
+
, len = arguments.length
|
|
12050
|
+
, args
|
|
12051
|
+
, i;
|
|
12052
|
+
|
|
12053
|
+
if (listeners.fn) {
|
|
12054
|
+
if (listeners.once) this.removeListener(event, listeners.fn, undefined, true);
|
|
12055
|
+
|
|
12056
|
+
switch (len) {
|
|
12057
|
+
case 1: return listeners.fn.call(listeners.context), true;
|
|
12058
|
+
case 2: return listeners.fn.call(listeners.context, a1), true;
|
|
12059
|
+
case 3: return listeners.fn.call(listeners.context, a1, a2), true;
|
|
12060
|
+
case 4: return listeners.fn.call(listeners.context, a1, a2, a3), true;
|
|
12061
|
+
case 5: return listeners.fn.call(listeners.context, a1, a2, a3, a4), true;
|
|
12062
|
+
case 6: return listeners.fn.call(listeners.context, a1, a2, a3, a4, a5), true;
|
|
12063
|
+
}
|
|
12064
|
+
|
|
12065
|
+
for (i = 1, args = new Array(len -1); i < len; i++) {
|
|
12066
|
+
args[i - 1] = arguments[i];
|
|
12067
|
+
}
|
|
12068
|
+
|
|
12069
|
+
listeners.fn.apply(listeners.context, args);
|
|
12070
|
+
} else {
|
|
12071
|
+
var length = listeners.length
|
|
12072
|
+
, j;
|
|
12073
|
+
|
|
12074
|
+
for (i = 0; i < length; i++) {
|
|
12075
|
+
if (listeners[i].once) this.removeListener(event, listeners[i].fn, undefined, true);
|
|
12076
|
+
|
|
12077
|
+
switch (len) {
|
|
12078
|
+
case 1: listeners[i].fn.call(listeners[i].context); break;
|
|
12079
|
+
case 2: listeners[i].fn.call(listeners[i].context, a1); break;
|
|
12080
|
+
case 3: listeners[i].fn.call(listeners[i].context, a1, a2); break;
|
|
12081
|
+
case 4: listeners[i].fn.call(listeners[i].context, a1, a2, a3); break;
|
|
12082
|
+
default:
|
|
12083
|
+
if (!args) for (j = 1, args = new Array(len -1); j < len; j++) {
|
|
12084
|
+
args[j - 1] = arguments[j];
|
|
12085
|
+
}
|
|
12086
|
+
|
|
12087
|
+
listeners[i].fn.apply(listeners[i].context, args);
|
|
12088
|
+
}
|
|
12089
|
+
}
|
|
12090
|
+
}
|
|
12091
|
+
|
|
12092
|
+
return true;
|
|
12093
|
+
};
|
|
12094
|
+
|
|
12095
|
+
/**
|
|
12096
|
+
* Add a listener for a given event.
|
|
12097
|
+
*
|
|
12098
|
+
* @param {(String|Symbol)} event The event name.
|
|
12099
|
+
* @param {Function} fn The listener function.
|
|
12100
|
+
* @param {*} [context=this] The context to invoke the listener with.
|
|
12101
|
+
* @returns {EventEmitter} `this`.
|
|
12102
|
+
* @public
|
|
12103
|
+
*/
|
|
12104
|
+
EventEmitter.prototype.on = function on(event, fn, context) {
|
|
12105
|
+
return addListener(this, event, fn, context, false);
|
|
12106
|
+
};
|
|
12107
|
+
|
|
12108
|
+
/**
|
|
12109
|
+
* Add a one-time listener for a given event.
|
|
12110
|
+
*
|
|
12111
|
+
* @param {(String|Symbol)} event The event name.
|
|
12112
|
+
* @param {Function} fn The listener function.
|
|
12113
|
+
* @param {*} [context=this] The context to invoke the listener with.
|
|
12114
|
+
* @returns {EventEmitter} `this`.
|
|
12115
|
+
* @public
|
|
12116
|
+
*/
|
|
12117
|
+
EventEmitter.prototype.once = function once(event, fn, context) {
|
|
12118
|
+
return addListener(this, event, fn, context, true);
|
|
12119
|
+
};
|
|
12120
|
+
|
|
12121
|
+
/**
|
|
12122
|
+
* Remove the listeners of a given event.
|
|
12123
|
+
*
|
|
12124
|
+
* @param {(String|Symbol)} event The event name.
|
|
12125
|
+
* @param {Function} fn Only remove the listeners that match this function.
|
|
12126
|
+
* @param {*} context Only remove the listeners that have this context.
|
|
12127
|
+
* @param {Boolean} once Only remove one-time listeners.
|
|
12128
|
+
* @returns {EventEmitter} `this`.
|
|
12129
|
+
* @public
|
|
12130
|
+
*/
|
|
12131
|
+
EventEmitter.prototype.removeListener = function removeListener(event, fn, context, once) {
|
|
12132
|
+
var evt = prefix ? prefix + event : event;
|
|
12133
|
+
|
|
12134
|
+
if (!this._events[evt]) return this;
|
|
12135
|
+
if (!fn) {
|
|
12136
|
+
clearEvent(this, evt);
|
|
12137
|
+
return this;
|
|
12138
|
+
}
|
|
12139
|
+
|
|
12140
|
+
var listeners = this._events[evt];
|
|
12141
|
+
|
|
12142
|
+
if (listeners.fn) {
|
|
12143
|
+
if (
|
|
12144
|
+
listeners.fn === fn &&
|
|
12145
|
+
(!once || listeners.once) &&
|
|
12146
|
+
(!context || listeners.context === context)
|
|
12147
|
+
) {
|
|
12148
|
+
clearEvent(this, evt);
|
|
12149
|
+
}
|
|
12150
|
+
} else {
|
|
12151
|
+
for (var i = 0, events = [], length = listeners.length; i < length; i++) {
|
|
12152
|
+
if (
|
|
12153
|
+
listeners[i].fn !== fn ||
|
|
12154
|
+
(once && !listeners[i].once) ||
|
|
12155
|
+
(context && listeners[i].context !== context)
|
|
12156
|
+
) {
|
|
12157
|
+
events.push(listeners[i]);
|
|
12158
|
+
}
|
|
12159
|
+
}
|
|
8916
12160
|
|
|
8917
|
-
//
|
|
8918
|
-
|
|
8919
|
-
|
|
8920
|
-
|
|
8921
|
-
|
|
8922
|
-
|
|
8923
|
-
|
|
8924
|
-
|
|
8925
|
-
|
|
8926
|
-
|
|
8927
|
-
|
|
8928
|
-
|
|
8929
|
-
|
|
8930
|
-
|
|
8931
|
-
|
|
8932
|
-
|
|
8933
|
-
|
|
8934
|
-
|
|
8935
|
-
|
|
8936
|
-
|
|
8937
|
-
|
|
8938
|
-
|
|
8939
|
-
|
|
8940
|
-
|
|
8941
|
-
|
|
8942
|
-
|
|
8943
|
-
|
|
8944
|
-
|
|
8945
|
-
|
|
8946
|
-
|
|
8947
|
-
|
|
8948
|
-
|
|
8949
|
-
|
|
8950
|
-
|
|
8951
|
-
|
|
8952
|
-
|
|
8953
|
-
|
|
8954
|
-
|
|
8955
|
-
|
|
8956
|
-
|
|
8957
|
-
|
|
8958
|
-
|
|
8959
|
-
|
|
8960
|
-
|
|
8961
|
-
|
|
8962
|
-
|
|
8963
|
-
|
|
8964
|
-
|
|
8965
|
-
|
|
8966
|
-
|
|
8967
|
-
|
|
8968
|
-
|
|
8969
|
-
|
|
8970
|
-
|
|
8971
|
-
|
|
8972
|
-
throw new Error("Unsupported Solana transaction format");
|
|
8973
|
-
}
|
|
8974
|
-
function parseEVMTransactionToHex(transaction) {
|
|
8975
|
-
if (typeof transaction === "string" && transaction.startsWith("0x")) {
|
|
8976
|
-
return {
|
|
8977
|
-
parsed: transaction,
|
|
8978
|
-
originalFormat: "hex"
|
|
8979
|
-
};
|
|
8980
|
-
}
|
|
8981
|
-
if (transaction?.serialize && typeof transaction.serialize === "function") {
|
|
8982
|
-
const serialized = transaction.serialize();
|
|
8983
|
-
const hex = serialized.startsWith("0x") ? serialized : "0x" + serialized;
|
|
8984
|
-
return {
|
|
8985
|
-
parsed: hex,
|
|
8986
|
-
originalFormat: "ethers"
|
|
8987
|
-
};
|
|
8988
|
-
}
|
|
8989
|
-
if (transaction instanceof Uint8Array) {
|
|
8990
|
-
const hex = "0x" + index.bufferExports.Buffer.from(transaction).toString("hex");
|
|
8991
|
-
return {
|
|
8992
|
-
parsed: hex,
|
|
8993
|
-
originalFormat: "bytes"
|
|
8994
|
-
};
|
|
8995
|
-
}
|
|
8996
|
-
if (transaction && typeof transaction === "object" && (transaction.to || transaction.data || transaction.from)) {
|
|
8997
|
-
try {
|
|
8998
|
-
const { from, gas, ...txForSerialization } = transaction;
|
|
8999
|
-
if (gas) {
|
|
9000
|
-
txForSerialization.gasLimit = gas;
|
|
9001
|
-
}
|
|
9002
|
-
if (!txForSerialization.gasLimit) {
|
|
9003
|
-
if (txForSerialization.to && txForSerialization.value && !txForSerialization.data) {
|
|
9004
|
-
txForSerialization.gasLimit = "0x5208";
|
|
9005
|
-
}
|
|
9006
|
-
}
|
|
9007
|
-
if (txForSerialization.to && typeof txForSerialization.to === "string") {
|
|
9008
|
-
try {
|
|
9009
|
-
txForSerialization.to = getAddress(txForSerialization.to);
|
|
9010
|
-
} catch {
|
|
9011
|
-
txForSerialization.to = txForSerialization.to.toLowerCase();
|
|
9012
|
-
}
|
|
9013
|
-
}
|
|
9014
|
-
const serialized = Transaction.from(txForSerialization).unsignedSerialized;
|
|
9015
|
-
const hex = serialized.startsWith("0x") ? serialized : "0x" + serialized;
|
|
9016
|
-
return {
|
|
9017
|
-
parsed: hex,
|
|
9018
|
-
originalFormat: "json"
|
|
9019
|
-
};
|
|
9020
|
-
} catch (error) {
|
|
9021
|
-
const errorMessage = error instanceof Error ? error.message : "Unknown error";
|
|
9022
|
-
const txKeys = transaction ? Object.keys(transaction).join(", ") : "N/A";
|
|
9023
|
-
const txValues = transaction ? JSON.stringify(transaction, null, 2) : "N/A";
|
|
9024
|
-
throw new Error(
|
|
9025
|
-
`Failed to RLP encode EVM transaction: ${errorMessage}.
|
|
9026
|
-
Transaction keys: [${txKeys}].
|
|
9027
|
-
Transaction: ${txValues}
|
|
9028
|
-
Please ensure the transaction object includes required fields (to, value, chainId, gasLimit or gasPrice, etc.)`
|
|
9029
|
-
);
|
|
9030
|
-
}
|
|
9031
|
-
}
|
|
9032
|
-
throw new Error(
|
|
9033
|
-
"Unsupported EVM transaction format. Expected hex string, bytes, or transaction object with 'to', 'data', or 'from' fields."
|
|
9034
|
-
);
|
|
9035
|
-
}
|
|
9036
|
-
async function parseSuiTransactionToBase64Url(transaction) {
|
|
9037
|
-
if (transaction?.serialize && typeof transaction.serialize === "function") {
|
|
9038
|
-
const serialized = transaction.serialize();
|
|
9039
|
-
return {
|
|
9040
|
-
parsed: base64urlEncode(serialized),
|
|
9041
|
-
originalFormat: "sui-sdk"
|
|
9042
|
-
};
|
|
9043
|
-
}
|
|
9044
|
-
if (transaction instanceof Uint8Array) {
|
|
9045
|
-
return {
|
|
9046
|
-
parsed: base64urlEncode(transaction),
|
|
9047
|
-
originalFormat: "bytes"
|
|
9048
|
-
};
|
|
9049
|
-
}
|
|
9050
|
-
if (transaction?.build && typeof transaction.build === "function") {
|
|
9051
|
-
const built = await transaction.build();
|
|
9052
|
-
if (built?.serialize && typeof built.serialize === "function") {
|
|
9053
|
-
const serialized = built.serialize();
|
|
9054
|
-
return {
|
|
9055
|
-
parsed: base64urlEncode(serialized),
|
|
9056
|
-
originalFormat: "transaction-block"
|
|
9057
|
-
};
|
|
9058
|
-
}
|
|
9059
|
-
}
|
|
9060
|
-
throw new Error("Unsupported Sui transaction format");
|
|
9061
|
-
}
|
|
9062
|
-
function parseBitcoinTransactionToBase64Url(transaction) {
|
|
9063
|
-
if (transaction?.toBuffer && typeof transaction.toBuffer === "function") {
|
|
9064
|
-
const buffer = transaction.toBuffer();
|
|
9065
|
-
return {
|
|
9066
|
-
parsed: base64urlEncode(new Uint8Array(buffer)),
|
|
9067
|
-
originalFormat: "bitcoinjs-lib"
|
|
9068
|
-
};
|
|
9069
|
-
}
|
|
9070
|
-
if (transaction instanceof Uint8Array) {
|
|
9071
|
-
return {
|
|
9072
|
-
parsed: base64urlEncode(transaction),
|
|
9073
|
-
originalFormat: "bytes"
|
|
9074
|
-
};
|
|
9075
|
-
}
|
|
9076
|
-
if (typeof transaction === "string") {
|
|
9077
|
-
const bytes = new Uint8Array(index.bufferExports.Buffer.from(transaction, "hex"));
|
|
9078
|
-
return {
|
|
9079
|
-
parsed: base64urlEncode(bytes),
|
|
9080
|
-
originalFormat: "hex"
|
|
9081
|
-
};
|
|
9082
|
-
}
|
|
9083
|
-
throw new Error("Unsupported Bitcoin transaction format");
|
|
12161
|
+
//
|
|
12162
|
+
// Reset the array, or remove it completely if we have no more listeners.
|
|
12163
|
+
//
|
|
12164
|
+
if (events.length) this._events[evt] = events.length === 1 ? events[0] : events;
|
|
12165
|
+
else clearEvent(this, evt);
|
|
12166
|
+
}
|
|
12167
|
+
|
|
12168
|
+
return this;
|
|
12169
|
+
};
|
|
12170
|
+
|
|
12171
|
+
/**
|
|
12172
|
+
* Remove all listeners, or those of the specified event.
|
|
12173
|
+
*
|
|
12174
|
+
* @param {(String|Symbol)} [event] The event name.
|
|
12175
|
+
* @returns {EventEmitter} `this`.
|
|
12176
|
+
* @public
|
|
12177
|
+
*/
|
|
12178
|
+
EventEmitter.prototype.removeAllListeners = function removeAllListeners(event) {
|
|
12179
|
+
var evt;
|
|
12180
|
+
|
|
12181
|
+
if (event) {
|
|
12182
|
+
evt = prefix ? prefix + event : event;
|
|
12183
|
+
if (this._events[evt]) clearEvent(this, evt);
|
|
12184
|
+
} else {
|
|
12185
|
+
this._events = new Events();
|
|
12186
|
+
this._eventsCount = 0;
|
|
12187
|
+
}
|
|
12188
|
+
|
|
12189
|
+
return this;
|
|
12190
|
+
};
|
|
12191
|
+
|
|
12192
|
+
//
|
|
12193
|
+
// Alias methods names because people roll like that.
|
|
12194
|
+
//
|
|
12195
|
+
EventEmitter.prototype.off = EventEmitter.prototype.removeListener;
|
|
12196
|
+
EventEmitter.prototype.addListener = EventEmitter.prototype.on;
|
|
12197
|
+
|
|
12198
|
+
//
|
|
12199
|
+
// Expose the prefix.
|
|
12200
|
+
//
|
|
12201
|
+
EventEmitter.prefixed = prefix;
|
|
12202
|
+
|
|
12203
|
+
//
|
|
12204
|
+
// Allow `EventEmitter` to be imported as module namespace.
|
|
12205
|
+
//
|
|
12206
|
+
EventEmitter.EventEmitter = EventEmitter;
|
|
12207
|
+
|
|
12208
|
+
//
|
|
12209
|
+
// Expose the module.
|
|
12210
|
+
//
|
|
12211
|
+
{
|
|
12212
|
+
module.exports = EventEmitter;
|
|
12213
|
+
}
|
|
12214
|
+
} (eventemitter3));
|
|
12215
|
+
return eventemitter3.exports;
|
|
9084
12216
|
}
|
|
9085
12217
|
|
|
12218
|
+
var eventemitter3Exports = requireEventemitter3();
|
|
12219
|
+
var EventEmitter2 = /*@__PURE__*/index.getDefaultExportFromCjs(eventemitter3Exports);
|
|
12220
|
+
|
|
9086
12221
|
// src/embedded-provider.ts
|
|
9087
12222
|
|
|
9088
12223
|
// src/constants.ts
|
|
@@ -9094,7 +12229,7 @@ var EmbeddedSolanaChain = class {
|
|
|
9094
12229
|
this.currentNetworkId = NetworkId.SOLANA_MAINNET;
|
|
9095
12230
|
this._connected = false;
|
|
9096
12231
|
this._publicKey = null;
|
|
9097
|
-
this.eventEmitter = new
|
|
12232
|
+
this.eventEmitter = new EventEmitter2();
|
|
9098
12233
|
this.setupEventListeners();
|
|
9099
12234
|
this.syncInitialState();
|
|
9100
12235
|
}
|
|
@@ -9118,7 +12253,7 @@ var EmbeddedSolanaChain = class {
|
|
|
9118
12253
|
message: messageStr,
|
|
9119
12254
|
networkId: this.currentNetworkId
|
|
9120
12255
|
});
|
|
9121
|
-
const signature = typeof result.signature === "string" ? new Uint8Array(
|
|
12256
|
+
const signature = typeof result.signature === "string" ? new Uint8Array(bs582.decode(result.signature)) : result.signature;
|
|
9122
12257
|
return {
|
|
9123
12258
|
signature,
|
|
9124
12259
|
publicKey: this._publicKey || ""
|
|
@@ -9224,7 +12359,7 @@ var EmbeddedEthereumChain = class {
|
|
|
9224
12359
|
this.currentNetworkId = NetworkId.ETHEREUM_MAINNET;
|
|
9225
12360
|
this._connected = false;
|
|
9226
12361
|
this._accounts = [];
|
|
9227
|
-
this.eventEmitter = new
|
|
12362
|
+
this.eventEmitter = new EventEmitter2();
|
|
9228
12363
|
this.setupEventListeners();
|
|
9229
12364
|
this.syncInitialState();
|
|
9230
12365
|
}
|
|
@@ -9801,7 +12936,7 @@ var EmbeddedProvider$1 = class EmbeddedProvider {
|
|
|
9801
12936
|
publicKey: stamperInfo.publicKey,
|
|
9802
12937
|
platform: platformName
|
|
9803
12938
|
});
|
|
9804
|
-
const base64urlPublicKey = base64urlEncode(
|
|
12939
|
+
const base64urlPublicKey = base64urlEncode(bs582.decode(stamperInfo.publicKey));
|
|
9805
12940
|
const username = `user-${randomUUID()}`;
|
|
9806
12941
|
const { organizationId } = await tempClient.createOrganization(organizationName, [
|
|
9807
12942
|
{
|
|
@@ -10390,6 +13525,133 @@ var EmbeddedProvider$1 = class EmbeddedProvider {
|
|
|
10390
13525
|
}
|
|
10391
13526
|
};
|
|
10392
13527
|
|
|
13528
|
+
// base-x encoding / decoding
|
|
13529
|
+
// Copyright (c) 2018 base-x contributors
|
|
13530
|
+
// Copyright (c) 2014-2018 The Bitcoin Core developers (base58.cpp)
|
|
13531
|
+
// Distributed under the MIT software license, see the accompanying
|
|
13532
|
+
// file LICENSE or http://www.opensource.org/licenses/mit-license.php.
|
|
13533
|
+
function base (ALPHABET) {
|
|
13534
|
+
if (ALPHABET.length >= 255) { throw new TypeError('Alphabet too long') }
|
|
13535
|
+
const BASE_MAP = new Uint8Array(256);
|
|
13536
|
+
for (let j = 0; j < BASE_MAP.length; j++) {
|
|
13537
|
+
BASE_MAP[j] = 255;
|
|
13538
|
+
}
|
|
13539
|
+
for (let i = 0; i < ALPHABET.length; i++) {
|
|
13540
|
+
const x = ALPHABET.charAt(i);
|
|
13541
|
+
const xc = x.charCodeAt(0);
|
|
13542
|
+
if (BASE_MAP[xc] !== 255) { throw new TypeError(x + ' is ambiguous') }
|
|
13543
|
+
BASE_MAP[xc] = i;
|
|
13544
|
+
}
|
|
13545
|
+
const BASE = ALPHABET.length;
|
|
13546
|
+
const LEADER = ALPHABET.charAt(0);
|
|
13547
|
+
const FACTOR = Math.log(BASE) / Math.log(256); // log(BASE) / log(256), rounded up
|
|
13548
|
+
const iFACTOR = Math.log(256) / Math.log(BASE); // log(256) / log(BASE), rounded up
|
|
13549
|
+
function encode (source) {
|
|
13550
|
+
// eslint-disable-next-line no-empty
|
|
13551
|
+
if (source instanceof Uint8Array) ; else if (ArrayBuffer.isView(source)) {
|
|
13552
|
+
source = new Uint8Array(source.buffer, source.byteOffset, source.byteLength);
|
|
13553
|
+
} else if (Array.isArray(source)) {
|
|
13554
|
+
source = Uint8Array.from(source);
|
|
13555
|
+
}
|
|
13556
|
+
if (!(source instanceof Uint8Array)) { throw new TypeError('Expected Uint8Array') }
|
|
13557
|
+
if (source.length === 0) { return '' }
|
|
13558
|
+
// Skip & count leading zeroes.
|
|
13559
|
+
let zeroes = 0;
|
|
13560
|
+
let length = 0;
|
|
13561
|
+
let pbegin = 0;
|
|
13562
|
+
const pend = source.length;
|
|
13563
|
+
while (pbegin !== pend && source[pbegin] === 0) {
|
|
13564
|
+
pbegin++;
|
|
13565
|
+
zeroes++;
|
|
13566
|
+
}
|
|
13567
|
+
// Allocate enough space in big-endian base58 representation.
|
|
13568
|
+
const size = ((pend - pbegin) * iFACTOR + 1) >>> 0;
|
|
13569
|
+
const b58 = new Uint8Array(size);
|
|
13570
|
+
// Process the bytes.
|
|
13571
|
+
while (pbegin !== pend) {
|
|
13572
|
+
let carry = source[pbegin];
|
|
13573
|
+
// Apply "b58 = b58 * 256 + ch".
|
|
13574
|
+
let i = 0;
|
|
13575
|
+
for (let it1 = size - 1; (carry !== 0 || i < length) && (it1 !== -1); it1--, i++) {
|
|
13576
|
+
carry += (256 * b58[it1]) >>> 0;
|
|
13577
|
+
b58[it1] = (carry % BASE) >>> 0;
|
|
13578
|
+
carry = (carry / BASE) >>> 0;
|
|
13579
|
+
}
|
|
13580
|
+
if (carry !== 0) { throw new Error('Non-zero carry') }
|
|
13581
|
+
length = i;
|
|
13582
|
+
pbegin++;
|
|
13583
|
+
}
|
|
13584
|
+
// Skip leading zeroes in base58 result.
|
|
13585
|
+
let it2 = size - length;
|
|
13586
|
+
while (it2 !== size && b58[it2] === 0) {
|
|
13587
|
+
it2++;
|
|
13588
|
+
}
|
|
13589
|
+
// Translate the result into a string.
|
|
13590
|
+
let str = LEADER.repeat(zeroes);
|
|
13591
|
+
for (; it2 < size; ++it2) { str += ALPHABET.charAt(b58[it2]); }
|
|
13592
|
+
return str
|
|
13593
|
+
}
|
|
13594
|
+
function decodeUnsafe (source) {
|
|
13595
|
+
if (typeof source !== 'string') { throw new TypeError('Expected String') }
|
|
13596
|
+
if (source.length === 0) { return new Uint8Array() }
|
|
13597
|
+
let psz = 0;
|
|
13598
|
+
// Skip and count leading '1's.
|
|
13599
|
+
let zeroes = 0;
|
|
13600
|
+
let length = 0;
|
|
13601
|
+
while (source[psz] === LEADER) {
|
|
13602
|
+
zeroes++;
|
|
13603
|
+
psz++;
|
|
13604
|
+
}
|
|
13605
|
+
// Allocate enough space in big-endian base256 representation.
|
|
13606
|
+
const size = (((source.length - psz) * FACTOR) + 1) >>> 0; // log(58) / log(256), rounded up.
|
|
13607
|
+
const b256 = new Uint8Array(size);
|
|
13608
|
+
// Process the characters.
|
|
13609
|
+
while (psz < source.length) {
|
|
13610
|
+
// Find code of next character
|
|
13611
|
+
const charCode = source.charCodeAt(psz);
|
|
13612
|
+
// Base map can not be indexed using char code
|
|
13613
|
+
if (charCode > 255) { return }
|
|
13614
|
+
// Decode character
|
|
13615
|
+
let carry = BASE_MAP[charCode];
|
|
13616
|
+
// Invalid character
|
|
13617
|
+
if (carry === 255) { return }
|
|
13618
|
+
let i = 0;
|
|
13619
|
+
for (let it3 = size - 1; (carry !== 0 || i < length) && (it3 !== -1); it3--, i++) {
|
|
13620
|
+
carry += (BASE * b256[it3]) >>> 0;
|
|
13621
|
+
b256[it3] = (carry % 256) >>> 0;
|
|
13622
|
+
carry = (carry / 256) >>> 0;
|
|
13623
|
+
}
|
|
13624
|
+
if (carry !== 0) { throw new Error('Non-zero carry') }
|
|
13625
|
+
length = i;
|
|
13626
|
+
psz++;
|
|
13627
|
+
}
|
|
13628
|
+
// Skip leading zeroes in b256.
|
|
13629
|
+
let it4 = size - length;
|
|
13630
|
+
while (it4 !== size && b256[it4] === 0) {
|
|
13631
|
+
it4++;
|
|
13632
|
+
}
|
|
13633
|
+
const vch = new Uint8Array(zeroes + (size - it4));
|
|
13634
|
+
let j = zeroes;
|
|
13635
|
+
while (it4 !== size) {
|
|
13636
|
+
vch[j++] = b256[it4++];
|
|
13637
|
+
}
|
|
13638
|
+
return vch
|
|
13639
|
+
}
|
|
13640
|
+
function decode (string) {
|
|
13641
|
+
const buffer = decodeUnsafe(string);
|
|
13642
|
+
if (buffer) { return buffer }
|
|
13643
|
+
throw new Error('Non-base' + BASE + ' character')
|
|
13644
|
+
}
|
|
13645
|
+
return {
|
|
13646
|
+
encode,
|
|
13647
|
+
decodeUnsafe,
|
|
13648
|
+
decode
|
|
13649
|
+
}
|
|
13650
|
+
}
|
|
13651
|
+
|
|
13652
|
+
var ALPHABET = '123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz';
|
|
13653
|
+
var bs58 = base(ALPHABET);
|
|
13654
|
+
|
|
10393
13655
|
// src/index.ts
|
|
10394
13656
|
var IndexedDbStamper = class {
|
|
10395
13657
|
// Optional for PKI, required for OIDC
|
|
@@ -10463,14 +13725,14 @@ var IndexedDbStamper = class {
|
|
|
10463
13725
|
const salt = params.type === "OIDC" ? params.salt : this.salt;
|
|
10464
13726
|
const stampData = stampType === "PKI" ? {
|
|
10465
13727
|
// Decode base58 public key to bytes, then encode as base64url (consistent with ApiKeyStamper)
|
|
10466
|
-
publicKey: base64urlEncode(
|
|
13728
|
+
publicKey: base64urlEncode(bs58.decode(this.activeKeyPairRecord.keyInfo.publicKey)),
|
|
10467
13729
|
signature: signatureBase64url,
|
|
10468
13730
|
kind: "PKI",
|
|
10469
13731
|
algorithm: this.algorithm
|
|
10470
13732
|
} : {
|
|
10471
13733
|
kind: "OIDC",
|
|
10472
13734
|
idToken,
|
|
10473
|
-
publicKey: base64urlEncode(
|
|
13735
|
+
publicKey: base64urlEncode(bs58.decode(this.activeKeyPairRecord.keyInfo.publicKey)),
|
|
10474
13736
|
salt,
|
|
10475
13737
|
algorithm: this.algorithm,
|
|
10476
13738
|
signature: signatureBase64url
|
|
@@ -10573,7 +13835,7 @@ var IndexedDbStamper = class {
|
|
|
10573
13835
|
["sign", "verify"]
|
|
10574
13836
|
);
|
|
10575
13837
|
const rawPublicKeyBuffer = await crypto.subtle.exportKey("raw", keyPair.publicKey);
|
|
10576
|
-
const publicKeyBase58 =
|
|
13838
|
+
const publicKeyBase58 = bs58.encode(new Uint8Array(rawPublicKeyBuffer));
|
|
10577
13839
|
const keyIdBuffer = await crypto.subtle.digest("SHA-256", rawPublicKeyBuffer);
|
|
10578
13840
|
const keyId = base64urlEncode(new Uint8Array(keyIdBuffer)).substring(0, 16);
|
|
10579
13841
|
const now = Date.now();
|
|
@@ -11492,7 +14754,7 @@ var WalletStandardSolanaAdapter = class {
|
|
|
11492
14754
|
throw new Error("No signature found in signAndSendTransaction result");
|
|
11493
14755
|
}
|
|
11494
14756
|
const signatureBytes = this.parseUint8Array(signatureOutput.signature);
|
|
11495
|
-
const signature =
|
|
14757
|
+
const signature = bs58$1.encode(signatureBytes);
|
|
11496
14758
|
return { signature };
|
|
11497
14759
|
} catch (error) {
|
|
11498
14760
|
debug.error(DebugCategory.INJECTED_PROVIDER, "Wallet Standard Solana signAndSendTransaction failed", {
|
|
@@ -15924,4 +19186,4 @@ exports.useModal = useModal;
|
|
|
15924
19186
|
exports.usePhantom = usePhantom;
|
|
15925
19187
|
exports.useSolana = useSolana;
|
|
15926
19188
|
exports.useTheme = useTheme;
|
|
15927
|
-
//# sourceMappingURL=index-
|
|
19189
|
+
//# sourceMappingURL=index-Ci3m3diI.js.map
|