@pooflabs/web 0.0.81-rc5 → 0.0.81
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-B2WGCssJ.js} +346 -490
- package/dist/index-B2WGCssJ.js.map +1 -0
- package/dist/{index-DB9nDInp.esm.js → index-CjHbp7Dq.esm.js} +3697 -562
- package/dist/index-CjHbp7Dq.esm.js.map +1 -0
- package/dist/{index-D_ta2S2c.js → index-DXPkkq81.js} +3698 -563
- package/dist/index-DXPkkq81.js.map +1 -0
- package/dist/{index-Bg_ApFIo.js → index-D_DiP8XQ.js} +3698 -563
- package/dist/index-D_DiP8XQ.js.map +1 -0
- package/dist/{index-CZhJBWap.esm.js → index-dcJIjFrs.esm.js} +3697 -562
- package/dist/index-dcJIjFrs.esm.js.map +1 -0
- package/dist/{index-Bkr4BRoP.esm.js → index-nt_HQVrk.esm.js} +344 -490
- package/dist/index-nt_HQVrk.esm.js.map +1 -0
- package/dist/{index.browser-iqs5DlRU.esm.js → index.browser-BNdFfyIg.esm.js} +1571 -1368
- package/dist/index.browser-BNdFfyIg.esm.js.map +1 -0
- package/dist/{index.browser-DHi7UhqF.js → index.browser-CT6PUv9G.js} +1571 -1368
- package/dist/index.browser-CT6PUv9G.js.map +1 -0
- package/dist/index.browser-Cy21yaX0.esm.js +1096 -0
- package/dist/index.browser-Cy21yaX0.esm.js.map +1 -0
- package/dist/index.browser-OvGNsMPu.esm.js +1002 -0
- package/dist/index.browser-OvGNsMPu.esm.js.map +1 -0
- package/dist/index.browser-ZD7Tz2bn.js +1099 -0
- package/dist/index.browser-ZD7Tz2bn.js.map +1 -0
- package/dist/index.browser-d0PlOXpF.js +105 -0
- package/dist/index.browser-d0PlOXpF.js.map +1 -0
- package/dist/index.browser-pE1s68e9.esm.js +102 -0
- package/dist/index.browser-pE1s68e9.esm.js.map +1 -0
- package/dist/index.browser-vuTr40so.js +1008 -0
- package/dist/index.browser-vuTr40so.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-DYgJWWY4.esm.js → index.native-BqYr--vb.esm.js} +202 -178
- package/dist/index.native-BqYr--vb.esm.js.map +1 -0
- package/dist/{index.native-DJWuqJTZ.js → index.native-CyA-RdvW.js} +204 -178
- package/dist/index.native-CyA-RdvW.js.map +1 -0
- package/dist/index.native.esm.js +1 -1
- package/dist/index.native.js +1 -1
- package/dist/{phantom-wallet-provider-fofd8BMo.js → phantom-wallet-provider-DWCaMkyz.js} +147 -238
- package/dist/phantom-wallet-provider-DWCaMkyz.js.map +1 -0
- package/dist/{phantom-wallet-provider-DSFGWSOJ.esm.js → phantom-wallet-provider-K2V96G-G.esm.js} +147 -238
- package/dist/phantom-wallet-provider-K2V96G-G.esm.js.map +1 -0
- package/dist/{privy-wallet-provider-Csv34Kcc.js → privy-wallet-provider-BMg_S_d0.js} +4 -4
- package/dist/privy-wallet-provider-BMg_S_d0.js.map +1 -0
- package/dist/{privy-wallet-provider-TRToDe4Q.esm.js → privy-wallet-provider-DoX8q99w.esm.js} +4 -4
- package/dist/privy-wallet-provider-DoX8q99w.esm.js.map +1 -0
- package/dist/{solana-mobile-wallet-provider-L7nRuxhv.esm.js → solana-mobile-wallet-provider-Cmphb3oB.esm.js} +3 -82
- package/dist/solana-mobile-wallet-provider-Cmphb3oB.esm.js.map +1 -0
- package/dist/{solana-mobile-wallet-provider-Cp65LfNb.js → solana-mobile-wallet-provider-t22Ie8lY.js} +3 -82
- package/dist/solana-mobile-wallet-provider-t22Ie8lY.js.map +1 -0
- package/package.json +3 -3
- 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-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 +0 -119
- package/dist/index.browser-BTlliHCf.esm.js.map +0 -1
- package/dist/index.browser-C-_FEr5M.esm.js +0 -1134
- package/dist/index.browser-C-_FEr5M.esm.js.map +0 -1
- package/dist/index.browser-DHi7UhqF.js.map +0 -1
- package/dist/index.browser-DRTQuf0J.js +0 -1253
- package/dist/index.browser-DRTQuf0J.js.map +0 -1
- package/dist/index.browser-Disp7Kcb.esm.js +0 -1250
- package/dist/index.browser-Disp7Kcb.esm.js.map +0 -1
- package/dist/index.browser-DjEZSiqI.js +0 -1137
- package/dist/index.browser-DjEZSiqI.js.map +0 -1
- package/dist/index.browser-DvTeEO2r.js +0 -122
- package/dist/index.browser-DvTeEO2r.js.map +0 -1
- package/dist/index.browser-iqs5DlRU.esm.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
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import * as React from 'react';
|
|
2
2
|
import { useContext, createContext, useState, useMemo, useRef, useEffect, useCallback } from 'react';
|
|
3
3
|
import globalAxios, { isAxiosError } from 'axios';
|
|
4
|
-
import { b as bufferExports, g as getDefaultExportFromCjs, a as
|
|
4
|
+
import { c as commonjsRequire, r as require$$0, b as bufferExports, g as getDefaultExportFromCjs, a as base58 } from './index-nt_HQVrk.esm.js';
|
|
5
5
|
import { Transaction as Transaction$1, VersionedTransaction } from '@solana/web3.js';
|
|
6
6
|
import { jsx, jsxs, Fragment } from 'react/jsx-runtime';
|
|
7
7
|
import '@coral-xyz/anchor';
|
|
@@ -998,269 +998,2673 @@ function isSolanaChain(networkId) {
|
|
|
998
998
|
return network === "solana";
|
|
999
999
|
}
|
|
1000
1000
|
|
|
1001
|
-
var
|
|
1002
|
-
var hasRequiredSrc;
|
|
1001
|
+
var naclFast = {exports: {}};
|
|
1003
1002
|
|
|
1004
|
-
|
|
1005
|
-
if (hasRequiredSrc) return src;
|
|
1006
|
-
hasRequiredSrc = 1;
|
|
1007
|
-
// base-x encoding / decoding
|
|
1008
|
-
// Copyright (c) 2018 base-x contributors
|
|
1009
|
-
// Copyright (c) 2014-2018 The Bitcoin Core developers (base58.cpp)
|
|
1010
|
-
// Distributed under the MIT software license, see the accompanying
|
|
1011
|
-
// file LICENSE or http://www.opensource.org/licenses/mit-license.php.
|
|
1012
|
-
function base (ALPHABET) {
|
|
1013
|
-
if (ALPHABET.length >= 255) { throw new TypeError('Alphabet too long') }
|
|
1014
|
-
var BASE_MAP = new Uint8Array(256);
|
|
1015
|
-
for (var j = 0; j < BASE_MAP.length; j++) {
|
|
1016
|
-
BASE_MAP[j] = 255;
|
|
1017
|
-
}
|
|
1018
|
-
for (var i = 0; i < ALPHABET.length; i++) {
|
|
1019
|
-
var x = ALPHABET.charAt(i);
|
|
1020
|
-
var xc = x.charCodeAt(0);
|
|
1021
|
-
if (BASE_MAP[xc] !== 255) { throw new TypeError(x + ' is ambiguous') }
|
|
1022
|
-
BASE_MAP[xc] = i;
|
|
1023
|
-
}
|
|
1024
|
-
var BASE = ALPHABET.length;
|
|
1025
|
-
var LEADER = ALPHABET.charAt(0);
|
|
1026
|
-
var FACTOR = Math.log(BASE) / Math.log(256); // log(BASE) / log(256), rounded up
|
|
1027
|
-
var iFACTOR = Math.log(256) / Math.log(BASE); // log(256) / log(BASE), rounded up
|
|
1028
|
-
function encode (source) {
|
|
1029
|
-
if (source instanceof Uint8Array) ; else if (ArrayBuffer.isView(source)) {
|
|
1030
|
-
source = new Uint8Array(source.buffer, source.byteOffset, source.byteLength);
|
|
1031
|
-
} else if (Array.isArray(source)) {
|
|
1032
|
-
source = Uint8Array.from(source);
|
|
1033
|
-
}
|
|
1034
|
-
if (!(source instanceof Uint8Array)) { throw new TypeError('Expected Uint8Array') }
|
|
1035
|
-
if (source.length === 0) { return '' }
|
|
1036
|
-
// Skip & count leading zeroes.
|
|
1037
|
-
var zeroes = 0;
|
|
1038
|
-
var length = 0;
|
|
1039
|
-
var pbegin = 0;
|
|
1040
|
-
var pend = source.length;
|
|
1041
|
-
while (pbegin !== pend && source[pbegin] === 0) {
|
|
1042
|
-
pbegin++;
|
|
1043
|
-
zeroes++;
|
|
1044
|
-
}
|
|
1045
|
-
// Allocate enough space in big-endian base58 representation.
|
|
1046
|
-
var size = ((pend - pbegin) * iFACTOR + 1) >>> 0;
|
|
1047
|
-
var b58 = new Uint8Array(size);
|
|
1048
|
-
// Process the bytes.
|
|
1049
|
-
while (pbegin !== pend) {
|
|
1050
|
-
var carry = source[pbegin];
|
|
1051
|
-
// Apply "b58 = b58 * 256 + ch".
|
|
1052
|
-
var i = 0;
|
|
1053
|
-
for (var it1 = size - 1; (carry !== 0 || i < length) && (it1 !== -1); it1--, i++) {
|
|
1054
|
-
carry += (256 * b58[it1]) >>> 0;
|
|
1055
|
-
b58[it1] = (carry % BASE) >>> 0;
|
|
1056
|
-
carry = (carry / BASE) >>> 0;
|
|
1057
|
-
}
|
|
1058
|
-
if (carry !== 0) { throw new Error('Non-zero carry') }
|
|
1059
|
-
length = i;
|
|
1060
|
-
pbegin++;
|
|
1061
|
-
}
|
|
1062
|
-
// Skip leading zeroes in base58 result.
|
|
1063
|
-
var it2 = size - length;
|
|
1064
|
-
while (it2 !== size && b58[it2] === 0) {
|
|
1065
|
-
it2++;
|
|
1066
|
-
}
|
|
1067
|
-
// Translate the result into a string.
|
|
1068
|
-
var str = LEADER.repeat(zeroes);
|
|
1069
|
-
for (; it2 < size; ++it2) { str += ALPHABET.charAt(b58[it2]); }
|
|
1070
|
-
return str
|
|
1071
|
-
}
|
|
1072
|
-
function decodeUnsafe (source) {
|
|
1073
|
-
if (typeof source !== 'string') { throw new TypeError('Expected String') }
|
|
1074
|
-
if (source.length === 0) { return new Uint8Array() }
|
|
1075
|
-
var psz = 0;
|
|
1076
|
-
// Skip and count leading '1's.
|
|
1077
|
-
var zeroes = 0;
|
|
1078
|
-
var length = 0;
|
|
1079
|
-
while (source[psz] === LEADER) {
|
|
1080
|
-
zeroes++;
|
|
1081
|
-
psz++;
|
|
1082
|
-
}
|
|
1083
|
-
// Allocate enough space in big-endian base256 representation.
|
|
1084
|
-
var size = (((source.length - psz) * FACTOR) + 1) >>> 0; // log(58) / log(256), rounded up.
|
|
1085
|
-
var b256 = new Uint8Array(size);
|
|
1086
|
-
// Process the characters.
|
|
1087
|
-
while (source[psz]) {
|
|
1088
|
-
// Find code of next character
|
|
1089
|
-
var charCode = source.charCodeAt(psz);
|
|
1090
|
-
// Base map can not be indexed using char code
|
|
1091
|
-
if (charCode > 255) { return }
|
|
1092
|
-
// Decode character
|
|
1093
|
-
var carry = BASE_MAP[charCode];
|
|
1094
|
-
// Invalid character
|
|
1095
|
-
if (carry === 255) { return }
|
|
1096
|
-
var i = 0;
|
|
1097
|
-
for (var it3 = size - 1; (carry !== 0 || i < length) && (it3 !== -1); it3--, i++) {
|
|
1098
|
-
carry += (BASE * b256[it3]) >>> 0;
|
|
1099
|
-
b256[it3] = (carry % 256) >>> 0;
|
|
1100
|
-
carry = (carry / 256) >>> 0;
|
|
1101
|
-
}
|
|
1102
|
-
if (carry !== 0) { throw new Error('Non-zero carry') }
|
|
1103
|
-
length = i;
|
|
1104
|
-
psz++;
|
|
1105
|
-
}
|
|
1106
|
-
// Skip leading zeroes in b256.
|
|
1107
|
-
var it4 = size - length;
|
|
1108
|
-
while (it4 !== size && b256[it4] === 0) {
|
|
1109
|
-
it4++;
|
|
1110
|
-
}
|
|
1111
|
-
var vch = new Uint8Array(zeroes + (size - it4));
|
|
1112
|
-
var j = zeroes;
|
|
1113
|
-
while (it4 !== size) {
|
|
1114
|
-
vch[j++] = b256[it4++];
|
|
1115
|
-
}
|
|
1116
|
-
return vch
|
|
1117
|
-
}
|
|
1118
|
-
function decode (string) {
|
|
1119
|
-
var buffer = decodeUnsafe(string);
|
|
1120
|
-
if (buffer) { return buffer }
|
|
1121
|
-
throw new Error('Non-base' + BASE + ' character')
|
|
1122
|
-
}
|
|
1123
|
-
return {
|
|
1124
|
-
encode: encode,
|
|
1125
|
-
decodeUnsafe: decodeUnsafe,
|
|
1126
|
-
decode: decode
|
|
1127
|
-
}
|
|
1128
|
-
}
|
|
1129
|
-
src = base;
|
|
1130
|
-
return src;
|
|
1131
|
-
}
|
|
1003
|
+
var hasRequiredNaclFast;
|
|
1132
1004
|
|
|
1133
|
-
|
|
1134
|
-
|
|
1005
|
+
function requireNaclFast () {
|
|
1006
|
+
if (hasRequiredNaclFast) return naclFast.exports;
|
|
1007
|
+
hasRequiredNaclFast = 1;
|
|
1008
|
+
(function (module) {
|
|
1009
|
+
(function(nacl) {
|
|
1135
1010
|
|
|
1136
|
-
|
|
1137
|
-
|
|
1138
|
-
|
|
1139
|
-
|
|
1140
|
-
|
|
1011
|
+
// Ported in 2014 by Dmitry Chestnykh and Devi Mandiri.
|
|
1012
|
+
// Public domain.
|
|
1013
|
+
//
|
|
1014
|
+
// Implementation derived from TweetNaCl version 20140427.
|
|
1015
|
+
// See for details: http://tweetnacl.cr.yp.to/
|
|
1141
1016
|
|
|
1142
|
-
|
|
1143
|
-
|
|
1144
|
-
|
|
1017
|
+
var gf = function(init) {
|
|
1018
|
+
var i, r = new Float64Array(16);
|
|
1019
|
+
if (init) for (i = 0; i < init.length; i++) r[i] = init[i];
|
|
1020
|
+
return r;
|
|
1021
|
+
};
|
|
1145
1022
|
|
|
1146
|
-
|
|
1023
|
+
// Pluggable, initialized in high-level API below.
|
|
1024
|
+
var randombytes = function(/* x, n */) { throw new Error('no PRNG'); };
|
|
1147
1025
|
|
|
1148
|
-
|
|
1149
|
-
var
|
|
1150
|
-
|
|
1151
|
-
|
|
1152
|
-
|
|
1153
|
-
|
|
1154
|
-
|
|
1155
|
-
|
|
1156
|
-
|
|
1157
|
-
|
|
1158
|
-
|
|
1159
|
-
|
|
1160
|
-
|
|
1161
|
-
|
|
1162
|
-
|
|
1163
|
-
|
|
1164
|
-
|
|
1165
|
-
|
|
1166
|
-
|
|
1167
|
-
|
|
1168
|
-
|
|
1169
|
-
|
|
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
|
-
|
|
1026
|
+
var _0 = new Uint8Array(16);
|
|
1027
|
+
var _9 = new Uint8Array(32); _9[0] = 9;
|
|
1028
|
+
|
|
1029
|
+
var gf0 = gf(),
|
|
1030
|
+
gf1 = gf([1]),
|
|
1031
|
+
_121665 = gf([0xdb41, 1]),
|
|
1032
|
+
D = gf([0x78a3, 0x1359, 0x4dca, 0x75eb, 0xd8ab, 0x4141, 0x0a4d, 0x0070, 0xe898, 0x7779, 0x4079, 0x8cc7, 0xfe73, 0x2b6f, 0x6cee, 0x5203]),
|
|
1033
|
+
D2 = gf([0xf159, 0x26b2, 0x9b94, 0xebd6, 0xb156, 0x8283, 0x149a, 0x00e0, 0xd130, 0xeef3, 0x80f2, 0x198e, 0xfce7, 0x56df, 0xd9dc, 0x2406]),
|
|
1034
|
+
X = gf([0xd51a, 0x8f25, 0x2d60, 0xc956, 0xa7b2, 0x9525, 0xc760, 0x692c, 0xdc5c, 0xfdd6, 0xe231, 0xc0a4, 0x53fe, 0xcd6e, 0x36d3, 0x2169]),
|
|
1035
|
+
Y = gf([0x6658, 0x6666, 0x6666, 0x6666, 0x6666, 0x6666, 0x6666, 0x6666, 0x6666, 0x6666, 0x6666, 0x6666, 0x6666, 0x6666, 0x6666, 0x6666]),
|
|
1036
|
+
I = gf([0xa0b0, 0x4a0e, 0x1b27, 0xc4ee, 0xe478, 0xad2f, 0x1806, 0x2f43, 0xd7a7, 0x3dfb, 0x0099, 0x2b4d, 0xdf0b, 0x4fc1, 0x2480, 0x2b83]);
|
|
1037
|
+
|
|
1038
|
+
function ts64(x, i, h, l) {
|
|
1039
|
+
x[i] = (h >> 24) & 0xff;
|
|
1040
|
+
x[i+1] = (h >> 16) & 0xff;
|
|
1041
|
+
x[i+2] = (h >> 8) & 0xff;
|
|
1042
|
+
x[i+3] = h & 0xff;
|
|
1043
|
+
x[i+4] = (l >> 24) & 0xff;
|
|
1044
|
+
x[i+5] = (l >> 16) & 0xff;
|
|
1045
|
+
x[i+6] = (l >> 8) & 0xff;
|
|
1046
|
+
x[i+7] = l & 0xff;
|
|
1047
|
+
}
|
|
1048
|
+
|
|
1049
|
+
function vn(x, xi, y, yi, n) {
|
|
1050
|
+
var i,d = 0;
|
|
1051
|
+
for (i = 0; i < n; i++) d |= x[xi+i]^y[yi+i];
|
|
1052
|
+
return (1 & ((d - 1) >>> 8)) - 1;
|
|
1053
|
+
}
|
|
1054
|
+
|
|
1055
|
+
function crypto_verify_16(x, xi, y, yi) {
|
|
1056
|
+
return vn(x,xi,y,yi,16);
|
|
1057
|
+
}
|
|
1058
|
+
|
|
1059
|
+
function crypto_verify_32(x, xi, y, yi) {
|
|
1060
|
+
return vn(x,xi,y,yi,32);
|
|
1061
|
+
}
|
|
1062
|
+
|
|
1063
|
+
function core_salsa20(o, p, k, c) {
|
|
1064
|
+
var j0 = c[ 0] & 0xff | (c[ 1] & 0xff)<<8 | (c[ 2] & 0xff)<<16 | (c[ 3] & 0xff)<<24,
|
|
1065
|
+
j1 = k[ 0] & 0xff | (k[ 1] & 0xff)<<8 | (k[ 2] & 0xff)<<16 | (k[ 3] & 0xff)<<24,
|
|
1066
|
+
j2 = k[ 4] & 0xff | (k[ 5] & 0xff)<<8 | (k[ 6] & 0xff)<<16 | (k[ 7] & 0xff)<<24,
|
|
1067
|
+
j3 = k[ 8] & 0xff | (k[ 9] & 0xff)<<8 | (k[10] & 0xff)<<16 | (k[11] & 0xff)<<24,
|
|
1068
|
+
j4 = k[12] & 0xff | (k[13] & 0xff)<<8 | (k[14] & 0xff)<<16 | (k[15] & 0xff)<<24,
|
|
1069
|
+
j5 = c[ 4] & 0xff | (c[ 5] & 0xff)<<8 | (c[ 6] & 0xff)<<16 | (c[ 7] & 0xff)<<24,
|
|
1070
|
+
j6 = p[ 0] & 0xff | (p[ 1] & 0xff)<<8 | (p[ 2] & 0xff)<<16 | (p[ 3] & 0xff)<<24,
|
|
1071
|
+
j7 = p[ 4] & 0xff | (p[ 5] & 0xff)<<8 | (p[ 6] & 0xff)<<16 | (p[ 7] & 0xff)<<24,
|
|
1072
|
+
j8 = p[ 8] & 0xff | (p[ 9] & 0xff)<<8 | (p[10] & 0xff)<<16 | (p[11] & 0xff)<<24,
|
|
1073
|
+
j9 = p[12] & 0xff | (p[13] & 0xff)<<8 | (p[14] & 0xff)<<16 | (p[15] & 0xff)<<24,
|
|
1074
|
+
j10 = c[ 8] & 0xff | (c[ 9] & 0xff)<<8 | (c[10] & 0xff)<<16 | (c[11] & 0xff)<<24,
|
|
1075
|
+
j11 = k[16] & 0xff | (k[17] & 0xff)<<8 | (k[18] & 0xff)<<16 | (k[19] & 0xff)<<24,
|
|
1076
|
+
j12 = k[20] & 0xff | (k[21] & 0xff)<<8 | (k[22] & 0xff)<<16 | (k[23] & 0xff)<<24,
|
|
1077
|
+
j13 = k[24] & 0xff | (k[25] & 0xff)<<8 | (k[26] & 0xff)<<16 | (k[27] & 0xff)<<24,
|
|
1078
|
+
j14 = k[28] & 0xff | (k[29] & 0xff)<<8 | (k[30] & 0xff)<<16 | (k[31] & 0xff)<<24,
|
|
1079
|
+
j15 = c[12] & 0xff | (c[13] & 0xff)<<8 | (c[14] & 0xff)<<16 | (c[15] & 0xff)<<24;
|
|
1080
|
+
|
|
1081
|
+
var x0 = j0, x1 = j1, x2 = j2, x3 = j3, x4 = j4, x5 = j5, x6 = j6, x7 = j7,
|
|
1082
|
+
x8 = j8, x9 = j9, x10 = j10, x11 = j11, x12 = j12, x13 = j13, x14 = j14,
|
|
1083
|
+
x15 = j15, u;
|
|
1084
|
+
|
|
1085
|
+
for (var i = 0; i < 20; i += 2) {
|
|
1086
|
+
u = x0 + x12 | 0;
|
|
1087
|
+
x4 ^= u<<7 | u>>>(32-7);
|
|
1088
|
+
u = x4 + x0 | 0;
|
|
1089
|
+
x8 ^= u<<9 | u>>>(32-9);
|
|
1090
|
+
u = x8 + x4 | 0;
|
|
1091
|
+
x12 ^= u<<13 | u>>>(32-13);
|
|
1092
|
+
u = x12 + x8 | 0;
|
|
1093
|
+
x0 ^= u<<18 | u>>>(32-18);
|
|
1094
|
+
|
|
1095
|
+
u = x5 + x1 | 0;
|
|
1096
|
+
x9 ^= u<<7 | u>>>(32-7);
|
|
1097
|
+
u = x9 + x5 | 0;
|
|
1098
|
+
x13 ^= u<<9 | u>>>(32-9);
|
|
1099
|
+
u = x13 + x9 | 0;
|
|
1100
|
+
x1 ^= u<<13 | u>>>(32-13);
|
|
1101
|
+
u = x1 + x13 | 0;
|
|
1102
|
+
x5 ^= u<<18 | u>>>(32-18);
|
|
1103
|
+
|
|
1104
|
+
u = x10 + x6 | 0;
|
|
1105
|
+
x14 ^= u<<7 | u>>>(32-7);
|
|
1106
|
+
u = x14 + x10 | 0;
|
|
1107
|
+
x2 ^= u<<9 | u>>>(32-9);
|
|
1108
|
+
u = x2 + x14 | 0;
|
|
1109
|
+
x6 ^= u<<13 | u>>>(32-13);
|
|
1110
|
+
u = x6 + x2 | 0;
|
|
1111
|
+
x10 ^= u<<18 | u>>>(32-18);
|
|
1112
|
+
|
|
1113
|
+
u = x15 + x11 | 0;
|
|
1114
|
+
x3 ^= u<<7 | u>>>(32-7);
|
|
1115
|
+
u = x3 + x15 | 0;
|
|
1116
|
+
x7 ^= u<<9 | u>>>(32-9);
|
|
1117
|
+
u = x7 + x3 | 0;
|
|
1118
|
+
x11 ^= u<<13 | u>>>(32-13);
|
|
1119
|
+
u = x11 + x7 | 0;
|
|
1120
|
+
x15 ^= u<<18 | u>>>(32-18);
|
|
1121
|
+
|
|
1122
|
+
u = x0 + x3 | 0;
|
|
1123
|
+
x1 ^= u<<7 | u>>>(32-7);
|
|
1124
|
+
u = x1 + x0 | 0;
|
|
1125
|
+
x2 ^= u<<9 | u>>>(32-9);
|
|
1126
|
+
u = x2 + x1 | 0;
|
|
1127
|
+
x3 ^= u<<13 | u>>>(32-13);
|
|
1128
|
+
u = x3 + x2 | 0;
|
|
1129
|
+
x0 ^= u<<18 | u>>>(32-18);
|
|
1130
|
+
|
|
1131
|
+
u = x5 + x4 | 0;
|
|
1132
|
+
x6 ^= u<<7 | u>>>(32-7);
|
|
1133
|
+
u = x6 + x5 | 0;
|
|
1134
|
+
x7 ^= u<<9 | u>>>(32-9);
|
|
1135
|
+
u = x7 + x6 | 0;
|
|
1136
|
+
x4 ^= u<<13 | u>>>(32-13);
|
|
1137
|
+
u = x4 + x7 | 0;
|
|
1138
|
+
x5 ^= u<<18 | u>>>(32-18);
|
|
1139
|
+
|
|
1140
|
+
u = x10 + x9 | 0;
|
|
1141
|
+
x11 ^= u<<7 | u>>>(32-7);
|
|
1142
|
+
u = x11 + x10 | 0;
|
|
1143
|
+
x8 ^= u<<9 | u>>>(32-9);
|
|
1144
|
+
u = x8 + x11 | 0;
|
|
1145
|
+
x9 ^= u<<13 | u>>>(32-13);
|
|
1146
|
+
u = x9 + x8 | 0;
|
|
1147
|
+
x10 ^= u<<18 | u>>>(32-18);
|
|
1148
|
+
|
|
1149
|
+
u = x15 + x14 | 0;
|
|
1150
|
+
x12 ^= u<<7 | u>>>(32-7);
|
|
1151
|
+
u = x12 + x15 | 0;
|
|
1152
|
+
x13 ^= u<<9 | u>>>(32-9);
|
|
1153
|
+
u = x13 + x12 | 0;
|
|
1154
|
+
x14 ^= u<<13 | u>>>(32-13);
|
|
1155
|
+
u = x14 + x13 | 0;
|
|
1156
|
+
x15 ^= u<<18 | u>>>(32-18);
|
|
1157
|
+
}
|
|
1158
|
+
x0 = x0 + j0 | 0;
|
|
1159
|
+
x1 = x1 + j1 | 0;
|
|
1160
|
+
x2 = x2 + j2 | 0;
|
|
1161
|
+
x3 = x3 + j3 | 0;
|
|
1162
|
+
x4 = x4 + j4 | 0;
|
|
1163
|
+
x5 = x5 + j5 | 0;
|
|
1164
|
+
x6 = x6 + j6 | 0;
|
|
1165
|
+
x7 = x7 + j7 | 0;
|
|
1166
|
+
x8 = x8 + j8 | 0;
|
|
1167
|
+
x9 = x9 + j9 | 0;
|
|
1168
|
+
x10 = x10 + j10 | 0;
|
|
1169
|
+
x11 = x11 + j11 | 0;
|
|
1170
|
+
x12 = x12 + j12 | 0;
|
|
1171
|
+
x13 = x13 + j13 | 0;
|
|
1172
|
+
x14 = x14 + j14 | 0;
|
|
1173
|
+
x15 = x15 + j15 | 0;
|
|
1174
|
+
|
|
1175
|
+
o[ 0] = x0 >>> 0 & 0xff;
|
|
1176
|
+
o[ 1] = x0 >>> 8 & 0xff;
|
|
1177
|
+
o[ 2] = x0 >>> 16 & 0xff;
|
|
1178
|
+
o[ 3] = x0 >>> 24 & 0xff;
|
|
1179
|
+
|
|
1180
|
+
o[ 4] = x1 >>> 0 & 0xff;
|
|
1181
|
+
o[ 5] = x1 >>> 8 & 0xff;
|
|
1182
|
+
o[ 6] = x1 >>> 16 & 0xff;
|
|
1183
|
+
o[ 7] = x1 >>> 24 & 0xff;
|
|
1184
|
+
|
|
1185
|
+
o[ 8] = x2 >>> 0 & 0xff;
|
|
1186
|
+
o[ 9] = x2 >>> 8 & 0xff;
|
|
1187
|
+
o[10] = x2 >>> 16 & 0xff;
|
|
1188
|
+
o[11] = x2 >>> 24 & 0xff;
|
|
1189
|
+
|
|
1190
|
+
o[12] = x3 >>> 0 & 0xff;
|
|
1191
|
+
o[13] = x3 >>> 8 & 0xff;
|
|
1192
|
+
o[14] = x3 >>> 16 & 0xff;
|
|
1193
|
+
o[15] = x3 >>> 24 & 0xff;
|
|
1194
|
+
|
|
1195
|
+
o[16] = x4 >>> 0 & 0xff;
|
|
1196
|
+
o[17] = x4 >>> 8 & 0xff;
|
|
1197
|
+
o[18] = x4 >>> 16 & 0xff;
|
|
1198
|
+
o[19] = x4 >>> 24 & 0xff;
|
|
1199
|
+
|
|
1200
|
+
o[20] = x5 >>> 0 & 0xff;
|
|
1201
|
+
o[21] = x5 >>> 8 & 0xff;
|
|
1202
|
+
o[22] = x5 >>> 16 & 0xff;
|
|
1203
|
+
o[23] = x5 >>> 24 & 0xff;
|
|
1204
|
+
|
|
1205
|
+
o[24] = x6 >>> 0 & 0xff;
|
|
1206
|
+
o[25] = x6 >>> 8 & 0xff;
|
|
1207
|
+
o[26] = x6 >>> 16 & 0xff;
|
|
1208
|
+
o[27] = x6 >>> 24 & 0xff;
|
|
1209
|
+
|
|
1210
|
+
o[28] = x7 >>> 0 & 0xff;
|
|
1211
|
+
o[29] = x7 >>> 8 & 0xff;
|
|
1212
|
+
o[30] = x7 >>> 16 & 0xff;
|
|
1213
|
+
o[31] = x7 >>> 24 & 0xff;
|
|
1214
|
+
|
|
1215
|
+
o[32] = x8 >>> 0 & 0xff;
|
|
1216
|
+
o[33] = x8 >>> 8 & 0xff;
|
|
1217
|
+
o[34] = x8 >>> 16 & 0xff;
|
|
1218
|
+
o[35] = x8 >>> 24 & 0xff;
|
|
1219
|
+
|
|
1220
|
+
o[36] = x9 >>> 0 & 0xff;
|
|
1221
|
+
o[37] = x9 >>> 8 & 0xff;
|
|
1222
|
+
o[38] = x9 >>> 16 & 0xff;
|
|
1223
|
+
o[39] = x9 >>> 24 & 0xff;
|
|
1224
|
+
|
|
1225
|
+
o[40] = x10 >>> 0 & 0xff;
|
|
1226
|
+
o[41] = x10 >>> 8 & 0xff;
|
|
1227
|
+
o[42] = x10 >>> 16 & 0xff;
|
|
1228
|
+
o[43] = x10 >>> 24 & 0xff;
|
|
1229
|
+
|
|
1230
|
+
o[44] = x11 >>> 0 & 0xff;
|
|
1231
|
+
o[45] = x11 >>> 8 & 0xff;
|
|
1232
|
+
o[46] = x11 >>> 16 & 0xff;
|
|
1233
|
+
o[47] = x11 >>> 24 & 0xff;
|
|
1234
|
+
|
|
1235
|
+
o[48] = x12 >>> 0 & 0xff;
|
|
1236
|
+
o[49] = x12 >>> 8 & 0xff;
|
|
1237
|
+
o[50] = x12 >>> 16 & 0xff;
|
|
1238
|
+
o[51] = x12 >>> 24 & 0xff;
|
|
1239
|
+
|
|
1240
|
+
o[52] = x13 >>> 0 & 0xff;
|
|
1241
|
+
o[53] = x13 >>> 8 & 0xff;
|
|
1242
|
+
o[54] = x13 >>> 16 & 0xff;
|
|
1243
|
+
o[55] = x13 >>> 24 & 0xff;
|
|
1244
|
+
|
|
1245
|
+
o[56] = x14 >>> 0 & 0xff;
|
|
1246
|
+
o[57] = x14 >>> 8 & 0xff;
|
|
1247
|
+
o[58] = x14 >>> 16 & 0xff;
|
|
1248
|
+
o[59] = x14 >>> 24 & 0xff;
|
|
1249
|
+
|
|
1250
|
+
o[60] = x15 >>> 0 & 0xff;
|
|
1251
|
+
o[61] = x15 >>> 8 & 0xff;
|
|
1252
|
+
o[62] = x15 >>> 16 & 0xff;
|
|
1253
|
+
o[63] = x15 >>> 24 & 0xff;
|
|
1254
|
+
}
|
|
1255
|
+
|
|
1256
|
+
function core_hsalsa20(o,p,k,c) {
|
|
1257
|
+
var j0 = c[ 0] & 0xff | (c[ 1] & 0xff)<<8 | (c[ 2] & 0xff)<<16 | (c[ 3] & 0xff)<<24,
|
|
1258
|
+
j1 = k[ 0] & 0xff | (k[ 1] & 0xff)<<8 | (k[ 2] & 0xff)<<16 | (k[ 3] & 0xff)<<24,
|
|
1259
|
+
j2 = k[ 4] & 0xff | (k[ 5] & 0xff)<<8 | (k[ 6] & 0xff)<<16 | (k[ 7] & 0xff)<<24,
|
|
1260
|
+
j3 = k[ 8] & 0xff | (k[ 9] & 0xff)<<8 | (k[10] & 0xff)<<16 | (k[11] & 0xff)<<24,
|
|
1261
|
+
j4 = k[12] & 0xff | (k[13] & 0xff)<<8 | (k[14] & 0xff)<<16 | (k[15] & 0xff)<<24,
|
|
1262
|
+
j5 = c[ 4] & 0xff | (c[ 5] & 0xff)<<8 | (c[ 6] & 0xff)<<16 | (c[ 7] & 0xff)<<24,
|
|
1263
|
+
j6 = p[ 0] & 0xff | (p[ 1] & 0xff)<<8 | (p[ 2] & 0xff)<<16 | (p[ 3] & 0xff)<<24,
|
|
1264
|
+
j7 = p[ 4] & 0xff | (p[ 5] & 0xff)<<8 | (p[ 6] & 0xff)<<16 | (p[ 7] & 0xff)<<24,
|
|
1265
|
+
j8 = p[ 8] & 0xff | (p[ 9] & 0xff)<<8 | (p[10] & 0xff)<<16 | (p[11] & 0xff)<<24,
|
|
1266
|
+
j9 = p[12] & 0xff | (p[13] & 0xff)<<8 | (p[14] & 0xff)<<16 | (p[15] & 0xff)<<24,
|
|
1267
|
+
j10 = c[ 8] & 0xff | (c[ 9] & 0xff)<<8 | (c[10] & 0xff)<<16 | (c[11] & 0xff)<<24,
|
|
1268
|
+
j11 = k[16] & 0xff | (k[17] & 0xff)<<8 | (k[18] & 0xff)<<16 | (k[19] & 0xff)<<24,
|
|
1269
|
+
j12 = k[20] & 0xff | (k[21] & 0xff)<<8 | (k[22] & 0xff)<<16 | (k[23] & 0xff)<<24,
|
|
1270
|
+
j13 = k[24] & 0xff | (k[25] & 0xff)<<8 | (k[26] & 0xff)<<16 | (k[27] & 0xff)<<24,
|
|
1271
|
+
j14 = k[28] & 0xff | (k[29] & 0xff)<<8 | (k[30] & 0xff)<<16 | (k[31] & 0xff)<<24,
|
|
1272
|
+
j15 = c[12] & 0xff | (c[13] & 0xff)<<8 | (c[14] & 0xff)<<16 | (c[15] & 0xff)<<24;
|
|
1273
|
+
|
|
1274
|
+
var x0 = j0, x1 = j1, x2 = j2, x3 = j3, x4 = j4, x5 = j5, x6 = j6, x7 = j7,
|
|
1275
|
+
x8 = j8, x9 = j9, x10 = j10, x11 = j11, x12 = j12, x13 = j13, x14 = j14,
|
|
1276
|
+
x15 = j15, u;
|
|
1277
|
+
|
|
1278
|
+
for (var i = 0; i < 20; i += 2) {
|
|
1279
|
+
u = x0 + x12 | 0;
|
|
1280
|
+
x4 ^= u<<7 | u>>>(32-7);
|
|
1281
|
+
u = x4 + x0 | 0;
|
|
1282
|
+
x8 ^= u<<9 | u>>>(32-9);
|
|
1283
|
+
u = x8 + x4 | 0;
|
|
1284
|
+
x12 ^= u<<13 | u>>>(32-13);
|
|
1285
|
+
u = x12 + x8 | 0;
|
|
1286
|
+
x0 ^= u<<18 | u>>>(32-18);
|
|
1287
|
+
|
|
1288
|
+
u = x5 + x1 | 0;
|
|
1289
|
+
x9 ^= u<<7 | u>>>(32-7);
|
|
1290
|
+
u = x9 + x5 | 0;
|
|
1291
|
+
x13 ^= u<<9 | u>>>(32-9);
|
|
1292
|
+
u = x13 + x9 | 0;
|
|
1293
|
+
x1 ^= u<<13 | u>>>(32-13);
|
|
1294
|
+
u = x1 + x13 | 0;
|
|
1295
|
+
x5 ^= u<<18 | u>>>(32-18);
|
|
1296
|
+
|
|
1297
|
+
u = x10 + x6 | 0;
|
|
1298
|
+
x14 ^= u<<7 | u>>>(32-7);
|
|
1299
|
+
u = x14 + x10 | 0;
|
|
1300
|
+
x2 ^= u<<9 | u>>>(32-9);
|
|
1301
|
+
u = x2 + x14 | 0;
|
|
1302
|
+
x6 ^= u<<13 | u>>>(32-13);
|
|
1303
|
+
u = x6 + x2 | 0;
|
|
1304
|
+
x10 ^= u<<18 | u>>>(32-18);
|
|
1305
|
+
|
|
1306
|
+
u = x15 + x11 | 0;
|
|
1307
|
+
x3 ^= u<<7 | u>>>(32-7);
|
|
1308
|
+
u = x3 + x15 | 0;
|
|
1309
|
+
x7 ^= u<<9 | u>>>(32-9);
|
|
1310
|
+
u = x7 + x3 | 0;
|
|
1311
|
+
x11 ^= u<<13 | u>>>(32-13);
|
|
1312
|
+
u = x11 + x7 | 0;
|
|
1313
|
+
x15 ^= u<<18 | u>>>(32-18);
|
|
1314
|
+
|
|
1315
|
+
u = x0 + x3 | 0;
|
|
1316
|
+
x1 ^= u<<7 | u>>>(32-7);
|
|
1317
|
+
u = x1 + x0 | 0;
|
|
1318
|
+
x2 ^= u<<9 | u>>>(32-9);
|
|
1319
|
+
u = x2 + x1 | 0;
|
|
1320
|
+
x3 ^= u<<13 | u>>>(32-13);
|
|
1321
|
+
u = x3 + x2 | 0;
|
|
1322
|
+
x0 ^= u<<18 | u>>>(32-18);
|
|
1323
|
+
|
|
1324
|
+
u = x5 + x4 | 0;
|
|
1325
|
+
x6 ^= u<<7 | u>>>(32-7);
|
|
1326
|
+
u = x6 + x5 | 0;
|
|
1327
|
+
x7 ^= u<<9 | u>>>(32-9);
|
|
1328
|
+
u = x7 + x6 | 0;
|
|
1329
|
+
x4 ^= u<<13 | u>>>(32-13);
|
|
1330
|
+
u = x4 + x7 | 0;
|
|
1331
|
+
x5 ^= u<<18 | u>>>(32-18);
|
|
1332
|
+
|
|
1333
|
+
u = x10 + x9 | 0;
|
|
1334
|
+
x11 ^= u<<7 | u>>>(32-7);
|
|
1335
|
+
u = x11 + x10 | 0;
|
|
1336
|
+
x8 ^= u<<9 | u>>>(32-9);
|
|
1337
|
+
u = x8 + x11 | 0;
|
|
1338
|
+
x9 ^= u<<13 | u>>>(32-13);
|
|
1339
|
+
u = x9 + x8 | 0;
|
|
1340
|
+
x10 ^= u<<18 | u>>>(32-18);
|
|
1341
|
+
|
|
1342
|
+
u = x15 + x14 | 0;
|
|
1343
|
+
x12 ^= u<<7 | u>>>(32-7);
|
|
1344
|
+
u = x12 + x15 | 0;
|
|
1345
|
+
x13 ^= u<<9 | u>>>(32-9);
|
|
1346
|
+
u = x13 + x12 | 0;
|
|
1347
|
+
x14 ^= u<<13 | u>>>(32-13);
|
|
1348
|
+
u = x14 + x13 | 0;
|
|
1349
|
+
x15 ^= u<<18 | u>>>(32-18);
|
|
1350
|
+
}
|
|
1351
|
+
|
|
1352
|
+
o[ 0] = x0 >>> 0 & 0xff;
|
|
1353
|
+
o[ 1] = x0 >>> 8 & 0xff;
|
|
1354
|
+
o[ 2] = x0 >>> 16 & 0xff;
|
|
1355
|
+
o[ 3] = x0 >>> 24 & 0xff;
|
|
1356
|
+
|
|
1357
|
+
o[ 4] = x5 >>> 0 & 0xff;
|
|
1358
|
+
o[ 5] = x5 >>> 8 & 0xff;
|
|
1359
|
+
o[ 6] = x5 >>> 16 & 0xff;
|
|
1360
|
+
o[ 7] = x5 >>> 24 & 0xff;
|
|
1361
|
+
|
|
1362
|
+
o[ 8] = x10 >>> 0 & 0xff;
|
|
1363
|
+
o[ 9] = x10 >>> 8 & 0xff;
|
|
1364
|
+
o[10] = x10 >>> 16 & 0xff;
|
|
1365
|
+
o[11] = x10 >>> 24 & 0xff;
|
|
1366
|
+
|
|
1367
|
+
o[12] = x15 >>> 0 & 0xff;
|
|
1368
|
+
o[13] = x15 >>> 8 & 0xff;
|
|
1369
|
+
o[14] = x15 >>> 16 & 0xff;
|
|
1370
|
+
o[15] = x15 >>> 24 & 0xff;
|
|
1371
|
+
|
|
1372
|
+
o[16] = x6 >>> 0 & 0xff;
|
|
1373
|
+
o[17] = x6 >>> 8 & 0xff;
|
|
1374
|
+
o[18] = x6 >>> 16 & 0xff;
|
|
1375
|
+
o[19] = x6 >>> 24 & 0xff;
|
|
1376
|
+
|
|
1377
|
+
o[20] = x7 >>> 0 & 0xff;
|
|
1378
|
+
o[21] = x7 >>> 8 & 0xff;
|
|
1379
|
+
o[22] = x7 >>> 16 & 0xff;
|
|
1380
|
+
o[23] = x7 >>> 24 & 0xff;
|
|
1381
|
+
|
|
1382
|
+
o[24] = x8 >>> 0 & 0xff;
|
|
1383
|
+
o[25] = x8 >>> 8 & 0xff;
|
|
1384
|
+
o[26] = x8 >>> 16 & 0xff;
|
|
1385
|
+
o[27] = x8 >>> 24 & 0xff;
|
|
1386
|
+
|
|
1387
|
+
o[28] = x9 >>> 0 & 0xff;
|
|
1388
|
+
o[29] = x9 >>> 8 & 0xff;
|
|
1389
|
+
o[30] = x9 >>> 16 & 0xff;
|
|
1390
|
+
o[31] = x9 >>> 24 & 0xff;
|
|
1391
|
+
}
|
|
1392
|
+
|
|
1393
|
+
function crypto_core_salsa20(out,inp,k,c) {
|
|
1394
|
+
core_salsa20(out,inp,k,c);
|
|
1395
|
+
}
|
|
1396
|
+
|
|
1397
|
+
function crypto_core_hsalsa20(out,inp,k,c) {
|
|
1398
|
+
core_hsalsa20(out,inp,k,c);
|
|
1399
|
+
}
|
|
1400
|
+
|
|
1401
|
+
var sigma = new Uint8Array([101, 120, 112, 97, 110, 100, 32, 51, 50, 45, 98, 121, 116, 101, 32, 107]);
|
|
1402
|
+
// "expand 32-byte k"
|
|
1403
|
+
|
|
1404
|
+
function crypto_stream_salsa20_xor(c,cpos,m,mpos,b,n,k) {
|
|
1405
|
+
var z = new Uint8Array(16), x = new Uint8Array(64);
|
|
1406
|
+
var u, i;
|
|
1407
|
+
for (i = 0; i < 16; i++) z[i] = 0;
|
|
1408
|
+
for (i = 0; i < 8; i++) z[i] = n[i];
|
|
1409
|
+
while (b >= 64) {
|
|
1410
|
+
crypto_core_salsa20(x,z,k,sigma);
|
|
1411
|
+
for (i = 0; i < 64; i++) c[cpos+i] = m[mpos+i] ^ x[i];
|
|
1412
|
+
u = 1;
|
|
1413
|
+
for (i = 8; i < 16; i++) {
|
|
1414
|
+
u = u + (z[i] & 0xff) | 0;
|
|
1415
|
+
z[i] = u & 0xff;
|
|
1416
|
+
u >>>= 8;
|
|
1417
|
+
}
|
|
1418
|
+
b -= 64;
|
|
1419
|
+
cpos += 64;
|
|
1420
|
+
mpos += 64;
|
|
1421
|
+
}
|
|
1422
|
+
if (b > 0) {
|
|
1423
|
+
crypto_core_salsa20(x,z,k,sigma);
|
|
1424
|
+
for (i = 0; i < b; i++) c[cpos+i] = m[mpos+i] ^ x[i];
|
|
1425
|
+
}
|
|
1426
|
+
return 0;
|
|
1427
|
+
}
|
|
1428
|
+
|
|
1429
|
+
function crypto_stream_salsa20(c,cpos,b,n,k) {
|
|
1430
|
+
var z = new Uint8Array(16), x = new Uint8Array(64);
|
|
1431
|
+
var u, i;
|
|
1432
|
+
for (i = 0; i < 16; i++) z[i] = 0;
|
|
1433
|
+
for (i = 0; i < 8; i++) z[i] = n[i];
|
|
1434
|
+
while (b >= 64) {
|
|
1435
|
+
crypto_core_salsa20(x,z,k,sigma);
|
|
1436
|
+
for (i = 0; i < 64; i++) c[cpos+i] = x[i];
|
|
1437
|
+
u = 1;
|
|
1438
|
+
for (i = 8; i < 16; i++) {
|
|
1439
|
+
u = u + (z[i] & 0xff) | 0;
|
|
1440
|
+
z[i] = u & 0xff;
|
|
1441
|
+
u >>>= 8;
|
|
1442
|
+
}
|
|
1443
|
+
b -= 64;
|
|
1444
|
+
cpos += 64;
|
|
1445
|
+
}
|
|
1446
|
+
if (b > 0) {
|
|
1447
|
+
crypto_core_salsa20(x,z,k,sigma);
|
|
1448
|
+
for (i = 0; i < b; i++) c[cpos+i] = x[i];
|
|
1449
|
+
}
|
|
1450
|
+
return 0;
|
|
1451
|
+
}
|
|
1452
|
+
|
|
1453
|
+
function crypto_stream(c,cpos,d,n,k) {
|
|
1454
|
+
var s = new Uint8Array(32);
|
|
1455
|
+
crypto_core_hsalsa20(s,n,k,sigma);
|
|
1456
|
+
var sn = new Uint8Array(8);
|
|
1457
|
+
for (var i = 0; i < 8; i++) sn[i] = n[i+16];
|
|
1458
|
+
return crypto_stream_salsa20(c,cpos,d,sn,s);
|
|
1459
|
+
}
|
|
1460
|
+
|
|
1461
|
+
function crypto_stream_xor(c,cpos,m,mpos,d,n,k) {
|
|
1462
|
+
var s = new Uint8Array(32);
|
|
1463
|
+
crypto_core_hsalsa20(s,n,k,sigma);
|
|
1464
|
+
var sn = new Uint8Array(8);
|
|
1465
|
+
for (var i = 0; i < 8; i++) sn[i] = n[i+16];
|
|
1466
|
+
return crypto_stream_salsa20_xor(c,cpos,m,mpos,d,sn,s);
|
|
1467
|
+
}
|
|
1468
|
+
|
|
1469
|
+
/*
|
|
1470
|
+
* Port of Andrew Moon's Poly1305-donna-16. Public domain.
|
|
1471
|
+
* https://github.com/floodyberry/poly1305-donna
|
|
1472
|
+
*/
|
|
1473
|
+
|
|
1474
|
+
var poly1305 = function(key) {
|
|
1475
|
+
this.buffer = new Uint8Array(16);
|
|
1476
|
+
this.r = new Uint16Array(10);
|
|
1477
|
+
this.h = new Uint16Array(10);
|
|
1478
|
+
this.pad = new Uint16Array(8);
|
|
1479
|
+
this.leftover = 0;
|
|
1480
|
+
this.fin = 0;
|
|
1481
|
+
|
|
1482
|
+
var t0, t1, t2, t3, t4, t5, t6, t7;
|
|
1483
|
+
|
|
1484
|
+
t0 = key[ 0] & 0xff | (key[ 1] & 0xff) << 8; this.r[0] = ( t0 ) & 0x1fff;
|
|
1485
|
+
t1 = key[ 2] & 0xff | (key[ 3] & 0xff) << 8; this.r[1] = ((t0 >>> 13) | (t1 << 3)) & 0x1fff;
|
|
1486
|
+
t2 = key[ 4] & 0xff | (key[ 5] & 0xff) << 8; this.r[2] = ((t1 >>> 10) | (t2 << 6)) & 0x1f03;
|
|
1487
|
+
t3 = key[ 6] & 0xff | (key[ 7] & 0xff) << 8; this.r[3] = ((t2 >>> 7) | (t3 << 9)) & 0x1fff;
|
|
1488
|
+
t4 = key[ 8] & 0xff | (key[ 9] & 0xff) << 8; this.r[4] = ((t3 >>> 4) | (t4 << 12)) & 0x00ff;
|
|
1489
|
+
this.r[5] = ((t4 >>> 1)) & 0x1ffe;
|
|
1490
|
+
t5 = key[10] & 0xff | (key[11] & 0xff) << 8; this.r[6] = ((t4 >>> 14) | (t5 << 2)) & 0x1fff;
|
|
1491
|
+
t6 = key[12] & 0xff | (key[13] & 0xff) << 8; this.r[7] = ((t5 >>> 11) | (t6 << 5)) & 0x1f81;
|
|
1492
|
+
t7 = key[14] & 0xff | (key[15] & 0xff) << 8; this.r[8] = ((t6 >>> 8) | (t7 << 8)) & 0x1fff;
|
|
1493
|
+
this.r[9] = ((t7 >>> 5)) & 0x007f;
|
|
1494
|
+
|
|
1495
|
+
this.pad[0] = key[16] & 0xff | (key[17] & 0xff) << 8;
|
|
1496
|
+
this.pad[1] = key[18] & 0xff | (key[19] & 0xff) << 8;
|
|
1497
|
+
this.pad[2] = key[20] & 0xff | (key[21] & 0xff) << 8;
|
|
1498
|
+
this.pad[3] = key[22] & 0xff | (key[23] & 0xff) << 8;
|
|
1499
|
+
this.pad[4] = key[24] & 0xff | (key[25] & 0xff) << 8;
|
|
1500
|
+
this.pad[5] = key[26] & 0xff | (key[27] & 0xff) << 8;
|
|
1501
|
+
this.pad[6] = key[28] & 0xff | (key[29] & 0xff) << 8;
|
|
1502
|
+
this.pad[7] = key[30] & 0xff | (key[31] & 0xff) << 8;
|
|
1503
|
+
};
|
|
1504
|
+
|
|
1505
|
+
poly1305.prototype.blocks = function(m, mpos, bytes) {
|
|
1506
|
+
var hibit = this.fin ? 0 : (1 << 11);
|
|
1507
|
+
var t0, t1, t2, t3, t4, t5, t6, t7, c;
|
|
1508
|
+
var d0, d1, d2, d3, d4, d5, d6, d7, d8, d9;
|
|
1509
|
+
|
|
1510
|
+
var h0 = this.h[0],
|
|
1511
|
+
h1 = this.h[1],
|
|
1512
|
+
h2 = this.h[2],
|
|
1513
|
+
h3 = this.h[3],
|
|
1514
|
+
h4 = this.h[4],
|
|
1515
|
+
h5 = this.h[5],
|
|
1516
|
+
h6 = this.h[6],
|
|
1517
|
+
h7 = this.h[7],
|
|
1518
|
+
h8 = this.h[8],
|
|
1519
|
+
h9 = this.h[9];
|
|
1520
|
+
|
|
1521
|
+
var r0 = this.r[0],
|
|
1522
|
+
r1 = this.r[1],
|
|
1523
|
+
r2 = this.r[2],
|
|
1524
|
+
r3 = this.r[3],
|
|
1525
|
+
r4 = this.r[4],
|
|
1526
|
+
r5 = this.r[5],
|
|
1527
|
+
r6 = this.r[6],
|
|
1528
|
+
r7 = this.r[7],
|
|
1529
|
+
r8 = this.r[8],
|
|
1530
|
+
r9 = this.r[9];
|
|
1531
|
+
|
|
1532
|
+
while (bytes >= 16) {
|
|
1533
|
+
t0 = m[mpos+ 0] & 0xff | (m[mpos+ 1] & 0xff) << 8; h0 += ( t0 ) & 0x1fff;
|
|
1534
|
+
t1 = m[mpos+ 2] & 0xff | (m[mpos+ 3] & 0xff) << 8; h1 += ((t0 >>> 13) | (t1 << 3)) & 0x1fff;
|
|
1535
|
+
t2 = m[mpos+ 4] & 0xff | (m[mpos+ 5] & 0xff) << 8; h2 += ((t1 >>> 10) | (t2 << 6)) & 0x1fff;
|
|
1536
|
+
t3 = m[mpos+ 6] & 0xff | (m[mpos+ 7] & 0xff) << 8; h3 += ((t2 >>> 7) | (t3 << 9)) & 0x1fff;
|
|
1537
|
+
t4 = m[mpos+ 8] & 0xff | (m[mpos+ 9] & 0xff) << 8; h4 += ((t3 >>> 4) | (t4 << 12)) & 0x1fff;
|
|
1538
|
+
h5 += ((t4 >>> 1)) & 0x1fff;
|
|
1539
|
+
t5 = m[mpos+10] & 0xff | (m[mpos+11] & 0xff) << 8; h6 += ((t4 >>> 14) | (t5 << 2)) & 0x1fff;
|
|
1540
|
+
t6 = m[mpos+12] & 0xff | (m[mpos+13] & 0xff) << 8; h7 += ((t5 >>> 11) | (t6 << 5)) & 0x1fff;
|
|
1541
|
+
t7 = m[mpos+14] & 0xff | (m[mpos+15] & 0xff) << 8; h8 += ((t6 >>> 8) | (t7 << 8)) & 0x1fff;
|
|
1542
|
+
h9 += ((t7 >>> 5)) | hibit;
|
|
1543
|
+
|
|
1544
|
+
c = 0;
|
|
1545
|
+
|
|
1546
|
+
d0 = c;
|
|
1547
|
+
d0 += h0 * r0;
|
|
1548
|
+
d0 += h1 * (5 * r9);
|
|
1549
|
+
d0 += h2 * (5 * r8);
|
|
1550
|
+
d0 += h3 * (5 * r7);
|
|
1551
|
+
d0 += h4 * (5 * r6);
|
|
1552
|
+
c = (d0 >>> 13); d0 &= 0x1fff;
|
|
1553
|
+
d0 += h5 * (5 * r5);
|
|
1554
|
+
d0 += h6 * (5 * r4);
|
|
1555
|
+
d0 += h7 * (5 * r3);
|
|
1556
|
+
d0 += h8 * (5 * r2);
|
|
1557
|
+
d0 += h9 * (5 * r1);
|
|
1558
|
+
c += (d0 >>> 13); d0 &= 0x1fff;
|
|
1559
|
+
|
|
1560
|
+
d1 = c;
|
|
1561
|
+
d1 += h0 * r1;
|
|
1562
|
+
d1 += h1 * r0;
|
|
1563
|
+
d1 += h2 * (5 * r9);
|
|
1564
|
+
d1 += h3 * (5 * r8);
|
|
1565
|
+
d1 += h4 * (5 * r7);
|
|
1566
|
+
c = (d1 >>> 13); d1 &= 0x1fff;
|
|
1567
|
+
d1 += h5 * (5 * r6);
|
|
1568
|
+
d1 += h6 * (5 * r5);
|
|
1569
|
+
d1 += h7 * (5 * r4);
|
|
1570
|
+
d1 += h8 * (5 * r3);
|
|
1571
|
+
d1 += h9 * (5 * r2);
|
|
1572
|
+
c += (d1 >>> 13); d1 &= 0x1fff;
|
|
1573
|
+
|
|
1574
|
+
d2 = c;
|
|
1575
|
+
d2 += h0 * r2;
|
|
1576
|
+
d2 += h1 * r1;
|
|
1577
|
+
d2 += h2 * r0;
|
|
1578
|
+
d2 += h3 * (5 * r9);
|
|
1579
|
+
d2 += h4 * (5 * r8);
|
|
1580
|
+
c = (d2 >>> 13); d2 &= 0x1fff;
|
|
1581
|
+
d2 += h5 * (5 * r7);
|
|
1582
|
+
d2 += h6 * (5 * r6);
|
|
1583
|
+
d2 += h7 * (5 * r5);
|
|
1584
|
+
d2 += h8 * (5 * r4);
|
|
1585
|
+
d2 += h9 * (5 * r3);
|
|
1586
|
+
c += (d2 >>> 13); d2 &= 0x1fff;
|
|
1587
|
+
|
|
1588
|
+
d3 = c;
|
|
1589
|
+
d3 += h0 * r3;
|
|
1590
|
+
d3 += h1 * r2;
|
|
1591
|
+
d3 += h2 * r1;
|
|
1592
|
+
d3 += h3 * r0;
|
|
1593
|
+
d3 += h4 * (5 * r9);
|
|
1594
|
+
c = (d3 >>> 13); d3 &= 0x1fff;
|
|
1595
|
+
d3 += h5 * (5 * r8);
|
|
1596
|
+
d3 += h6 * (5 * r7);
|
|
1597
|
+
d3 += h7 * (5 * r6);
|
|
1598
|
+
d3 += h8 * (5 * r5);
|
|
1599
|
+
d3 += h9 * (5 * r4);
|
|
1600
|
+
c += (d3 >>> 13); d3 &= 0x1fff;
|
|
1601
|
+
|
|
1602
|
+
d4 = c;
|
|
1603
|
+
d4 += h0 * r4;
|
|
1604
|
+
d4 += h1 * r3;
|
|
1605
|
+
d4 += h2 * r2;
|
|
1606
|
+
d4 += h3 * r1;
|
|
1607
|
+
d4 += h4 * r0;
|
|
1608
|
+
c = (d4 >>> 13); d4 &= 0x1fff;
|
|
1609
|
+
d4 += h5 * (5 * r9);
|
|
1610
|
+
d4 += h6 * (5 * r8);
|
|
1611
|
+
d4 += h7 * (5 * r7);
|
|
1612
|
+
d4 += h8 * (5 * r6);
|
|
1613
|
+
d4 += h9 * (5 * r5);
|
|
1614
|
+
c += (d4 >>> 13); d4 &= 0x1fff;
|
|
1615
|
+
|
|
1616
|
+
d5 = c;
|
|
1617
|
+
d5 += h0 * r5;
|
|
1618
|
+
d5 += h1 * r4;
|
|
1619
|
+
d5 += h2 * r3;
|
|
1620
|
+
d5 += h3 * r2;
|
|
1621
|
+
d5 += h4 * r1;
|
|
1622
|
+
c = (d5 >>> 13); d5 &= 0x1fff;
|
|
1623
|
+
d5 += h5 * r0;
|
|
1624
|
+
d5 += h6 * (5 * r9);
|
|
1625
|
+
d5 += h7 * (5 * r8);
|
|
1626
|
+
d5 += h8 * (5 * r7);
|
|
1627
|
+
d5 += h9 * (5 * r6);
|
|
1628
|
+
c += (d5 >>> 13); d5 &= 0x1fff;
|
|
1629
|
+
|
|
1630
|
+
d6 = c;
|
|
1631
|
+
d6 += h0 * r6;
|
|
1632
|
+
d6 += h1 * r5;
|
|
1633
|
+
d6 += h2 * r4;
|
|
1634
|
+
d6 += h3 * r3;
|
|
1635
|
+
d6 += h4 * r2;
|
|
1636
|
+
c = (d6 >>> 13); d6 &= 0x1fff;
|
|
1637
|
+
d6 += h5 * r1;
|
|
1638
|
+
d6 += h6 * r0;
|
|
1639
|
+
d6 += h7 * (5 * r9);
|
|
1640
|
+
d6 += h8 * (5 * r8);
|
|
1641
|
+
d6 += h9 * (5 * r7);
|
|
1642
|
+
c += (d6 >>> 13); d6 &= 0x1fff;
|
|
1643
|
+
|
|
1644
|
+
d7 = c;
|
|
1645
|
+
d7 += h0 * r7;
|
|
1646
|
+
d7 += h1 * r6;
|
|
1647
|
+
d7 += h2 * r5;
|
|
1648
|
+
d7 += h3 * r4;
|
|
1649
|
+
d7 += h4 * r3;
|
|
1650
|
+
c = (d7 >>> 13); d7 &= 0x1fff;
|
|
1651
|
+
d7 += h5 * r2;
|
|
1652
|
+
d7 += h6 * r1;
|
|
1653
|
+
d7 += h7 * r0;
|
|
1654
|
+
d7 += h8 * (5 * r9);
|
|
1655
|
+
d7 += h9 * (5 * r8);
|
|
1656
|
+
c += (d7 >>> 13); d7 &= 0x1fff;
|
|
1657
|
+
|
|
1658
|
+
d8 = c;
|
|
1659
|
+
d8 += h0 * r8;
|
|
1660
|
+
d8 += h1 * r7;
|
|
1661
|
+
d8 += h2 * r6;
|
|
1662
|
+
d8 += h3 * r5;
|
|
1663
|
+
d8 += h4 * r4;
|
|
1664
|
+
c = (d8 >>> 13); d8 &= 0x1fff;
|
|
1665
|
+
d8 += h5 * r3;
|
|
1666
|
+
d8 += h6 * r2;
|
|
1667
|
+
d8 += h7 * r1;
|
|
1668
|
+
d8 += h8 * r0;
|
|
1669
|
+
d8 += h9 * (5 * r9);
|
|
1670
|
+
c += (d8 >>> 13); d8 &= 0x1fff;
|
|
1671
|
+
|
|
1672
|
+
d9 = c;
|
|
1673
|
+
d9 += h0 * r9;
|
|
1674
|
+
d9 += h1 * r8;
|
|
1675
|
+
d9 += h2 * r7;
|
|
1676
|
+
d9 += h3 * r6;
|
|
1677
|
+
d9 += h4 * r5;
|
|
1678
|
+
c = (d9 >>> 13); d9 &= 0x1fff;
|
|
1679
|
+
d9 += h5 * r4;
|
|
1680
|
+
d9 += h6 * r3;
|
|
1681
|
+
d9 += h7 * r2;
|
|
1682
|
+
d9 += h8 * r1;
|
|
1683
|
+
d9 += h9 * r0;
|
|
1684
|
+
c += (d9 >>> 13); d9 &= 0x1fff;
|
|
1685
|
+
|
|
1686
|
+
c = (((c << 2) + c)) | 0;
|
|
1687
|
+
c = (c + d0) | 0;
|
|
1688
|
+
d0 = c & 0x1fff;
|
|
1689
|
+
c = (c >>> 13);
|
|
1690
|
+
d1 += c;
|
|
1691
|
+
|
|
1692
|
+
h0 = d0;
|
|
1693
|
+
h1 = d1;
|
|
1694
|
+
h2 = d2;
|
|
1695
|
+
h3 = d3;
|
|
1696
|
+
h4 = d4;
|
|
1697
|
+
h5 = d5;
|
|
1698
|
+
h6 = d6;
|
|
1699
|
+
h7 = d7;
|
|
1700
|
+
h8 = d8;
|
|
1701
|
+
h9 = d9;
|
|
1702
|
+
|
|
1703
|
+
mpos += 16;
|
|
1704
|
+
bytes -= 16;
|
|
1705
|
+
}
|
|
1706
|
+
this.h[0] = h0;
|
|
1707
|
+
this.h[1] = h1;
|
|
1708
|
+
this.h[2] = h2;
|
|
1709
|
+
this.h[3] = h3;
|
|
1710
|
+
this.h[4] = h4;
|
|
1711
|
+
this.h[5] = h5;
|
|
1712
|
+
this.h[6] = h6;
|
|
1713
|
+
this.h[7] = h7;
|
|
1714
|
+
this.h[8] = h8;
|
|
1715
|
+
this.h[9] = h9;
|
|
1716
|
+
};
|
|
1717
|
+
|
|
1718
|
+
poly1305.prototype.finish = function(mac, macpos) {
|
|
1719
|
+
var g = new Uint16Array(10);
|
|
1720
|
+
var c, mask, f, i;
|
|
1721
|
+
|
|
1722
|
+
if (this.leftover) {
|
|
1723
|
+
i = this.leftover;
|
|
1724
|
+
this.buffer[i++] = 1;
|
|
1725
|
+
for (; i < 16; i++) this.buffer[i] = 0;
|
|
1726
|
+
this.fin = 1;
|
|
1727
|
+
this.blocks(this.buffer, 0, 16);
|
|
1728
|
+
}
|
|
1729
|
+
|
|
1730
|
+
c = this.h[1] >>> 13;
|
|
1731
|
+
this.h[1] &= 0x1fff;
|
|
1732
|
+
for (i = 2; i < 10; i++) {
|
|
1733
|
+
this.h[i] += c;
|
|
1734
|
+
c = this.h[i] >>> 13;
|
|
1735
|
+
this.h[i] &= 0x1fff;
|
|
1736
|
+
}
|
|
1737
|
+
this.h[0] += (c * 5);
|
|
1738
|
+
c = this.h[0] >>> 13;
|
|
1739
|
+
this.h[0] &= 0x1fff;
|
|
1740
|
+
this.h[1] += c;
|
|
1741
|
+
c = this.h[1] >>> 13;
|
|
1742
|
+
this.h[1] &= 0x1fff;
|
|
1743
|
+
this.h[2] += c;
|
|
1744
|
+
|
|
1745
|
+
g[0] = this.h[0] + 5;
|
|
1746
|
+
c = g[0] >>> 13;
|
|
1747
|
+
g[0] &= 0x1fff;
|
|
1748
|
+
for (i = 1; i < 10; i++) {
|
|
1749
|
+
g[i] = this.h[i] + c;
|
|
1750
|
+
c = g[i] >>> 13;
|
|
1751
|
+
g[i] &= 0x1fff;
|
|
1752
|
+
}
|
|
1753
|
+
g[9] -= (1 << 13);
|
|
1754
|
+
|
|
1755
|
+
mask = (c ^ 1) - 1;
|
|
1756
|
+
for (i = 0; i < 10; i++) g[i] &= mask;
|
|
1757
|
+
mask = ~mask;
|
|
1758
|
+
for (i = 0; i < 10; i++) this.h[i] = (this.h[i] & mask) | g[i];
|
|
1759
|
+
|
|
1760
|
+
this.h[0] = ((this.h[0] ) | (this.h[1] << 13) ) & 0xffff;
|
|
1761
|
+
this.h[1] = ((this.h[1] >>> 3) | (this.h[2] << 10) ) & 0xffff;
|
|
1762
|
+
this.h[2] = ((this.h[2] >>> 6) | (this.h[3] << 7) ) & 0xffff;
|
|
1763
|
+
this.h[3] = ((this.h[3] >>> 9) | (this.h[4] << 4) ) & 0xffff;
|
|
1764
|
+
this.h[4] = ((this.h[4] >>> 12) | (this.h[5] << 1) | (this.h[6] << 14)) & 0xffff;
|
|
1765
|
+
this.h[5] = ((this.h[6] >>> 2) | (this.h[7] << 11) ) & 0xffff;
|
|
1766
|
+
this.h[6] = ((this.h[7] >>> 5) | (this.h[8] << 8) ) & 0xffff;
|
|
1767
|
+
this.h[7] = ((this.h[8] >>> 8) | (this.h[9] << 5) ) & 0xffff;
|
|
1768
|
+
|
|
1769
|
+
f = this.h[0] + this.pad[0];
|
|
1770
|
+
this.h[0] = f & 0xffff;
|
|
1771
|
+
for (i = 1; i < 8; i++) {
|
|
1772
|
+
f = (((this.h[i] + this.pad[i]) | 0) + (f >>> 16)) | 0;
|
|
1773
|
+
this.h[i] = f & 0xffff;
|
|
1774
|
+
}
|
|
1775
|
+
|
|
1776
|
+
mac[macpos+ 0] = (this.h[0] >>> 0) & 0xff;
|
|
1777
|
+
mac[macpos+ 1] = (this.h[0] >>> 8) & 0xff;
|
|
1778
|
+
mac[macpos+ 2] = (this.h[1] >>> 0) & 0xff;
|
|
1779
|
+
mac[macpos+ 3] = (this.h[1] >>> 8) & 0xff;
|
|
1780
|
+
mac[macpos+ 4] = (this.h[2] >>> 0) & 0xff;
|
|
1781
|
+
mac[macpos+ 5] = (this.h[2] >>> 8) & 0xff;
|
|
1782
|
+
mac[macpos+ 6] = (this.h[3] >>> 0) & 0xff;
|
|
1783
|
+
mac[macpos+ 7] = (this.h[3] >>> 8) & 0xff;
|
|
1784
|
+
mac[macpos+ 8] = (this.h[4] >>> 0) & 0xff;
|
|
1785
|
+
mac[macpos+ 9] = (this.h[4] >>> 8) & 0xff;
|
|
1786
|
+
mac[macpos+10] = (this.h[5] >>> 0) & 0xff;
|
|
1787
|
+
mac[macpos+11] = (this.h[5] >>> 8) & 0xff;
|
|
1788
|
+
mac[macpos+12] = (this.h[6] >>> 0) & 0xff;
|
|
1789
|
+
mac[macpos+13] = (this.h[6] >>> 8) & 0xff;
|
|
1790
|
+
mac[macpos+14] = (this.h[7] >>> 0) & 0xff;
|
|
1791
|
+
mac[macpos+15] = (this.h[7] >>> 8) & 0xff;
|
|
1792
|
+
};
|
|
1793
|
+
|
|
1794
|
+
poly1305.prototype.update = function(m, mpos, bytes) {
|
|
1795
|
+
var i, want;
|
|
1796
|
+
|
|
1797
|
+
if (this.leftover) {
|
|
1798
|
+
want = (16 - this.leftover);
|
|
1799
|
+
if (want > bytes)
|
|
1800
|
+
want = bytes;
|
|
1801
|
+
for (i = 0; i < want; i++)
|
|
1802
|
+
this.buffer[this.leftover + i] = m[mpos+i];
|
|
1803
|
+
bytes -= want;
|
|
1804
|
+
mpos += want;
|
|
1805
|
+
this.leftover += want;
|
|
1806
|
+
if (this.leftover < 16)
|
|
1807
|
+
return;
|
|
1808
|
+
this.blocks(this.buffer, 0, 16);
|
|
1809
|
+
this.leftover = 0;
|
|
1810
|
+
}
|
|
1811
|
+
|
|
1812
|
+
if (bytes >= 16) {
|
|
1813
|
+
want = bytes - (bytes % 16);
|
|
1814
|
+
this.blocks(m, mpos, want);
|
|
1815
|
+
mpos += want;
|
|
1816
|
+
bytes -= want;
|
|
1817
|
+
}
|
|
1818
|
+
|
|
1819
|
+
if (bytes) {
|
|
1820
|
+
for (i = 0; i < bytes; i++)
|
|
1821
|
+
this.buffer[this.leftover + i] = m[mpos+i];
|
|
1822
|
+
this.leftover += bytes;
|
|
1823
|
+
}
|
|
1824
|
+
};
|
|
1825
|
+
|
|
1826
|
+
function crypto_onetimeauth(out, outpos, m, mpos, n, k) {
|
|
1827
|
+
var s = new poly1305(k);
|
|
1828
|
+
s.update(m, mpos, n);
|
|
1829
|
+
s.finish(out, outpos);
|
|
1830
|
+
return 0;
|
|
1831
|
+
}
|
|
1832
|
+
|
|
1833
|
+
function crypto_onetimeauth_verify(h, hpos, m, mpos, n, k) {
|
|
1834
|
+
var x = new Uint8Array(16);
|
|
1835
|
+
crypto_onetimeauth(x,0,m,mpos,n,k);
|
|
1836
|
+
return crypto_verify_16(h,hpos,x,0);
|
|
1837
|
+
}
|
|
1838
|
+
|
|
1839
|
+
function crypto_secretbox(c,m,d,n,k) {
|
|
1840
|
+
var i;
|
|
1841
|
+
if (d < 32) return -1;
|
|
1842
|
+
crypto_stream_xor(c,0,m,0,d,n,k);
|
|
1843
|
+
crypto_onetimeauth(c, 16, c, 32, d - 32, c);
|
|
1844
|
+
for (i = 0; i < 16; i++) c[i] = 0;
|
|
1845
|
+
return 0;
|
|
1846
|
+
}
|
|
1847
|
+
|
|
1848
|
+
function crypto_secretbox_open(m,c,d,n,k) {
|
|
1849
|
+
var i;
|
|
1850
|
+
var x = new Uint8Array(32);
|
|
1851
|
+
if (d < 32) return -1;
|
|
1852
|
+
crypto_stream(x,0,32,n,k);
|
|
1853
|
+
if (crypto_onetimeauth_verify(c, 16,c, 32,d - 32,x) !== 0) return -1;
|
|
1854
|
+
crypto_stream_xor(m,0,c,0,d,n,k);
|
|
1855
|
+
for (i = 0; i < 32; i++) m[i] = 0;
|
|
1856
|
+
return 0;
|
|
1857
|
+
}
|
|
1858
|
+
|
|
1859
|
+
function set25519(r, a) {
|
|
1860
|
+
var i;
|
|
1861
|
+
for (i = 0; i < 16; i++) r[i] = a[i]|0;
|
|
1862
|
+
}
|
|
1863
|
+
|
|
1864
|
+
function car25519(o) {
|
|
1865
|
+
var i, v, c = 1;
|
|
1866
|
+
for (i = 0; i < 16; i++) {
|
|
1867
|
+
v = o[i] + c + 65535;
|
|
1868
|
+
c = Math.floor(v / 65536);
|
|
1869
|
+
o[i] = v - c * 65536;
|
|
1870
|
+
}
|
|
1871
|
+
o[0] += c-1 + 37 * (c-1);
|
|
1872
|
+
}
|
|
1873
|
+
|
|
1874
|
+
function sel25519(p, q, b) {
|
|
1875
|
+
var t, c = ~(b-1);
|
|
1876
|
+
for (var i = 0; i < 16; i++) {
|
|
1877
|
+
t = c & (p[i] ^ q[i]);
|
|
1878
|
+
p[i] ^= t;
|
|
1879
|
+
q[i] ^= t;
|
|
1880
|
+
}
|
|
1881
|
+
}
|
|
1882
|
+
|
|
1883
|
+
function pack25519(o, n) {
|
|
1884
|
+
var i, j, b;
|
|
1885
|
+
var m = gf(), t = gf();
|
|
1886
|
+
for (i = 0; i < 16; i++) t[i] = n[i];
|
|
1887
|
+
car25519(t);
|
|
1888
|
+
car25519(t);
|
|
1889
|
+
car25519(t);
|
|
1890
|
+
for (j = 0; j < 2; j++) {
|
|
1891
|
+
m[0] = t[0] - 0xffed;
|
|
1892
|
+
for (i = 1; i < 15; i++) {
|
|
1893
|
+
m[i] = t[i] - 0xffff - ((m[i-1]>>16) & 1);
|
|
1894
|
+
m[i-1] &= 0xffff;
|
|
1895
|
+
}
|
|
1896
|
+
m[15] = t[15] - 0x7fff - ((m[14]>>16) & 1);
|
|
1897
|
+
b = (m[15]>>16) & 1;
|
|
1898
|
+
m[14] &= 0xffff;
|
|
1899
|
+
sel25519(t, m, 1-b);
|
|
1900
|
+
}
|
|
1901
|
+
for (i = 0; i < 16; i++) {
|
|
1902
|
+
o[2*i] = t[i] & 0xff;
|
|
1903
|
+
o[2*i+1] = t[i]>>8;
|
|
1904
|
+
}
|
|
1905
|
+
}
|
|
1906
|
+
|
|
1907
|
+
function neq25519(a, b) {
|
|
1908
|
+
var c = new Uint8Array(32), d = new Uint8Array(32);
|
|
1909
|
+
pack25519(c, a);
|
|
1910
|
+
pack25519(d, b);
|
|
1911
|
+
return crypto_verify_32(c, 0, d, 0);
|
|
1912
|
+
}
|
|
1913
|
+
|
|
1914
|
+
function par25519(a) {
|
|
1915
|
+
var d = new Uint8Array(32);
|
|
1916
|
+
pack25519(d, a);
|
|
1917
|
+
return d[0] & 1;
|
|
1918
|
+
}
|
|
1919
|
+
|
|
1920
|
+
function unpack25519(o, n) {
|
|
1921
|
+
var i;
|
|
1922
|
+
for (i = 0; i < 16; i++) o[i] = n[2*i] + (n[2*i+1] << 8);
|
|
1923
|
+
o[15] &= 0x7fff;
|
|
1924
|
+
}
|
|
1925
|
+
|
|
1926
|
+
function A(o, a, b) {
|
|
1927
|
+
for (var i = 0; i < 16; i++) o[i] = a[i] + b[i];
|
|
1928
|
+
}
|
|
1929
|
+
|
|
1930
|
+
function Z(o, a, b) {
|
|
1931
|
+
for (var i = 0; i < 16; i++) o[i] = a[i] - b[i];
|
|
1932
|
+
}
|
|
1933
|
+
|
|
1934
|
+
function M(o, a, b) {
|
|
1935
|
+
var v, c,
|
|
1936
|
+
t0 = 0, t1 = 0, t2 = 0, t3 = 0, t4 = 0, t5 = 0, t6 = 0, t7 = 0,
|
|
1937
|
+
t8 = 0, t9 = 0, t10 = 0, t11 = 0, t12 = 0, t13 = 0, t14 = 0, t15 = 0,
|
|
1938
|
+
t16 = 0, t17 = 0, t18 = 0, t19 = 0, t20 = 0, t21 = 0, t22 = 0, t23 = 0,
|
|
1939
|
+
t24 = 0, t25 = 0, t26 = 0, t27 = 0, t28 = 0, t29 = 0, t30 = 0,
|
|
1940
|
+
b0 = b[0],
|
|
1941
|
+
b1 = b[1],
|
|
1942
|
+
b2 = b[2],
|
|
1943
|
+
b3 = b[3],
|
|
1944
|
+
b4 = b[4],
|
|
1945
|
+
b5 = b[5],
|
|
1946
|
+
b6 = b[6],
|
|
1947
|
+
b7 = b[7],
|
|
1948
|
+
b8 = b[8],
|
|
1949
|
+
b9 = b[9],
|
|
1950
|
+
b10 = b[10],
|
|
1951
|
+
b11 = b[11],
|
|
1952
|
+
b12 = b[12],
|
|
1953
|
+
b13 = b[13],
|
|
1954
|
+
b14 = b[14],
|
|
1955
|
+
b15 = b[15];
|
|
1956
|
+
|
|
1957
|
+
v = a[0];
|
|
1958
|
+
t0 += v * b0;
|
|
1959
|
+
t1 += v * b1;
|
|
1960
|
+
t2 += v * b2;
|
|
1961
|
+
t3 += v * b3;
|
|
1962
|
+
t4 += v * b4;
|
|
1963
|
+
t5 += v * b5;
|
|
1964
|
+
t6 += v * b6;
|
|
1965
|
+
t7 += v * b7;
|
|
1966
|
+
t8 += v * b8;
|
|
1967
|
+
t9 += v * b9;
|
|
1968
|
+
t10 += v * b10;
|
|
1969
|
+
t11 += v * b11;
|
|
1970
|
+
t12 += v * b12;
|
|
1971
|
+
t13 += v * b13;
|
|
1972
|
+
t14 += v * b14;
|
|
1973
|
+
t15 += v * b15;
|
|
1974
|
+
v = a[1];
|
|
1975
|
+
t1 += v * b0;
|
|
1976
|
+
t2 += v * b1;
|
|
1977
|
+
t3 += v * b2;
|
|
1978
|
+
t4 += v * b3;
|
|
1979
|
+
t5 += v * b4;
|
|
1980
|
+
t6 += v * b5;
|
|
1981
|
+
t7 += v * b6;
|
|
1982
|
+
t8 += v * b7;
|
|
1983
|
+
t9 += v * b8;
|
|
1984
|
+
t10 += v * b9;
|
|
1985
|
+
t11 += v * b10;
|
|
1986
|
+
t12 += v * b11;
|
|
1987
|
+
t13 += v * b12;
|
|
1988
|
+
t14 += v * b13;
|
|
1989
|
+
t15 += v * b14;
|
|
1990
|
+
t16 += v * b15;
|
|
1991
|
+
v = a[2];
|
|
1992
|
+
t2 += v * b0;
|
|
1993
|
+
t3 += v * b1;
|
|
1994
|
+
t4 += v * b2;
|
|
1995
|
+
t5 += v * b3;
|
|
1996
|
+
t6 += v * b4;
|
|
1997
|
+
t7 += v * b5;
|
|
1998
|
+
t8 += v * b6;
|
|
1999
|
+
t9 += v * b7;
|
|
2000
|
+
t10 += v * b8;
|
|
2001
|
+
t11 += v * b9;
|
|
2002
|
+
t12 += v * b10;
|
|
2003
|
+
t13 += v * b11;
|
|
2004
|
+
t14 += v * b12;
|
|
2005
|
+
t15 += v * b13;
|
|
2006
|
+
t16 += v * b14;
|
|
2007
|
+
t17 += v * b15;
|
|
2008
|
+
v = a[3];
|
|
2009
|
+
t3 += v * b0;
|
|
2010
|
+
t4 += v * b1;
|
|
2011
|
+
t5 += v * b2;
|
|
2012
|
+
t6 += v * b3;
|
|
2013
|
+
t7 += v * b4;
|
|
2014
|
+
t8 += v * b5;
|
|
2015
|
+
t9 += v * b6;
|
|
2016
|
+
t10 += v * b7;
|
|
2017
|
+
t11 += v * b8;
|
|
2018
|
+
t12 += v * b9;
|
|
2019
|
+
t13 += v * b10;
|
|
2020
|
+
t14 += v * b11;
|
|
2021
|
+
t15 += v * b12;
|
|
2022
|
+
t16 += v * b13;
|
|
2023
|
+
t17 += v * b14;
|
|
2024
|
+
t18 += v * b15;
|
|
2025
|
+
v = a[4];
|
|
2026
|
+
t4 += v * b0;
|
|
2027
|
+
t5 += v * b1;
|
|
2028
|
+
t6 += v * b2;
|
|
2029
|
+
t7 += v * b3;
|
|
2030
|
+
t8 += v * b4;
|
|
2031
|
+
t9 += v * b5;
|
|
2032
|
+
t10 += v * b6;
|
|
2033
|
+
t11 += v * b7;
|
|
2034
|
+
t12 += v * b8;
|
|
2035
|
+
t13 += v * b9;
|
|
2036
|
+
t14 += v * b10;
|
|
2037
|
+
t15 += v * b11;
|
|
2038
|
+
t16 += v * b12;
|
|
2039
|
+
t17 += v * b13;
|
|
2040
|
+
t18 += v * b14;
|
|
2041
|
+
t19 += v * b15;
|
|
2042
|
+
v = a[5];
|
|
2043
|
+
t5 += v * b0;
|
|
2044
|
+
t6 += v * b1;
|
|
2045
|
+
t7 += v * b2;
|
|
2046
|
+
t8 += v * b3;
|
|
2047
|
+
t9 += v * b4;
|
|
2048
|
+
t10 += v * b5;
|
|
2049
|
+
t11 += v * b6;
|
|
2050
|
+
t12 += v * b7;
|
|
2051
|
+
t13 += v * b8;
|
|
2052
|
+
t14 += v * b9;
|
|
2053
|
+
t15 += v * b10;
|
|
2054
|
+
t16 += v * b11;
|
|
2055
|
+
t17 += v * b12;
|
|
2056
|
+
t18 += v * b13;
|
|
2057
|
+
t19 += v * b14;
|
|
2058
|
+
t20 += v * b15;
|
|
2059
|
+
v = a[6];
|
|
2060
|
+
t6 += v * b0;
|
|
2061
|
+
t7 += v * b1;
|
|
2062
|
+
t8 += v * b2;
|
|
2063
|
+
t9 += v * b3;
|
|
2064
|
+
t10 += v * b4;
|
|
2065
|
+
t11 += v * b5;
|
|
2066
|
+
t12 += v * b6;
|
|
2067
|
+
t13 += v * b7;
|
|
2068
|
+
t14 += v * b8;
|
|
2069
|
+
t15 += v * b9;
|
|
2070
|
+
t16 += v * b10;
|
|
2071
|
+
t17 += v * b11;
|
|
2072
|
+
t18 += v * b12;
|
|
2073
|
+
t19 += v * b13;
|
|
2074
|
+
t20 += v * b14;
|
|
2075
|
+
t21 += v * b15;
|
|
2076
|
+
v = a[7];
|
|
2077
|
+
t7 += v * b0;
|
|
2078
|
+
t8 += v * b1;
|
|
2079
|
+
t9 += v * b2;
|
|
2080
|
+
t10 += v * b3;
|
|
2081
|
+
t11 += v * b4;
|
|
2082
|
+
t12 += v * b5;
|
|
2083
|
+
t13 += v * b6;
|
|
2084
|
+
t14 += v * b7;
|
|
2085
|
+
t15 += v * b8;
|
|
2086
|
+
t16 += v * b9;
|
|
2087
|
+
t17 += v * b10;
|
|
2088
|
+
t18 += v * b11;
|
|
2089
|
+
t19 += v * b12;
|
|
2090
|
+
t20 += v * b13;
|
|
2091
|
+
t21 += v * b14;
|
|
2092
|
+
t22 += v * b15;
|
|
2093
|
+
v = a[8];
|
|
2094
|
+
t8 += v * b0;
|
|
2095
|
+
t9 += v * b1;
|
|
2096
|
+
t10 += v * b2;
|
|
2097
|
+
t11 += v * b3;
|
|
2098
|
+
t12 += v * b4;
|
|
2099
|
+
t13 += v * b5;
|
|
2100
|
+
t14 += v * b6;
|
|
2101
|
+
t15 += v * b7;
|
|
2102
|
+
t16 += v * b8;
|
|
2103
|
+
t17 += v * b9;
|
|
2104
|
+
t18 += v * b10;
|
|
2105
|
+
t19 += v * b11;
|
|
2106
|
+
t20 += v * b12;
|
|
2107
|
+
t21 += v * b13;
|
|
2108
|
+
t22 += v * b14;
|
|
2109
|
+
t23 += v * b15;
|
|
2110
|
+
v = a[9];
|
|
2111
|
+
t9 += v * b0;
|
|
2112
|
+
t10 += v * b1;
|
|
2113
|
+
t11 += v * b2;
|
|
2114
|
+
t12 += v * b3;
|
|
2115
|
+
t13 += v * b4;
|
|
2116
|
+
t14 += v * b5;
|
|
2117
|
+
t15 += v * b6;
|
|
2118
|
+
t16 += v * b7;
|
|
2119
|
+
t17 += v * b8;
|
|
2120
|
+
t18 += v * b9;
|
|
2121
|
+
t19 += v * b10;
|
|
2122
|
+
t20 += v * b11;
|
|
2123
|
+
t21 += v * b12;
|
|
2124
|
+
t22 += v * b13;
|
|
2125
|
+
t23 += v * b14;
|
|
2126
|
+
t24 += v * b15;
|
|
2127
|
+
v = a[10];
|
|
2128
|
+
t10 += v * b0;
|
|
2129
|
+
t11 += v * b1;
|
|
2130
|
+
t12 += v * b2;
|
|
2131
|
+
t13 += v * b3;
|
|
2132
|
+
t14 += v * b4;
|
|
2133
|
+
t15 += v * b5;
|
|
2134
|
+
t16 += v * b6;
|
|
2135
|
+
t17 += v * b7;
|
|
2136
|
+
t18 += v * b8;
|
|
2137
|
+
t19 += v * b9;
|
|
2138
|
+
t20 += v * b10;
|
|
2139
|
+
t21 += v * b11;
|
|
2140
|
+
t22 += v * b12;
|
|
2141
|
+
t23 += v * b13;
|
|
2142
|
+
t24 += v * b14;
|
|
2143
|
+
t25 += v * b15;
|
|
2144
|
+
v = a[11];
|
|
2145
|
+
t11 += v * b0;
|
|
2146
|
+
t12 += v * b1;
|
|
2147
|
+
t13 += v * b2;
|
|
2148
|
+
t14 += v * b3;
|
|
2149
|
+
t15 += v * b4;
|
|
2150
|
+
t16 += v * b5;
|
|
2151
|
+
t17 += v * b6;
|
|
2152
|
+
t18 += v * b7;
|
|
2153
|
+
t19 += v * b8;
|
|
2154
|
+
t20 += v * b9;
|
|
2155
|
+
t21 += v * b10;
|
|
2156
|
+
t22 += v * b11;
|
|
2157
|
+
t23 += v * b12;
|
|
2158
|
+
t24 += v * b13;
|
|
2159
|
+
t25 += v * b14;
|
|
2160
|
+
t26 += v * b15;
|
|
2161
|
+
v = a[12];
|
|
2162
|
+
t12 += v * b0;
|
|
2163
|
+
t13 += v * b1;
|
|
2164
|
+
t14 += v * b2;
|
|
2165
|
+
t15 += v * b3;
|
|
2166
|
+
t16 += v * b4;
|
|
2167
|
+
t17 += v * b5;
|
|
2168
|
+
t18 += v * b6;
|
|
2169
|
+
t19 += v * b7;
|
|
2170
|
+
t20 += v * b8;
|
|
2171
|
+
t21 += v * b9;
|
|
2172
|
+
t22 += v * b10;
|
|
2173
|
+
t23 += v * b11;
|
|
2174
|
+
t24 += v * b12;
|
|
2175
|
+
t25 += v * b13;
|
|
2176
|
+
t26 += v * b14;
|
|
2177
|
+
t27 += v * b15;
|
|
2178
|
+
v = a[13];
|
|
2179
|
+
t13 += v * b0;
|
|
2180
|
+
t14 += v * b1;
|
|
2181
|
+
t15 += v * b2;
|
|
2182
|
+
t16 += v * b3;
|
|
2183
|
+
t17 += v * b4;
|
|
2184
|
+
t18 += v * b5;
|
|
2185
|
+
t19 += v * b6;
|
|
2186
|
+
t20 += v * b7;
|
|
2187
|
+
t21 += v * b8;
|
|
2188
|
+
t22 += v * b9;
|
|
2189
|
+
t23 += v * b10;
|
|
2190
|
+
t24 += v * b11;
|
|
2191
|
+
t25 += v * b12;
|
|
2192
|
+
t26 += v * b13;
|
|
2193
|
+
t27 += v * b14;
|
|
2194
|
+
t28 += v * b15;
|
|
2195
|
+
v = a[14];
|
|
2196
|
+
t14 += v * b0;
|
|
2197
|
+
t15 += v * b1;
|
|
2198
|
+
t16 += v * b2;
|
|
2199
|
+
t17 += v * b3;
|
|
2200
|
+
t18 += v * b4;
|
|
2201
|
+
t19 += v * b5;
|
|
2202
|
+
t20 += v * b6;
|
|
2203
|
+
t21 += v * b7;
|
|
2204
|
+
t22 += v * b8;
|
|
2205
|
+
t23 += v * b9;
|
|
2206
|
+
t24 += v * b10;
|
|
2207
|
+
t25 += v * b11;
|
|
2208
|
+
t26 += v * b12;
|
|
2209
|
+
t27 += v * b13;
|
|
2210
|
+
t28 += v * b14;
|
|
2211
|
+
t29 += v * b15;
|
|
2212
|
+
v = a[15];
|
|
2213
|
+
t15 += v * b0;
|
|
2214
|
+
t16 += v * b1;
|
|
2215
|
+
t17 += v * b2;
|
|
2216
|
+
t18 += v * b3;
|
|
2217
|
+
t19 += v * b4;
|
|
2218
|
+
t20 += v * b5;
|
|
2219
|
+
t21 += v * b6;
|
|
2220
|
+
t22 += v * b7;
|
|
2221
|
+
t23 += v * b8;
|
|
2222
|
+
t24 += v * b9;
|
|
2223
|
+
t25 += v * b10;
|
|
2224
|
+
t26 += v * b11;
|
|
2225
|
+
t27 += v * b12;
|
|
2226
|
+
t28 += v * b13;
|
|
2227
|
+
t29 += v * b14;
|
|
2228
|
+
t30 += v * b15;
|
|
2229
|
+
|
|
2230
|
+
t0 += 38 * t16;
|
|
2231
|
+
t1 += 38 * t17;
|
|
2232
|
+
t2 += 38 * t18;
|
|
2233
|
+
t3 += 38 * t19;
|
|
2234
|
+
t4 += 38 * t20;
|
|
2235
|
+
t5 += 38 * t21;
|
|
2236
|
+
t6 += 38 * t22;
|
|
2237
|
+
t7 += 38 * t23;
|
|
2238
|
+
t8 += 38 * t24;
|
|
2239
|
+
t9 += 38 * t25;
|
|
2240
|
+
t10 += 38 * t26;
|
|
2241
|
+
t11 += 38 * t27;
|
|
2242
|
+
t12 += 38 * t28;
|
|
2243
|
+
t13 += 38 * t29;
|
|
2244
|
+
t14 += 38 * t30;
|
|
2245
|
+
// t15 left as is
|
|
2246
|
+
|
|
2247
|
+
// first car
|
|
2248
|
+
c = 1;
|
|
2249
|
+
v = t0 + c + 65535; c = Math.floor(v / 65536); t0 = v - c * 65536;
|
|
2250
|
+
v = t1 + c + 65535; c = Math.floor(v / 65536); t1 = v - c * 65536;
|
|
2251
|
+
v = t2 + c + 65535; c = Math.floor(v / 65536); t2 = v - c * 65536;
|
|
2252
|
+
v = t3 + c + 65535; c = Math.floor(v / 65536); t3 = v - c * 65536;
|
|
2253
|
+
v = t4 + c + 65535; c = Math.floor(v / 65536); t4 = v - c * 65536;
|
|
2254
|
+
v = t5 + c + 65535; c = Math.floor(v / 65536); t5 = v - c * 65536;
|
|
2255
|
+
v = t6 + c + 65535; c = Math.floor(v / 65536); t6 = v - c * 65536;
|
|
2256
|
+
v = t7 + c + 65535; c = Math.floor(v / 65536); t7 = v - c * 65536;
|
|
2257
|
+
v = t8 + c + 65535; c = Math.floor(v / 65536); t8 = v - c * 65536;
|
|
2258
|
+
v = t9 + c + 65535; c = Math.floor(v / 65536); t9 = v - c * 65536;
|
|
2259
|
+
v = t10 + c + 65535; c = Math.floor(v / 65536); t10 = v - c * 65536;
|
|
2260
|
+
v = t11 + c + 65535; c = Math.floor(v / 65536); t11 = v - c * 65536;
|
|
2261
|
+
v = t12 + c + 65535; c = Math.floor(v / 65536); t12 = v - c * 65536;
|
|
2262
|
+
v = t13 + c + 65535; c = Math.floor(v / 65536); t13 = v - c * 65536;
|
|
2263
|
+
v = t14 + c + 65535; c = Math.floor(v / 65536); t14 = v - c * 65536;
|
|
2264
|
+
v = t15 + c + 65535; c = Math.floor(v / 65536); t15 = v - c * 65536;
|
|
2265
|
+
t0 += c-1 + 37 * (c-1);
|
|
2266
|
+
|
|
2267
|
+
// second 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
|
+
o[ 0] = t0;
|
|
2288
|
+
o[ 1] = t1;
|
|
2289
|
+
o[ 2] = t2;
|
|
2290
|
+
o[ 3] = t3;
|
|
2291
|
+
o[ 4] = t4;
|
|
2292
|
+
o[ 5] = t5;
|
|
2293
|
+
o[ 6] = t6;
|
|
2294
|
+
o[ 7] = t7;
|
|
2295
|
+
o[ 8] = t8;
|
|
2296
|
+
o[ 9] = t9;
|
|
2297
|
+
o[10] = t10;
|
|
2298
|
+
o[11] = t11;
|
|
2299
|
+
o[12] = t12;
|
|
2300
|
+
o[13] = t13;
|
|
2301
|
+
o[14] = t14;
|
|
2302
|
+
o[15] = t15;
|
|
2303
|
+
}
|
|
2304
|
+
|
|
2305
|
+
function S(o, a) {
|
|
2306
|
+
M(o, a, a);
|
|
2307
|
+
}
|
|
2308
|
+
|
|
2309
|
+
function inv25519(o, i) {
|
|
2310
|
+
var c = gf();
|
|
2311
|
+
var a;
|
|
2312
|
+
for (a = 0; a < 16; a++) c[a] = i[a];
|
|
2313
|
+
for (a = 253; a >= 0; a--) {
|
|
2314
|
+
S(c, c);
|
|
2315
|
+
if(a !== 2 && a !== 4) M(c, c, i);
|
|
2316
|
+
}
|
|
2317
|
+
for (a = 0; a < 16; a++) o[a] = c[a];
|
|
2318
|
+
}
|
|
2319
|
+
|
|
2320
|
+
function pow2523(o, i) {
|
|
2321
|
+
var c = gf();
|
|
2322
|
+
var a;
|
|
2323
|
+
for (a = 0; a < 16; a++) c[a] = i[a];
|
|
2324
|
+
for (a = 250; a >= 0; a--) {
|
|
2325
|
+
S(c, c);
|
|
2326
|
+
if(a !== 1) M(c, c, i);
|
|
2327
|
+
}
|
|
2328
|
+
for (a = 0; a < 16; a++) o[a] = c[a];
|
|
2329
|
+
}
|
|
2330
|
+
|
|
2331
|
+
function crypto_scalarmult(q, n, p) {
|
|
2332
|
+
var z = new Uint8Array(32);
|
|
2333
|
+
var x = new Float64Array(80), r, i;
|
|
2334
|
+
var a = gf(), b = gf(), c = gf(),
|
|
2335
|
+
d = gf(), e = gf(), f = gf();
|
|
2336
|
+
for (i = 0; i < 31; i++) z[i] = n[i];
|
|
2337
|
+
z[31]=(n[31]&127)|64;
|
|
2338
|
+
z[0]&=248;
|
|
2339
|
+
unpack25519(x,p);
|
|
2340
|
+
for (i = 0; i < 16; i++) {
|
|
2341
|
+
b[i]=x[i];
|
|
2342
|
+
d[i]=a[i]=c[i]=0;
|
|
2343
|
+
}
|
|
2344
|
+
a[0]=d[0]=1;
|
|
2345
|
+
for (i=254; i>=0; --i) {
|
|
2346
|
+
r=(z[i>>>3]>>>(i&7))&1;
|
|
2347
|
+
sel25519(a,b,r);
|
|
2348
|
+
sel25519(c,d,r);
|
|
2349
|
+
A(e,a,c);
|
|
2350
|
+
Z(a,a,c);
|
|
2351
|
+
A(c,b,d);
|
|
2352
|
+
Z(b,b,d);
|
|
2353
|
+
S(d,e);
|
|
2354
|
+
S(f,a);
|
|
2355
|
+
M(a,c,a);
|
|
2356
|
+
M(c,b,e);
|
|
2357
|
+
A(e,a,c);
|
|
2358
|
+
Z(a,a,c);
|
|
2359
|
+
S(b,a);
|
|
2360
|
+
Z(c,d,f);
|
|
2361
|
+
M(a,c,_121665);
|
|
2362
|
+
A(a,a,d);
|
|
2363
|
+
M(c,c,a);
|
|
2364
|
+
M(a,d,f);
|
|
2365
|
+
M(d,b,x);
|
|
2366
|
+
S(b,e);
|
|
2367
|
+
sel25519(a,b,r);
|
|
2368
|
+
sel25519(c,d,r);
|
|
2369
|
+
}
|
|
2370
|
+
for (i = 0; i < 16; i++) {
|
|
2371
|
+
x[i+16]=a[i];
|
|
2372
|
+
x[i+32]=c[i];
|
|
2373
|
+
x[i+48]=b[i];
|
|
2374
|
+
x[i+64]=d[i];
|
|
2375
|
+
}
|
|
2376
|
+
var x32 = x.subarray(32);
|
|
2377
|
+
var x16 = x.subarray(16);
|
|
2378
|
+
inv25519(x32,x32);
|
|
2379
|
+
M(x16,x16,x32);
|
|
2380
|
+
pack25519(q,x16);
|
|
2381
|
+
return 0;
|
|
2382
|
+
}
|
|
2383
|
+
|
|
2384
|
+
function crypto_scalarmult_base(q, n) {
|
|
2385
|
+
return crypto_scalarmult(q, n, _9);
|
|
2386
|
+
}
|
|
2387
|
+
|
|
2388
|
+
function crypto_box_keypair(y, x) {
|
|
2389
|
+
randombytes(x, 32);
|
|
2390
|
+
return crypto_scalarmult_base(y, x);
|
|
2391
|
+
}
|
|
2392
|
+
|
|
2393
|
+
function crypto_box_beforenm(k, y, x) {
|
|
2394
|
+
var s = new Uint8Array(32);
|
|
2395
|
+
crypto_scalarmult(s, x, y);
|
|
2396
|
+
return crypto_core_hsalsa20(k, _0, s, sigma);
|
|
2397
|
+
}
|
|
2398
|
+
|
|
2399
|
+
var crypto_box_afternm = crypto_secretbox;
|
|
2400
|
+
var crypto_box_open_afternm = crypto_secretbox_open;
|
|
2401
|
+
|
|
2402
|
+
function crypto_box(c, m, d, n, y, x) {
|
|
2403
|
+
var k = new Uint8Array(32);
|
|
2404
|
+
crypto_box_beforenm(k, y, x);
|
|
2405
|
+
return crypto_box_afternm(c, m, d, n, k);
|
|
2406
|
+
}
|
|
2407
|
+
|
|
2408
|
+
function crypto_box_open(m, c, d, n, y, x) {
|
|
2409
|
+
var k = new Uint8Array(32);
|
|
2410
|
+
crypto_box_beforenm(k, y, x);
|
|
2411
|
+
return crypto_box_open_afternm(m, c, d, n, k);
|
|
2412
|
+
}
|
|
2413
|
+
|
|
2414
|
+
var K = [
|
|
2415
|
+
0x428a2f98, 0xd728ae22, 0x71374491, 0x23ef65cd,
|
|
2416
|
+
0xb5c0fbcf, 0xec4d3b2f, 0xe9b5dba5, 0x8189dbbc,
|
|
2417
|
+
0x3956c25b, 0xf348b538, 0x59f111f1, 0xb605d019,
|
|
2418
|
+
0x923f82a4, 0xaf194f9b, 0xab1c5ed5, 0xda6d8118,
|
|
2419
|
+
0xd807aa98, 0xa3030242, 0x12835b01, 0x45706fbe,
|
|
2420
|
+
0x243185be, 0x4ee4b28c, 0x550c7dc3, 0xd5ffb4e2,
|
|
2421
|
+
0x72be5d74, 0xf27b896f, 0x80deb1fe, 0x3b1696b1,
|
|
2422
|
+
0x9bdc06a7, 0x25c71235, 0xc19bf174, 0xcf692694,
|
|
2423
|
+
0xe49b69c1, 0x9ef14ad2, 0xefbe4786, 0x384f25e3,
|
|
2424
|
+
0x0fc19dc6, 0x8b8cd5b5, 0x240ca1cc, 0x77ac9c65,
|
|
2425
|
+
0x2de92c6f, 0x592b0275, 0x4a7484aa, 0x6ea6e483,
|
|
2426
|
+
0x5cb0a9dc, 0xbd41fbd4, 0x76f988da, 0x831153b5,
|
|
2427
|
+
0x983e5152, 0xee66dfab, 0xa831c66d, 0x2db43210,
|
|
2428
|
+
0xb00327c8, 0x98fb213f, 0xbf597fc7, 0xbeef0ee4,
|
|
2429
|
+
0xc6e00bf3, 0x3da88fc2, 0xd5a79147, 0x930aa725,
|
|
2430
|
+
0x06ca6351, 0xe003826f, 0x14292967, 0x0a0e6e70,
|
|
2431
|
+
0x27b70a85, 0x46d22ffc, 0x2e1b2138, 0x5c26c926,
|
|
2432
|
+
0x4d2c6dfc, 0x5ac42aed, 0x53380d13, 0x9d95b3df,
|
|
2433
|
+
0x650a7354, 0x8baf63de, 0x766a0abb, 0x3c77b2a8,
|
|
2434
|
+
0x81c2c92e, 0x47edaee6, 0x92722c85, 0x1482353b,
|
|
2435
|
+
0xa2bfe8a1, 0x4cf10364, 0xa81a664b, 0xbc423001,
|
|
2436
|
+
0xc24b8b70, 0xd0f89791, 0xc76c51a3, 0x0654be30,
|
|
2437
|
+
0xd192e819, 0xd6ef5218, 0xd6990624, 0x5565a910,
|
|
2438
|
+
0xf40e3585, 0x5771202a, 0x106aa070, 0x32bbd1b8,
|
|
2439
|
+
0x19a4c116, 0xb8d2d0c8, 0x1e376c08, 0x5141ab53,
|
|
2440
|
+
0x2748774c, 0xdf8eeb99, 0x34b0bcb5, 0xe19b48a8,
|
|
2441
|
+
0x391c0cb3, 0xc5c95a63, 0x4ed8aa4a, 0xe3418acb,
|
|
2442
|
+
0x5b9cca4f, 0x7763e373, 0x682e6ff3, 0xd6b2b8a3,
|
|
2443
|
+
0x748f82ee, 0x5defb2fc, 0x78a5636f, 0x43172f60,
|
|
2444
|
+
0x84c87814, 0xa1f0ab72, 0x8cc70208, 0x1a6439ec,
|
|
2445
|
+
0x90befffa, 0x23631e28, 0xa4506ceb, 0xde82bde9,
|
|
2446
|
+
0xbef9a3f7, 0xb2c67915, 0xc67178f2, 0xe372532b,
|
|
2447
|
+
0xca273ece, 0xea26619c, 0xd186b8c7, 0x21c0c207,
|
|
2448
|
+
0xeada7dd6, 0xcde0eb1e, 0xf57d4f7f, 0xee6ed178,
|
|
2449
|
+
0x06f067aa, 0x72176fba, 0x0a637dc5, 0xa2c898a6,
|
|
2450
|
+
0x113f9804, 0xbef90dae, 0x1b710b35, 0x131c471b,
|
|
2451
|
+
0x28db77f5, 0x23047d84, 0x32caab7b, 0x40c72493,
|
|
2452
|
+
0x3c9ebe0a, 0x15c9bebc, 0x431d67c4, 0x9c100d4c,
|
|
2453
|
+
0x4cc5d4be, 0xcb3e42b6, 0x597f299c, 0xfc657e2a,
|
|
2454
|
+
0x5fcb6fab, 0x3ad6faec, 0x6c44198c, 0x4a475817
|
|
2455
|
+
];
|
|
2456
|
+
|
|
2457
|
+
function crypto_hashblocks_hl(hh, hl, m, n) {
|
|
2458
|
+
var wh = new Int32Array(16), wl = new Int32Array(16),
|
|
2459
|
+
bh0, bh1, bh2, bh3, bh4, bh5, bh6, bh7,
|
|
2460
|
+
bl0, bl1, bl2, bl3, bl4, bl5, bl6, bl7,
|
|
2461
|
+
th, tl, i, j, h, l, a, b, c, d;
|
|
2462
|
+
|
|
2463
|
+
var ah0 = hh[0],
|
|
2464
|
+
ah1 = hh[1],
|
|
2465
|
+
ah2 = hh[2],
|
|
2466
|
+
ah3 = hh[3],
|
|
2467
|
+
ah4 = hh[4],
|
|
2468
|
+
ah5 = hh[5],
|
|
2469
|
+
ah6 = hh[6],
|
|
2470
|
+
ah7 = hh[7],
|
|
2471
|
+
|
|
2472
|
+
al0 = hl[0],
|
|
2473
|
+
al1 = hl[1],
|
|
2474
|
+
al2 = hl[2],
|
|
2475
|
+
al3 = hl[3],
|
|
2476
|
+
al4 = hl[4],
|
|
2477
|
+
al5 = hl[5],
|
|
2478
|
+
al6 = hl[6],
|
|
2479
|
+
al7 = hl[7];
|
|
2480
|
+
|
|
2481
|
+
var pos = 0;
|
|
2482
|
+
while (n >= 128) {
|
|
2483
|
+
for (i = 0; i < 16; i++) {
|
|
2484
|
+
j = 8 * i + pos;
|
|
2485
|
+
wh[i] = (m[j+0] << 24) | (m[j+1] << 16) | (m[j+2] << 8) | m[j+3];
|
|
2486
|
+
wl[i] = (m[j+4] << 24) | (m[j+5] << 16) | (m[j+6] << 8) | m[j+7];
|
|
2487
|
+
}
|
|
2488
|
+
for (i = 0; i < 80; i++) {
|
|
2489
|
+
bh0 = ah0;
|
|
2490
|
+
bh1 = ah1;
|
|
2491
|
+
bh2 = ah2;
|
|
2492
|
+
bh3 = ah3;
|
|
2493
|
+
bh4 = ah4;
|
|
2494
|
+
bh5 = ah5;
|
|
2495
|
+
bh6 = ah6;
|
|
2496
|
+
bh7 = ah7;
|
|
2497
|
+
|
|
2498
|
+
bl0 = al0;
|
|
2499
|
+
bl1 = al1;
|
|
2500
|
+
bl2 = al2;
|
|
2501
|
+
bl3 = al3;
|
|
2502
|
+
bl4 = al4;
|
|
2503
|
+
bl5 = al5;
|
|
2504
|
+
bl6 = al6;
|
|
2505
|
+
bl7 = al7;
|
|
2506
|
+
|
|
2507
|
+
// add
|
|
2508
|
+
h = ah7;
|
|
2509
|
+
l = al7;
|
|
2510
|
+
|
|
2511
|
+
a = l & 0xffff; b = l >>> 16;
|
|
2512
|
+
c = h & 0xffff; d = h >>> 16;
|
|
2513
|
+
|
|
2514
|
+
// Sigma1
|
|
2515
|
+
h = ((ah4 >>> 14) | (al4 << (32-14))) ^ ((ah4 >>> 18) | (al4 << (32-18))) ^ ((al4 >>> (41-32)) | (ah4 << (32-(41-32))));
|
|
2516
|
+
l = ((al4 >>> 14) | (ah4 << (32-14))) ^ ((al4 >>> 18) | (ah4 << (32-18))) ^ ((ah4 >>> (41-32)) | (al4 << (32-(41-32))));
|
|
2517
|
+
|
|
2518
|
+
a += l & 0xffff; b += l >>> 16;
|
|
2519
|
+
c += h & 0xffff; d += h >>> 16;
|
|
2520
|
+
|
|
2521
|
+
// Ch
|
|
2522
|
+
h = (ah4 & ah5) ^ (~ah4 & ah6);
|
|
2523
|
+
l = (al4 & al5) ^ (~al4 & al6);
|
|
2524
|
+
|
|
2525
|
+
a += l & 0xffff; b += l >>> 16;
|
|
2526
|
+
c += h & 0xffff; d += h >>> 16;
|
|
2527
|
+
|
|
2528
|
+
// K
|
|
2529
|
+
h = K[i*2];
|
|
2530
|
+
l = K[i*2+1];
|
|
2531
|
+
|
|
2532
|
+
a += l & 0xffff; b += l >>> 16;
|
|
2533
|
+
c += h & 0xffff; d += h >>> 16;
|
|
2534
|
+
|
|
2535
|
+
// w
|
|
2536
|
+
h = wh[i%16];
|
|
2537
|
+
l = wl[i%16];
|
|
2538
|
+
|
|
2539
|
+
a += l & 0xffff; b += l >>> 16;
|
|
2540
|
+
c += h & 0xffff; d += h >>> 16;
|
|
2541
|
+
|
|
2542
|
+
b += a >>> 16;
|
|
2543
|
+
c += b >>> 16;
|
|
2544
|
+
d += c >>> 16;
|
|
2545
|
+
|
|
2546
|
+
th = c & 0xffff | d << 16;
|
|
2547
|
+
tl = a & 0xffff | b << 16;
|
|
2548
|
+
|
|
2549
|
+
// add
|
|
2550
|
+
h = th;
|
|
2551
|
+
l = tl;
|
|
2552
|
+
|
|
2553
|
+
a = l & 0xffff; b = l >>> 16;
|
|
2554
|
+
c = h & 0xffff; d = h >>> 16;
|
|
2555
|
+
|
|
2556
|
+
// Sigma0
|
|
2557
|
+
h = ((ah0 >>> 28) | (al0 << (32-28))) ^ ((al0 >>> (34-32)) | (ah0 << (32-(34-32)))) ^ ((al0 >>> (39-32)) | (ah0 << (32-(39-32))));
|
|
2558
|
+
l = ((al0 >>> 28) | (ah0 << (32-28))) ^ ((ah0 >>> (34-32)) | (al0 << (32-(34-32)))) ^ ((ah0 >>> (39-32)) | (al0 << (32-(39-32))));
|
|
2559
|
+
|
|
2560
|
+
a += l & 0xffff; b += l >>> 16;
|
|
2561
|
+
c += h & 0xffff; d += h >>> 16;
|
|
2562
|
+
|
|
2563
|
+
// Maj
|
|
2564
|
+
h = (ah0 & ah1) ^ (ah0 & ah2) ^ (ah1 & ah2);
|
|
2565
|
+
l = (al0 & al1) ^ (al0 & al2) ^ (al1 & al2);
|
|
2566
|
+
|
|
2567
|
+
a += l & 0xffff; b += l >>> 16;
|
|
2568
|
+
c += h & 0xffff; d += h >>> 16;
|
|
2569
|
+
|
|
2570
|
+
b += a >>> 16;
|
|
2571
|
+
c += b >>> 16;
|
|
2572
|
+
d += c >>> 16;
|
|
2573
|
+
|
|
2574
|
+
bh7 = (c & 0xffff) | (d << 16);
|
|
2575
|
+
bl7 = (a & 0xffff) | (b << 16);
|
|
2576
|
+
|
|
2577
|
+
// add
|
|
2578
|
+
h = bh3;
|
|
2579
|
+
l = bl3;
|
|
2580
|
+
|
|
2581
|
+
a = l & 0xffff; b = l >>> 16;
|
|
2582
|
+
c = h & 0xffff; d = h >>> 16;
|
|
2583
|
+
|
|
2584
|
+
h = th;
|
|
2585
|
+
l = tl;
|
|
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
|
+
bh3 = (c & 0xffff) | (d << 16);
|
|
2595
|
+
bl3 = (a & 0xffff) | (b << 16);
|
|
2596
|
+
|
|
2597
|
+
ah1 = bh0;
|
|
2598
|
+
ah2 = bh1;
|
|
2599
|
+
ah3 = bh2;
|
|
2600
|
+
ah4 = bh3;
|
|
2601
|
+
ah5 = bh4;
|
|
2602
|
+
ah6 = bh5;
|
|
2603
|
+
ah7 = bh6;
|
|
2604
|
+
ah0 = bh7;
|
|
2605
|
+
|
|
2606
|
+
al1 = bl0;
|
|
2607
|
+
al2 = bl1;
|
|
2608
|
+
al3 = bl2;
|
|
2609
|
+
al4 = bl3;
|
|
2610
|
+
al5 = bl4;
|
|
2611
|
+
al6 = bl5;
|
|
2612
|
+
al7 = bl6;
|
|
2613
|
+
al0 = bl7;
|
|
2614
|
+
|
|
2615
|
+
if (i%16 === 15) {
|
|
2616
|
+
for (j = 0; j < 16; j++) {
|
|
2617
|
+
// add
|
|
2618
|
+
h = wh[j];
|
|
2619
|
+
l = wl[j];
|
|
2620
|
+
|
|
2621
|
+
a = l & 0xffff; b = l >>> 16;
|
|
2622
|
+
c = h & 0xffff; d = h >>> 16;
|
|
2623
|
+
|
|
2624
|
+
h = wh[(j+9)%16];
|
|
2625
|
+
l = wl[(j+9)%16];
|
|
2626
|
+
|
|
2627
|
+
a += l & 0xffff; b += l >>> 16;
|
|
2628
|
+
c += h & 0xffff; d += h >>> 16;
|
|
2629
|
+
|
|
2630
|
+
// sigma0
|
|
2631
|
+
th = wh[(j+1)%16];
|
|
2632
|
+
tl = wl[(j+1)%16];
|
|
2633
|
+
h = ((th >>> 1) | (tl << (32-1))) ^ ((th >>> 8) | (tl << (32-8))) ^ (th >>> 7);
|
|
2634
|
+
l = ((tl >>> 1) | (th << (32-1))) ^ ((tl >>> 8) | (th << (32-8))) ^ ((tl >>> 7) | (th << (32-7)));
|
|
2635
|
+
|
|
2636
|
+
a += l & 0xffff; b += l >>> 16;
|
|
2637
|
+
c += h & 0xffff; d += h >>> 16;
|
|
2638
|
+
|
|
2639
|
+
// sigma1
|
|
2640
|
+
th = wh[(j+14)%16];
|
|
2641
|
+
tl = wl[(j+14)%16];
|
|
2642
|
+
h = ((th >>> 19) | (tl << (32-19))) ^ ((tl >>> (61-32)) | (th << (32-(61-32)))) ^ (th >>> 6);
|
|
2643
|
+
l = ((tl >>> 19) | (th << (32-19))) ^ ((th >>> (61-32)) | (tl << (32-(61-32)))) ^ ((tl >>> 6) | (th << (32-6)));
|
|
2644
|
+
|
|
2645
|
+
a += l & 0xffff; b += l >>> 16;
|
|
2646
|
+
c += h & 0xffff; d += h >>> 16;
|
|
2647
|
+
|
|
2648
|
+
b += a >>> 16;
|
|
2649
|
+
c += b >>> 16;
|
|
2650
|
+
d += c >>> 16;
|
|
2651
|
+
|
|
2652
|
+
wh[j] = (c & 0xffff) | (d << 16);
|
|
2653
|
+
wl[j] = (a & 0xffff) | (b << 16);
|
|
2654
|
+
}
|
|
2655
|
+
}
|
|
2656
|
+
}
|
|
2657
|
+
|
|
2658
|
+
// add
|
|
2659
|
+
h = ah0;
|
|
2660
|
+
l = al0;
|
|
2661
|
+
|
|
2662
|
+
a = l & 0xffff; b = l >>> 16;
|
|
2663
|
+
c = h & 0xffff; d = h >>> 16;
|
|
2664
|
+
|
|
2665
|
+
h = hh[0];
|
|
2666
|
+
l = hl[0];
|
|
2667
|
+
|
|
2668
|
+
a += l & 0xffff; b += l >>> 16;
|
|
2669
|
+
c += h & 0xffff; d += h >>> 16;
|
|
2670
|
+
|
|
2671
|
+
b += a >>> 16;
|
|
2672
|
+
c += b >>> 16;
|
|
2673
|
+
d += c >>> 16;
|
|
2674
|
+
|
|
2675
|
+
hh[0] = ah0 = (c & 0xffff) | (d << 16);
|
|
2676
|
+
hl[0] = al0 = (a & 0xffff) | (b << 16);
|
|
2677
|
+
|
|
2678
|
+
h = ah1;
|
|
2679
|
+
l = al1;
|
|
2680
|
+
|
|
2681
|
+
a = l & 0xffff; b = l >>> 16;
|
|
2682
|
+
c = h & 0xffff; d = h >>> 16;
|
|
2683
|
+
|
|
2684
|
+
h = hh[1];
|
|
2685
|
+
l = hl[1];
|
|
2686
|
+
|
|
2687
|
+
a += l & 0xffff; b += l >>> 16;
|
|
2688
|
+
c += h & 0xffff; d += h >>> 16;
|
|
2689
|
+
|
|
2690
|
+
b += a >>> 16;
|
|
2691
|
+
c += b >>> 16;
|
|
2692
|
+
d += c >>> 16;
|
|
2693
|
+
|
|
2694
|
+
hh[1] = ah1 = (c & 0xffff) | (d << 16);
|
|
2695
|
+
hl[1] = al1 = (a & 0xffff) | (b << 16);
|
|
2696
|
+
|
|
2697
|
+
h = ah2;
|
|
2698
|
+
l = al2;
|
|
2699
|
+
|
|
2700
|
+
a = l & 0xffff; b = l >>> 16;
|
|
2701
|
+
c = h & 0xffff; d = h >>> 16;
|
|
2702
|
+
|
|
2703
|
+
h = hh[2];
|
|
2704
|
+
l = hl[2];
|
|
2705
|
+
|
|
2706
|
+
a += l & 0xffff; b += l >>> 16;
|
|
2707
|
+
c += h & 0xffff; d += h >>> 16;
|
|
2708
|
+
|
|
2709
|
+
b += a >>> 16;
|
|
2710
|
+
c += b >>> 16;
|
|
2711
|
+
d += c >>> 16;
|
|
2712
|
+
|
|
2713
|
+
hh[2] = ah2 = (c & 0xffff) | (d << 16);
|
|
2714
|
+
hl[2] = al2 = (a & 0xffff) | (b << 16);
|
|
2715
|
+
|
|
2716
|
+
h = ah3;
|
|
2717
|
+
l = al3;
|
|
2718
|
+
|
|
2719
|
+
a = l & 0xffff; b = l >>> 16;
|
|
2720
|
+
c = h & 0xffff; d = h >>> 16;
|
|
2721
|
+
|
|
2722
|
+
h = hh[3];
|
|
2723
|
+
l = hl[3];
|
|
2724
|
+
|
|
2725
|
+
a += l & 0xffff; b += l >>> 16;
|
|
2726
|
+
c += h & 0xffff; d += h >>> 16;
|
|
2727
|
+
|
|
2728
|
+
b += a >>> 16;
|
|
2729
|
+
c += b >>> 16;
|
|
2730
|
+
d += c >>> 16;
|
|
2731
|
+
|
|
2732
|
+
hh[3] = ah3 = (c & 0xffff) | (d << 16);
|
|
2733
|
+
hl[3] = al3 = (a & 0xffff) | (b << 16);
|
|
2734
|
+
|
|
2735
|
+
h = ah4;
|
|
2736
|
+
l = al4;
|
|
2737
|
+
|
|
2738
|
+
a = l & 0xffff; b = l >>> 16;
|
|
2739
|
+
c = h & 0xffff; d = h >>> 16;
|
|
2740
|
+
|
|
2741
|
+
h = hh[4];
|
|
2742
|
+
l = hl[4];
|
|
2743
|
+
|
|
2744
|
+
a += l & 0xffff; b += l >>> 16;
|
|
2745
|
+
c += h & 0xffff; d += h >>> 16;
|
|
2746
|
+
|
|
2747
|
+
b += a >>> 16;
|
|
2748
|
+
c += b >>> 16;
|
|
2749
|
+
d += c >>> 16;
|
|
2750
|
+
|
|
2751
|
+
hh[4] = ah4 = (c & 0xffff) | (d << 16);
|
|
2752
|
+
hl[4] = al4 = (a & 0xffff) | (b << 16);
|
|
2753
|
+
|
|
2754
|
+
h = ah5;
|
|
2755
|
+
l = al5;
|
|
2756
|
+
|
|
2757
|
+
a = l & 0xffff; b = l >>> 16;
|
|
2758
|
+
c = h & 0xffff; d = h >>> 16;
|
|
2759
|
+
|
|
2760
|
+
h = hh[5];
|
|
2761
|
+
l = hl[5];
|
|
2762
|
+
|
|
2763
|
+
a += l & 0xffff; b += l >>> 16;
|
|
2764
|
+
c += h & 0xffff; d += h >>> 16;
|
|
2765
|
+
|
|
2766
|
+
b += a >>> 16;
|
|
2767
|
+
c += b >>> 16;
|
|
2768
|
+
d += c >>> 16;
|
|
2769
|
+
|
|
2770
|
+
hh[5] = ah5 = (c & 0xffff) | (d << 16);
|
|
2771
|
+
hl[5] = al5 = (a & 0xffff) | (b << 16);
|
|
2772
|
+
|
|
2773
|
+
h = ah6;
|
|
2774
|
+
l = al6;
|
|
2775
|
+
|
|
2776
|
+
a = l & 0xffff; b = l >>> 16;
|
|
2777
|
+
c = h & 0xffff; d = h >>> 16;
|
|
2778
|
+
|
|
2779
|
+
h = hh[6];
|
|
2780
|
+
l = hl[6];
|
|
2781
|
+
|
|
2782
|
+
a += l & 0xffff; b += l >>> 16;
|
|
2783
|
+
c += h & 0xffff; d += h >>> 16;
|
|
2784
|
+
|
|
2785
|
+
b += a >>> 16;
|
|
2786
|
+
c += b >>> 16;
|
|
2787
|
+
d += c >>> 16;
|
|
2788
|
+
|
|
2789
|
+
hh[6] = ah6 = (c & 0xffff) | (d << 16);
|
|
2790
|
+
hl[6] = al6 = (a & 0xffff) | (b << 16);
|
|
2791
|
+
|
|
2792
|
+
h = ah7;
|
|
2793
|
+
l = al7;
|
|
2794
|
+
|
|
2795
|
+
a = l & 0xffff; b = l >>> 16;
|
|
2796
|
+
c = h & 0xffff; d = h >>> 16;
|
|
2797
|
+
|
|
2798
|
+
h = hh[7];
|
|
2799
|
+
l = hl[7];
|
|
2800
|
+
|
|
2801
|
+
a += l & 0xffff; b += l >>> 16;
|
|
2802
|
+
c += h & 0xffff; d += h >>> 16;
|
|
2803
|
+
|
|
2804
|
+
b += a >>> 16;
|
|
2805
|
+
c += b >>> 16;
|
|
2806
|
+
d += c >>> 16;
|
|
2807
|
+
|
|
2808
|
+
hh[7] = ah7 = (c & 0xffff) | (d << 16);
|
|
2809
|
+
hl[7] = al7 = (a & 0xffff) | (b << 16);
|
|
2810
|
+
|
|
2811
|
+
pos += 128;
|
|
2812
|
+
n -= 128;
|
|
2813
|
+
}
|
|
2814
|
+
|
|
2815
|
+
return n;
|
|
2816
|
+
}
|
|
2817
|
+
|
|
2818
|
+
function crypto_hash(out, m, n) {
|
|
2819
|
+
var hh = new Int32Array(8),
|
|
2820
|
+
hl = new Int32Array(8),
|
|
2821
|
+
x = new Uint8Array(256),
|
|
2822
|
+
i, b = n;
|
|
2823
|
+
|
|
2824
|
+
hh[0] = 0x6a09e667;
|
|
2825
|
+
hh[1] = 0xbb67ae85;
|
|
2826
|
+
hh[2] = 0x3c6ef372;
|
|
2827
|
+
hh[3] = 0xa54ff53a;
|
|
2828
|
+
hh[4] = 0x510e527f;
|
|
2829
|
+
hh[5] = 0x9b05688c;
|
|
2830
|
+
hh[6] = 0x1f83d9ab;
|
|
2831
|
+
hh[7] = 0x5be0cd19;
|
|
2832
|
+
|
|
2833
|
+
hl[0] = 0xf3bcc908;
|
|
2834
|
+
hl[1] = 0x84caa73b;
|
|
2835
|
+
hl[2] = 0xfe94f82b;
|
|
2836
|
+
hl[3] = 0x5f1d36f1;
|
|
2837
|
+
hl[4] = 0xade682d1;
|
|
2838
|
+
hl[5] = 0x2b3e6c1f;
|
|
2839
|
+
hl[6] = 0xfb41bd6b;
|
|
2840
|
+
hl[7] = 0x137e2179;
|
|
2841
|
+
|
|
2842
|
+
crypto_hashblocks_hl(hh, hl, m, n);
|
|
2843
|
+
n %= 128;
|
|
2844
|
+
|
|
2845
|
+
for (i = 0; i < n; i++) x[i] = m[b-n+i];
|
|
2846
|
+
x[n] = 128;
|
|
2847
|
+
|
|
2848
|
+
n = 256-128*(n<112?1:0);
|
|
2849
|
+
x[n-9] = 0;
|
|
2850
|
+
ts64(x, n-8, (b / 0x20000000) | 0, b << 3);
|
|
2851
|
+
crypto_hashblocks_hl(hh, hl, x, n);
|
|
2852
|
+
|
|
2853
|
+
for (i = 0; i < 8; i++) ts64(out, 8*i, hh[i], hl[i]);
|
|
2854
|
+
|
|
2855
|
+
return 0;
|
|
2856
|
+
}
|
|
2857
|
+
|
|
2858
|
+
function add(p, q) {
|
|
2859
|
+
var a = gf(), b = gf(), c = gf(),
|
|
2860
|
+
d = gf(), e = gf(), f = gf(),
|
|
2861
|
+
g = gf(), h = gf(), t = gf();
|
|
2862
|
+
|
|
2863
|
+
Z(a, p[1], p[0]);
|
|
2864
|
+
Z(t, q[1], q[0]);
|
|
2865
|
+
M(a, a, t);
|
|
2866
|
+
A(b, p[0], p[1]);
|
|
2867
|
+
A(t, q[0], q[1]);
|
|
2868
|
+
M(b, b, t);
|
|
2869
|
+
M(c, p[3], q[3]);
|
|
2870
|
+
M(c, c, D2);
|
|
2871
|
+
M(d, p[2], q[2]);
|
|
2872
|
+
A(d, d, d);
|
|
2873
|
+
Z(e, b, a);
|
|
2874
|
+
Z(f, d, c);
|
|
2875
|
+
A(g, d, c);
|
|
2876
|
+
A(h, b, a);
|
|
2877
|
+
|
|
2878
|
+
M(p[0], e, f);
|
|
2879
|
+
M(p[1], h, g);
|
|
2880
|
+
M(p[2], g, f);
|
|
2881
|
+
M(p[3], e, h);
|
|
2882
|
+
}
|
|
2883
|
+
|
|
2884
|
+
function cswap(p, q, b) {
|
|
2885
|
+
var i;
|
|
2886
|
+
for (i = 0; i < 4; i++) {
|
|
2887
|
+
sel25519(p[i], q[i], b);
|
|
2888
|
+
}
|
|
2889
|
+
}
|
|
2890
|
+
|
|
2891
|
+
function pack(r, p) {
|
|
2892
|
+
var tx = gf(), ty = gf(), zi = gf();
|
|
2893
|
+
inv25519(zi, p[2]);
|
|
2894
|
+
M(tx, p[0], zi);
|
|
2895
|
+
M(ty, p[1], zi);
|
|
2896
|
+
pack25519(r, ty);
|
|
2897
|
+
r[31] ^= par25519(tx) << 7;
|
|
2898
|
+
}
|
|
2899
|
+
|
|
2900
|
+
function scalarmult(p, q, s) {
|
|
2901
|
+
var b, i;
|
|
2902
|
+
set25519(p[0], gf0);
|
|
2903
|
+
set25519(p[1], gf1);
|
|
2904
|
+
set25519(p[2], gf1);
|
|
2905
|
+
set25519(p[3], gf0);
|
|
2906
|
+
for (i = 255; i >= 0; --i) {
|
|
2907
|
+
b = (s[(i/8)|0] >> (i&7)) & 1;
|
|
2908
|
+
cswap(p, q, b);
|
|
2909
|
+
add(q, p);
|
|
2910
|
+
add(p, p);
|
|
2911
|
+
cswap(p, q, b);
|
|
2912
|
+
}
|
|
2913
|
+
}
|
|
2914
|
+
|
|
2915
|
+
function scalarbase(p, s) {
|
|
2916
|
+
var q = [gf(), gf(), gf(), gf()];
|
|
2917
|
+
set25519(q[0], X);
|
|
2918
|
+
set25519(q[1], Y);
|
|
2919
|
+
set25519(q[2], gf1);
|
|
2920
|
+
M(q[3], X, Y);
|
|
2921
|
+
scalarmult(p, q, s);
|
|
2922
|
+
}
|
|
2923
|
+
|
|
2924
|
+
function crypto_sign_keypair(pk, sk, seeded) {
|
|
2925
|
+
var d = new Uint8Array(64);
|
|
2926
|
+
var p = [gf(), gf(), gf(), gf()];
|
|
2927
|
+
var i;
|
|
2928
|
+
|
|
2929
|
+
if (!seeded) randombytes(sk, 32);
|
|
2930
|
+
crypto_hash(d, sk, 32);
|
|
2931
|
+
d[0] &= 248;
|
|
2932
|
+
d[31] &= 127;
|
|
2933
|
+
d[31] |= 64;
|
|
2934
|
+
|
|
2935
|
+
scalarbase(p, d);
|
|
2936
|
+
pack(pk, p);
|
|
2937
|
+
|
|
2938
|
+
for (i = 0; i < 32; i++) sk[i+32] = pk[i];
|
|
2939
|
+
return 0;
|
|
2940
|
+
}
|
|
2941
|
+
|
|
2942
|
+
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]);
|
|
2943
|
+
|
|
2944
|
+
function modL(r, x) {
|
|
2945
|
+
var carry, i, j, k;
|
|
2946
|
+
for (i = 63; i >= 32; --i) {
|
|
2947
|
+
carry = 0;
|
|
2948
|
+
for (j = i - 32, k = i - 12; j < k; ++j) {
|
|
2949
|
+
x[j] += carry - 16 * x[i] * L[j - (i - 32)];
|
|
2950
|
+
carry = Math.floor((x[j] + 128) / 256);
|
|
2951
|
+
x[j] -= carry * 256;
|
|
2952
|
+
}
|
|
2953
|
+
x[j] += carry;
|
|
2954
|
+
x[i] = 0;
|
|
2955
|
+
}
|
|
2956
|
+
carry = 0;
|
|
2957
|
+
for (j = 0; j < 32; j++) {
|
|
2958
|
+
x[j] += carry - (x[31] >> 4) * L[j];
|
|
2959
|
+
carry = x[j] >> 8;
|
|
2960
|
+
x[j] &= 255;
|
|
2961
|
+
}
|
|
2962
|
+
for (j = 0; j < 32; j++) x[j] -= carry * L[j];
|
|
2963
|
+
for (i = 0; i < 32; i++) {
|
|
2964
|
+
x[i+1] += x[i] >> 8;
|
|
2965
|
+
r[i] = x[i] & 255;
|
|
2966
|
+
}
|
|
2967
|
+
}
|
|
2968
|
+
|
|
2969
|
+
function reduce(r) {
|
|
2970
|
+
var x = new Float64Array(64), i;
|
|
2971
|
+
for (i = 0; i < 64; i++) x[i] = r[i];
|
|
2972
|
+
for (i = 0; i < 64; i++) r[i] = 0;
|
|
2973
|
+
modL(r, x);
|
|
2974
|
+
}
|
|
2975
|
+
|
|
2976
|
+
// Note: difference from C - smlen returned, not passed as argument.
|
|
2977
|
+
function crypto_sign(sm, m, n, sk) {
|
|
2978
|
+
var d = new Uint8Array(64), h = new Uint8Array(64), r = new Uint8Array(64);
|
|
2979
|
+
var i, j, x = new Float64Array(64);
|
|
2980
|
+
var p = [gf(), gf(), gf(), gf()];
|
|
2981
|
+
|
|
2982
|
+
crypto_hash(d, sk, 32);
|
|
2983
|
+
d[0] &= 248;
|
|
2984
|
+
d[31] &= 127;
|
|
2985
|
+
d[31] |= 64;
|
|
2986
|
+
|
|
2987
|
+
var smlen = n + 64;
|
|
2988
|
+
for (i = 0; i < n; i++) sm[64 + i] = m[i];
|
|
2989
|
+
for (i = 0; i < 32; i++) sm[32 + i] = d[32 + i];
|
|
2990
|
+
|
|
2991
|
+
crypto_hash(r, sm.subarray(32), n+32);
|
|
2992
|
+
reduce(r);
|
|
2993
|
+
scalarbase(p, r);
|
|
2994
|
+
pack(sm, p);
|
|
2995
|
+
|
|
2996
|
+
for (i = 32; i < 64; i++) sm[i] = sk[i];
|
|
2997
|
+
crypto_hash(h, sm, n + 64);
|
|
2998
|
+
reduce(h);
|
|
2999
|
+
|
|
3000
|
+
for (i = 0; i < 64; i++) x[i] = 0;
|
|
3001
|
+
for (i = 0; i < 32; i++) x[i] = r[i];
|
|
3002
|
+
for (i = 0; i < 32; i++) {
|
|
3003
|
+
for (j = 0; j < 32; j++) {
|
|
3004
|
+
x[i+j] += h[i] * d[j];
|
|
3005
|
+
}
|
|
3006
|
+
}
|
|
3007
|
+
|
|
3008
|
+
modL(sm.subarray(32), x);
|
|
3009
|
+
return smlen;
|
|
3010
|
+
}
|
|
3011
|
+
|
|
3012
|
+
function unpackneg(r, p) {
|
|
3013
|
+
var t = gf(), chk = gf(), num = gf(),
|
|
3014
|
+
den = gf(), den2 = gf(), den4 = gf(),
|
|
3015
|
+
den6 = gf();
|
|
3016
|
+
|
|
3017
|
+
set25519(r[2], gf1);
|
|
3018
|
+
unpack25519(r[1], p);
|
|
3019
|
+
S(num, r[1]);
|
|
3020
|
+
M(den, num, D);
|
|
3021
|
+
Z(num, num, r[2]);
|
|
3022
|
+
A(den, r[2], den);
|
|
3023
|
+
|
|
3024
|
+
S(den2, den);
|
|
3025
|
+
S(den4, den2);
|
|
3026
|
+
M(den6, den4, den2);
|
|
3027
|
+
M(t, den6, num);
|
|
3028
|
+
M(t, t, den);
|
|
3029
|
+
|
|
3030
|
+
pow2523(t, t);
|
|
3031
|
+
M(t, t, num);
|
|
3032
|
+
M(t, t, den);
|
|
3033
|
+
M(t, t, den);
|
|
3034
|
+
M(r[0], t, den);
|
|
3035
|
+
|
|
3036
|
+
S(chk, r[0]);
|
|
3037
|
+
M(chk, chk, den);
|
|
3038
|
+
if (neq25519(chk, num)) M(r[0], r[0], I);
|
|
3039
|
+
|
|
3040
|
+
S(chk, r[0]);
|
|
3041
|
+
M(chk, chk, den);
|
|
3042
|
+
if (neq25519(chk, num)) return -1;
|
|
3043
|
+
|
|
3044
|
+
if (par25519(r[0]) === (p[31]>>7)) Z(r[0], gf0, r[0]);
|
|
3045
|
+
|
|
3046
|
+
M(r[3], r[0], r[1]);
|
|
3047
|
+
return 0;
|
|
3048
|
+
}
|
|
3049
|
+
|
|
3050
|
+
function crypto_sign_open(m, sm, n, pk) {
|
|
3051
|
+
var i;
|
|
3052
|
+
var t = new Uint8Array(32), h = new Uint8Array(64);
|
|
3053
|
+
var p = [gf(), gf(), gf(), gf()],
|
|
3054
|
+
q = [gf(), gf(), gf(), gf()];
|
|
3055
|
+
|
|
3056
|
+
if (n < 64) return -1;
|
|
3057
|
+
|
|
3058
|
+
if (unpackneg(q, pk)) return -1;
|
|
3059
|
+
|
|
3060
|
+
for (i = 0; i < n; i++) m[i] = sm[i];
|
|
3061
|
+
for (i = 0; i < 32; i++) m[i+32] = pk[i];
|
|
3062
|
+
crypto_hash(h, m, n);
|
|
3063
|
+
reduce(h);
|
|
3064
|
+
scalarmult(p, q, h);
|
|
3065
|
+
|
|
3066
|
+
scalarbase(q, sm.subarray(32));
|
|
3067
|
+
add(p, q);
|
|
3068
|
+
pack(t, p);
|
|
3069
|
+
|
|
3070
|
+
n -= 64;
|
|
3071
|
+
if (crypto_verify_32(sm, 0, t, 0)) {
|
|
3072
|
+
for (i = 0; i < n; i++) m[i] = 0;
|
|
3073
|
+
return -1;
|
|
3074
|
+
}
|
|
3075
|
+
|
|
3076
|
+
for (i = 0; i < n; i++) m[i] = sm[i + 64];
|
|
3077
|
+
return n;
|
|
3078
|
+
}
|
|
3079
|
+
|
|
3080
|
+
var crypto_secretbox_KEYBYTES = 32,
|
|
3081
|
+
crypto_secretbox_NONCEBYTES = 24,
|
|
3082
|
+
crypto_secretbox_ZEROBYTES = 32,
|
|
3083
|
+
crypto_secretbox_BOXZEROBYTES = 16,
|
|
3084
|
+
crypto_scalarmult_BYTES = 32,
|
|
3085
|
+
crypto_scalarmult_SCALARBYTES = 32,
|
|
3086
|
+
crypto_box_PUBLICKEYBYTES = 32,
|
|
3087
|
+
crypto_box_SECRETKEYBYTES = 32,
|
|
3088
|
+
crypto_box_BEFORENMBYTES = 32,
|
|
3089
|
+
crypto_box_NONCEBYTES = crypto_secretbox_NONCEBYTES,
|
|
3090
|
+
crypto_box_ZEROBYTES = crypto_secretbox_ZEROBYTES,
|
|
3091
|
+
crypto_box_BOXZEROBYTES = crypto_secretbox_BOXZEROBYTES,
|
|
3092
|
+
crypto_sign_BYTES = 64,
|
|
3093
|
+
crypto_sign_PUBLICKEYBYTES = 32,
|
|
3094
|
+
crypto_sign_SECRETKEYBYTES = 64,
|
|
3095
|
+
crypto_sign_SEEDBYTES = 32,
|
|
3096
|
+
crypto_hash_BYTES = 64;
|
|
3097
|
+
|
|
3098
|
+
nacl.lowlevel = {
|
|
3099
|
+
crypto_core_hsalsa20: crypto_core_hsalsa20,
|
|
3100
|
+
crypto_stream_xor: crypto_stream_xor,
|
|
3101
|
+
crypto_stream: crypto_stream,
|
|
3102
|
+
crypto_stream_salsa20_xor: crypto_stream_salsa20_xor,
|
|
3103
|
+
crypto_stream_salsa20: crypto_stream_salsa20,
|
|
3104
|
+
crypto_onetimeauth: crypto_onetimeauth,
|
|
3105
|
+
crypto_onetimeauth_verify: crypto_onetimeauth_verify,
|
|
3106
|
+
crypto_verify_16: crypto_verify_16,
|
|
3107
|
+
crypto_verify_32: crypto_verify_32,
|
|
3108
|
+
crypto_secretbox: crypto_secretbox,
|
|
3109
|
+
crypto_secretbox_open: crypto_secretbox_open,
|
|
3110
|
+
crypto_scalarmult: crypto_scalarmult,
|
|
3111
|
+
crypto_scalarmult_base: crypto_scalarmult_base,
|
|
3112
|
+
crypto_box_beforenm: crypto_box_beforenm,
|
|
3113
|
+
crypto_box_afternm: crypto_box_afternm,
|
|
3114
|
+
crypto_box: crypto_box,
|
|
3115
|
+
crypto_box_open: crypto_box_open,
|
|
3116
|
+
crypto_box_keypair: crypto_box_keypair,
|
|
3117
|
+
crypto_hash: crypto_hash,
|
|
3118
|
+
crypto_sign: crypto_sign,
|
|
3119
|
+
crypto_sign_keypair: crypto_sign_keypair,
|
|
3120
|
+
crypto_sign_open: crypto_sign_open,
|
|
3121
|
+
|
|
3122
|
+
crypto_secretbox_KEYBYTES: crypto_secretbox_KEYBYTES,
|
|
3123
|
+
crypto_secretbox_NONCEBYTES: crypto_secretbox_NONCEBYTES,
|
|
3124
|
+
crypto_secretbox_ZEROBYTES: crypto_secretbox_ZEROBYTES,
|
|
3125
|
+
crypto_secretbox_BOXZEROBYTES: crypto_secretbox_BOXZEROBYTES,
|
|
3126
|
+
crypto_scalarmult_BYTES: crypto_scalarmult_BYTES,
|
|
3127
|
+
crypto_scalarmult_SCALARBYTES: crypto_scalarmult_SCALARBYTES,
|
|
3128
|
+
crypto_box_PUBLICKEYBYTES: crypto_box_PUBLICKEYBYTES,
|
|
3129
|
+
crypto_box_SECRETKEYBYTES: crypto_box_SECRETKEYBYTES,
|
|
3130
|
+
crypto_box_BEFORENMBYTES: crypto_box_BEFORENMBYTES,
|
|
3131
|
+
crypto_box_NONCEBYTES: crypto_box_NONCEBYTES,
|
|
3132
|
+
crypto_box_ZEROBYTES: crypto_box_ZEROBYTES,
|
|
3133
|
+
crypto_box_BOXZEROBYTES: crypto_box_BOXZEROBYTES,
|
|
3134
|
+
crypto_sign_BYTES: crypto_sign_BYTES,
|
|
3135
|
+
crypto_sign_PUBLICKEYBYTES: crypto_sign_PUBLICKEYBYTES,
|
|
3136
|
+
crypto_sign_SECRETKEYBYTES: crypto_sign_SECRETKEYBYTES,
|
|
3137
|
+
crypto_sign_SEEDBYTES: crypto_sign_SEEDBYTES,
|
|
3138
|
+
crypto_hash_BYTES: crypto_hash_BYTES,
|
|
3139
|
+
|
|
3140
|
+
gf: gf,
|
|
3141
|
+
D: D,
|
|
3142
|
+
L: L,
|
|
3143
|
+
pack25519: pack25519,
|
|
3144
|
+
unpack25519: unpack25519,
|
|
3145
|
+
M: M,
|
|
3146
|
+
A: A,
|
|
3147
|
+
S: S,
|
|
3148
|
+
Z: Z,
|
|
3149
|
+
pow2523: pow2523,
|
|
3150
|
+
add: add,
|
|
3151
|
+
set25519: set25519,
|
|
3152
|
+
modL: modL,
|
|
3153
|
+
scalarmult: scalarmult,
|
|
3154
|
+
scalarbase: scalarbase,
|
|
3155
|
+
};
|
|
3156
|
+
|
|
3157
|
+
/* High-level API */
|
|
3158
|
+
|
|
3159
|
+
function checkLengths(k, n) {
|
|
3160
|
+
if (k.length !== crypto_secretbox_KEYBYTES) throw new Error('bad key size');
|
|
3161
|
+
if (n.length !== crypto_secretbox_NONCEBYTES) throw new Error('bad nonce size');
|
|
3162
|
+
}
|
|
3163
|
+
|
|
3164
|
+
function checkBoxLengths(pk, sk) {
|
|
3165
|
+
if (pk.length !== crypto_box_PUBLICKEYBYTES) throw new Error('bad public key size');
|
|
3166
|
+
if (sk.length !== crypto_box_SECRETKEYBYTES) throw new Error('bad secret key size');
|
|
3167
|
+
}
|
|
3168
|
+
|
|
3169
|
+
function checkArrayTypes() {
|
|
3170
|
+
for (var i = 0; i < arguments.length; i++) {
|
|
3171
|
+
if (!(arguments[i] instanceof Uint8Array))
|
|
3172
|
+
throw new TypeError('unexpected type, use Uint8Array');
|
|
3173
|
+
}
|
|
3174
|
+
}
|
|
3175
|
+
|
|
3176
|
+
function cleanup(arr) {
|
|
3177
|
+
for (var i = 0; i < arr.length; i++) arr[i] = 0;
|
|
3178
|
+
}
|
|
3179
|
+
|
|
3180
|
+
nacl.randomBytes = function(n) {
|
|
3181
|
+
var b = new Uint8Array(n);
|
|
3182
|
+
randombytes(b, n);
|
|
3183
|
+
return b;
|
|
3184
|
+
};
|
|
3185
|
+
|
|
3186
|
+
nacl.secretbox = function(msg, nonce, key) {
|
|
3187
|
+
checkArrayTypes(msg, nonce, key);
|
|
3188
|
+
checkLengths(key, nonce);
|
|
3189
|
+
var m = new Uint8Array(crypto_secretbox_ZEROBYTES + msg.length);
|
|
3190
|
+
var c = new Uint8Array(m.length);
|
|
3191
|
+
for (var i = 0; i < msg.length; i++) m[i+crypto_secretbox_ZEROBYTES] = msg[i];
|
|
3192
|
+
crypto_secretbox(c, m, m.length, nonce, key);
|
|
3193
|
+
return c.subarray(crypto_secretbox_BOXZEROBYTES);
|
|
3194
|
+
};
|
|
3195
|
+
|
|
3196
|
+
nacl.secretbox.open = function(box, nonce, key) {
|
|
3197
|
+
checkArrayTypes(box, nonce, key);
|
|
3198
|
+
checkLengths(key, nonce);
|
|
3199
|
+
var c = new Uint8Array(crypto_secretbox_BOXZEROBYTES + box.length);
|
|
3200
|
+
var m = new Uint8Array(c.length);
|
|
3201
|
+
for (var i = 0; i < box.length; i++) c[i+crypto_secretbox_BOXZEROBYTES] = box[i];
|
|
3202
|
+
if (c.length < 32) return null;
|
|
3203
|
+
if (crypto_secretbox_open(m, c, c.length, nonce, key) !== 0) return null;
|
|
3204
|
+
return m.subarray(crypto_secretbox_ZEROBYTES);
|
|
3205
|
+
};
|
|
3206
|
+
|
|
3207
|
+
nacl.secretbox.keyLength = crypto_secretbox_KEYBYTES;
|
|
3208
|
+
nacl.secretbox.nonceLength = crypto_secretbox_NONCEBYTES;
|
|
3209
|
+
nacl.secretbox.overheadLength = crypto_secretbox_BOXZEROBYTES;
|
|
3210
|
+
|
|
3211
|
+
nacl.scalarMult = function(n, p) {
|
|
3212
|
+
checkArrayTypes(n, p);
|
|
3213
|
+
if (n.length !== crypto_scalarmult_SCALARBYTES) throw new Error('bad n size');
|
|
3214
|
+
if (p.length !== crypto_scalarmult_BYTES) throw new Error('bad p size');
|
|
3215
|
+
var q = new Uint8Array(crypto_scalarmult_BYTES);
|
|
3216
|
+
crypto_scalarmult(q, n, p);
|
|
3217
|
+
return q;
|
|
3218
|
+
};
|
|
3219
|
+
|
|
3220
|
+
nacl.scalarMult.base = function(n) {
|
|
3221
|
+
checkArrayTypes(n);
|
|
3222
|
+
if (n.length !== crypto_scalarmult_SCALARBYTES) throw new Error('bad n size');
|
|
3223
|
+
var q = new Uint8Array(crypto_scalarmult_BYTES);
|
|
3224
|
+
crypto_scalarmult_base(q, n);
|
|
3225
|
+
return q;
|
|
3226
|
+
};
|
|
3227
|
+
|
|
3228
|
+
nacl.scalarMult.scalarLength = crypto_scalarmult_SCALARBYTES;
|
|
3229
|
+
nacl.scalarMult.groupElementLength = crypto_scalarmult_BYTES;
|
|
3230
|
+
|
|
3231
|
+
nacl.box = function(msg, nonce, publicKey, secretKey) {
|
|
3232
|
+
var k = nacl.box.before(publicKey, secretKey);
|
|
3233
|
+
return nacl.secretbox(msg, nonce, k);
|
|
3234
|
+
};
|
|
3235
|
+
|
|
3236
|
+
nacl.box.before = function(publicKey, secretKey) {
|
|
3237
|
+
checkArrayTypes(publicKey, secretKey);
|
|
3238
|
+
checkBoxLengths(publicKey, secretKey);
|
|
3239
|
+
var k = new Uint8Array(crypto_box_BEFORENMBYTES);
|
|
3240
|
+
crypto_box_beforenm(k, publicKey, secretKey);
|
|
3241
|
+
return k;
|
|
3242
|
+
};
|
|
3243
|
+
|
|
3244
|
+
nacl.box.after = nacl.secretbox;
|
|
3245
|
+
|
|
3246
|
+
nacl.box.open = function(msg, nonce, publicKey, secretKey) {
|
|
3247
|
+
var k = nacl.box.before(publicKey, secretKey);
|
|
3248
|
+
return nacl.secretbox.open(msg, nonce, k);
|
|
3249
|
+
};
|
|
3250
|
+
|
|
3251
|
+
nacl.box.open.after = nacl.secretbox.open;
|
|
3252
|
+
|
|
3253
|
+
nacl.box.keyPair = function() {
|
|
3254
|
+
var pk = new Uint8Array(crypto_box_PUBLICKEYBYTES);
|
|
3255
|
+
var sk = new Uint8Array(crypto_box_SECRETKEYBYTES);
|
|
3256
|
+
crypto_box_keypair(pk, sk);
|
|
3257
|
+
return {publicKey: pk, secretKey: sk};
|
|
3258
|
+
};
|
|
3259
|
+
|
|
3260
|
+
nacl.box.keyPair.fromSecretKey = function(secretKey) {
|
|
3261
|
+
checkArrayTypes(secretKey);
|
|
3262
|
+
if (secretKey.length !== crypto_box_SECRETKEYBYTES)
|
|
3263
|
+
throw new Error('bad secret key size');
|
|
3264
|
+
var pk = new Uint8Array(crypto_box_PUBLICKEYBYTES);
|
|
3265
|
+
crypto_scalarmult_base(pk, secretKey);
|
|
3266
|
+
return {publicKey: pk, secretKey: new Uint8Array(secretKey)};
|
|
3267
|
+
};
|
|
3268
|
+
|
|
3269
|
+
nacl.box.publicKeyLength = crypto_box_PUBLICKEYBYTES;
|
|
3270
|
+
nacl.box.secretKeyLength = crypto_box_SECRETKEYBYTES;
|
|
3271
|
+
nacl.box.sharedKeyLength = crypto_box_BEFORENMBYTES;
|
|
3272
|
+
nacl.box.nonceLength = crypto_box_NONCEBYTES;
|
|
3273
|
+
nacl.box.overheadLength = nacl.secretbox.overheadLength;
|
|
3274
|
+
|
|
3275
|
+
nacl.sign = function(msg, secretKey) {
|
|
3276
|
+
checkArrayTypes(msg, secretKey);
|
|
3277
|
+
if (secretKey.length !== crypto_sign_SECRETKEYBYTES)
|
|
3278
|
+
throw new Error('bad secret key size');
|
|
3279
|
+
var signedMsg = new Uint8Array(crypto_sign_BYTES+msg.length);
|
|
3280
|
+
crypto_sign(signedMsg, msg, msg.length, secretKey);
|
|
3281
|
+
return signedMsg;
|
|
3282
|
+
};
|
|
3283
|
+
|
|
3284
|
+
nacl.sign.open = function(signedMsg, publicKey) {
|
|
3285
|
+
checkArrayTypes(signedMsg, publicKey);
|
|
3286
|
+
if (publicKey.length !== crypto_sign_PUBLICKEYBYTES)
|
|
3287
|
+
throw new Error('bad public key size');
|
|
3288
|
+
var tmp = new Uint8Array(signedMsg.length);
|
|
3289
|
+
var mlen = crypto_sign_open(tmp, signedMsg, signedMsg.length, publicKey);
|
|
3290
|
+
if (mlen < 0) return null;
|
|
3291
|
+
var m = new Uint8Array(mlen);
|
|
3292
|
+
for (var i = 0; i < m.length; i++) m[i] = tmp[i];
|
|
3293
|
+
return m;
|
|
3294
|
+
};
|
|
3295
|
+
|
|
3296
|
+
nacl.sign.detached = function(msg, secretKey) {
|
|
3297
|
+
var signedMsg = nacl.sign(msg, secretKey);
|
|
3298
|
+
var sig = new Uint8Array(crypto_sign_BYTES);
|
|
3299
|
+
for (var i = 0; i < sig.length; i++) sig[i] = signedMsg[i];
|
|
3300
|
+
return sig;
|
|
3301
|
+
};
|
|
3302
|
+
|
|
3303
|
+
nacl.sign.detached.verify = function(msg, sig, publicKey) {
|
|
3304
|
+
checkArrayTypes(msg, sig, publicKey);
|
|
3305
|
+
if (sig.length !== crypto_sign_BYTES)
|
|
3306
|
+
throw new Error('bad signature size');
|
|
3307
|
+
if (publicKey.length !== crypto_sign_PUBLICKEYBYTES)
|
|
3308
|
+
throw new Error('bad public key size');
|
|
3309
|
+
var sm = new Uint8Array(crypto_sign_BYTES + msg.length);
|
|
3310
|
+
var m = new Uint8Array(crypto_sign_BYTES + msg.length);
|
|
3311
|
+
var i;
|
|
3312
|
+
for (i = 0; i < crypto_sign_BYTES; i++) sm[i] = sig[i];
|
|
3313
|
+
for (i = 0; i < msg.length; i++) sm[i+crypto_sign_BYTES] = msg[i];
|
|
3314
|
+
return (crypto_sign_open(m, sm, sm.length, publicKey) >= 0);
|
|
3315
|
+
};
|
|
3316
|
+
|
|
3317
|
+
nacl.sign.keyPair = function() {
|
|
3318
|
+
var pk = new Uint8Array(crypto_sign_PUBLICKEYBYTES);
|
|
3319
|
+
var sk = new Uint8Array(crypto_sign_SECRETKEYBYTES);
|
|
3320
|
+
crypto_sign_keypair(pk, sk);
|
|
3321
|
+
return {publicKey: pk, secretKey: sk};
|
|
3322
|
+
};
|
|
3323
|
+
|
|
3324
|
+
nacl.sign.keyPair.fromSecretKey = function(secretKey) {
|
|
3325
|
+
checkArrayTypes(secretKey);
|
|
3326
|
+
if (secretKey.length !== crypto_sign_SECRETKEYBYTES)
|
|
3327
|
+
throw new Error('bad secret key size');
|
|
3328
|
+
var pk = new Uint8Array(crypto_sign_PUBLICKEYBYTES);
|
|
3329
|
+
for (var i = 0; i < pk.length; i++) pk[i] = secretKey[32+i];
|
|
3330
|
+
return {publicKey: pk, secretKey: new Uint8Array(secretKey)};
|
|
3331
|
+
};
|
|
3332
|
+
|
|
3333
|
+
nacl.sign.keyPair.fromSeed = function(seed) {
|
|
3334
|
+
checkArrayTypes(seed);
|
|
3335
|
+
if (seed.length !== crypto_sign_SEEDBYTES)
|
|
3336
|
+
throw new Error('bad seed size');
|
|
3337
|
+
var pk = new Uint8Array(crypto_sign_PUBLICKEYBYTES);
|
|
3338
|
+
var sk = new Uint8Array(crypto_sign_SECRETKEYBYTES);
|
|
3339
|
+
for (var i = 0; i < 32; i++) sk[i] = seed[i];
|
|
3340
|
+
crypto_sign_keypair(pk, sk, true);
|
|
3341
|
+
return {publicKey: pk, secretKey: sk};
|
|
3342
|
+
};
|
|
3343
|
+
|
|
3344
|
+
nacl.sign.publicKeyLength = crypto_sign_PUBLICKEYBYTES;
|
|
3345
|
+
nacl.sign.secretKeyLength = crypto_sign_SECRETKEYBYTES;
|
|
3346
|
+
nacl.sign.seedLength = crypto_sign_SEEDBYTES;
|
|
3347
|
+
nacl.sign.signatureLength = crypto_sign_BYTES;
|
|
3348
|
+
|
|
3349
|
+
nacl.hash = function(msg) {
|
|
3350
|
+
checkArrayTypes(msg);
|
|
3351
|
+
var h = new Uint8Array(crypto_hash_BYTES);
|
|
3352
|
+
crypto_hash(h, msg, msg.length);
|
|
3353
|
+
return h;
|
|
3354
|
+
};
|
|
3355
|
+
|
|
3356
|
+
nacl.hash.hashLength = crypto_hash_BYTES;
|
|
3357
|
+
|
|
3358
|
+
nacl.verify = function(x, y) {
|
|
3359
|
+
checkArrayTypes(x, y);
|
|
3360
|
+
// Zero length arguments are considered not equal.
|
|
3361
|
+
if (x.length === 0 || y.length === 0) return false;
|
|
3362
|
+
if (x.length !== y.length) return false;
|
|
3363
|
+
return (vn(x, 0, y, 0, x.length) === 0) ? true : false;
|
|
3364
|
+
};
|
|
3365
|
+
|
|
3366
|
+
nacl.setPRNG = function(fn) {
|
|
3367
|
+
randombytes = fn;
|
|
3368
|
+
};
|
|
3369
|
+
|
|
3370
|
+
(function() {
|
|
3371
|
+
// Initialize PRNG if environment provides CSPRNG.
|
|
3372
|
+
// If not, methods calling randombytes will throw.
|
|
3373
|
+
var crypto = typeof self !== 'undefined' ? (self.crypto || self.msCrypto) : null;
|
|
3374
|
+
if (crypto && crypto.getRandomValues) {
|
|
3375
|
+
// Browsers.
|
|
3376
|
+
var QUOTA = 65536;
|
|
3377
|
+
nacl.setPRNG(function(x, n) {
|
|
3378
|
+
var i, v = new Uint8Array(n);
|
|
3379
|
+
for (i = 0; i < n; i += QUOTA) {
|
|
3380
|
+
crypto.getRandomValues(v.subarray(i, i + Math.min(n - i, QUOTA)));
|
|
3381
|
+
}
|
|
3382
|
+
for (i = 0; i < n; i++) x[i] = v[i];
|
|
3383
|
+
cleanup(v);
|
|
3384
|
+
});
|
|
3385
|
+
} else if (typeof commonjsRequire !== 'undefined') {
|
|
3386
|
+
// Node.js.
|
|
3387
|
+
crypto = require$$0;
|
|
3388
|
+
if (crypto && crypto.randomBytes) {
|
|
3389
|
+
nacl.setPRNG(function(x, n) {
|
|
3390
|
+
var i, v = crypto.randomBytes(n);
|
|
3391
|
+
for (i = 0; i < n; i++) x[i] = v[i];
|
|
3392
|
+
cleanup(v);
|
|
3393
|
+
});
|
|
3394
|
+
}
|
|
3395
|
+
}
|
|
3396
|
+
})();
|
|
3397
|
+
|
|
3398
|
+
})(module.exports ? module.exports : (self.nacl = self.nacl || {}));
|
|
3399
|
+
} (naclFast));
|
|
3400
|
+
return naclFast.exports;
|
|
3401
|
+
}
|
|
3402
|
+
|
|
3403
|
+
requireNaclFast();
|
|
3404
|
+
|
|
3405
|
+
var src;
|
|
3406
|
+
var hasRequiredSrc;
|
|
3407
|
+
|
|
3408
|
+
function requireSrc () {
|
|
3409
|
+
if (hasRequiredSrc) return src;
|
|
3410
|
+
hasRequiredSrc = 1;
|
|
3411
|
+
// base-x encoding / decoding
|
|
3412
|
+
// Copyright (c) 2018 base-x contributors
|
|
3413
|
+
// Copyright (c) 2014-2018 The Bitcoin Core developers (base58.cpp)
|
|
3414
|
+
// Distributed under the MIT software license, see the accompanying
|
|
3415
|
+
// file LICENSE or http://www.opensource.org/licenses/mit-license.php.
|
|
3416
|
+
function base (ALPHABET) {
|
|
3417
|
+
if (ALPHABET.length >= 255) { throw new TypeError('Alphabet too long') }
|
|
3418
|
+
var BASE_MAP = new Uint8Array(256);
|
|
3419
|
+
for (var j = 0; j < BASE_MAP.length; j++) {
|
|
3420
|
+
BASE_MAP[j] = 255;
|
|
3421
|
+
}
|
|
3422
|
+
for (var i = 0; i < ALPHABET.length; i++) {
|
|
3423
|
+
var x = ALPHABET.charAt(i);
|
|
3424
|
+
var xc = x.charCodeAt(0);
|
|
3425
|
+
if (BASE_MAP[xc] !== 255) { throw new TypeError(x + ' is ambiguous') }
|
|
3426
|
+
BASE_MAP[xc] = i;
|
|
3427
|
+
}
|
|
3428
|
+
var BASE = ALPHABET.length;
|
|
3429
|
+
var LEADER = ALPHABET.charAt(0);
|
|
3430
|
+
var FACTOR = Math.log(BASE) / Math.log(256); // log(BASE) / log(256), rounded up
|
|
3431
|
+
var iFACTOR = Math.log(256) / Math.log(BASE); // log(256) / log(BASE), rounded up
|
|
3432
|
+
function encode (source) {
|
|
3433
|
+
if (source instanceof Uint8Array) ; else if (ArrayBuffer.isView(source)) {
|
|
3434
|
+
source = new Uint8Array(source.buffer, source.byteOffset, source.byteLength);
|
|
3435
|
+
} else if (Array.isArray(source)) {
|
|
3436
|
+
source = Uint8Array.from(source);
|
|
3437
|
+
}
|
|
3438
|
+
if (!(source instanceof Uint8Array)) { throw new TypeError('Expected Uint8Array') }
|
|
3439
|
+
if (source.length === 0) { return '' }
|
|
3440
|
+
// Skip & count leading zeroes.
|
|
3441
|
+
var zeroes = 0;
|
|
3442
|
+
var length = 0;
|
|
3443
|
+
var pbegin = 0;
|
|
3444
|
+
var pend = source.length;
|
|
3445
|
+
while (pbegin !== pend && source[pbegin] === 0) {
|
|
3446
|
+
pbegin++;
|
|
3447
|
+
zeroes++;
|
|
3448
|
+
}
|
|
3449
|
+
// Allocate enough space in big-endian base58 representation.
|
|
3450
|
+
var size = ((pend - pbegin) * iFACTOR + 1) >>> 0;
|
|
3451
|
+
var b58 = new Uint8Array(size);
|
|
3452
|
+
// Process the bytes.
|
|
3453
|
+
while (pbegin !== pend) {
|
|
3454
|
+
var carry = source[pbegin];
|
|
3455
|
+
// Apply "b58 = b58 * 256 + ch".
|
|
3456
|
+
var i = 0;
|
|
3457
|
+
for (var it1 = size - 1; (carry !== 0 || i < length) && (it1 !== -1); it1--, i++) {
|
|
3458
|
+
carry += (256 * b58[it1]) >>> 0;
|
|
3459
|
+
b58[it1] = (carry % BASE) >>> 0;
|
|
3460
|
+
carry = (carry / BASE) >>> 0;
|
|
3461
|
+
}
|
|
3462
|
+
if (carry !== 0) { throw new Error('Non-zero carry') }
|
|
3463
|
+
length = i;
|
|
3464
|
+
pbegin++;
|
|
3465
|
+
}
|
|
3466
|
+
// Skip leading zeroes in base58 result.
|
|
3467
|
+
var it2 = size - length;
|
|
3468
|
+
while (it2 !== size && b58[it2] === 0) {
|
|
3469
|
+
it2++;
|
|
3470
|
+
}
|
|
3471
|
+
// Translate the result into a string.
|
|
3472
|
+
var str = LEADER.repeat(zeroes);
|
|
3473
|
+
for (; it2 < size; ++it2) { str += ALPHABET.charAt(b58[it2]); }
|
|
3474
|
+
return str
|
|
3475
|
+
}
|
|
3476
|
+
function decodeUnsafe (source) {
|
|
3477
|
+
if (typeof source !== 'string') { throw new TypeError('Expected String') }
|
|
3478
|
+
if (source.length === 0) { return new Uint8Array() }
|
|
3479
|
+
var psz = 0;
|
|
3480
|
+
// Skip and count leading '1's.
|
|
3481
|
+
var zeroes = 0;
|
|
3482
|
+
var length = 0;
|
|
3483
|
+
while (source[psz] === LEADER) {
|
|
3484
|
+
zeroes++;
|
|
3485
|
+
psz++;
|
|
3486
|
+
}
|
|
3487
|
+
// Allocate enough space in big-endian base256 representation.
|
|
3488
|
+
var size = (((source.length - psz) * FACTOR) + 1) >>> 0; // log(58) / log(256), rounded up.
|
|
3489
|
+
var b256 = new Uint8Array(size);
|
|
3490
|
+
// Process the characters.
|
|
3491
|
+
while (source[psz]) {
|
|
3492
|
+
// Find code of next character
|
|
3493
|
+
var charCode = source.charCodeAt(psz);
|
|
3494
|
+
// Base map can not be indexed using char code
|
|
3495
|
+
if (charCode > 255) { return }
|
|
3496
|
+
// Decode character
|
|
3497
|
+
var carry = BASE_MAP[charCode];
|
|
3498
|
+
// Invalid character
|
|
3499
|
+
if (carry === 255) { return }
|
|
3500
|
+
var i = 0;
|
|
3501
|
+
for (var it3 = size - 1; (carry !== 0 || i < length) && (it3 !== -1); it3--, i++) {
|
|
3502
|
+
carry += (BASE * b256[it3]) >>> 0;
|
|
3503
|
+
b256[it3] = (carry % 256) >>> 0;
|
|
3504
|
+
carry = (carry / 256) >>> 0;
|
|
3505
|
+
}
|
|
3506
|
+
if (carry !== 0) { throw new Error('Non-zero carry') }
|
|
3507
|
+
length = i;
|
|
3508
|
+
psz++;
|
|
3509
|
+
}
|
|
3510
|
+
// Skip leading zeroes in b256.
|
|
3511
|
+
var it4 = size - length;
|
|
3512
|
+
while (it4 !== size && b256[it4] === 0) {
|
|
3513
|
+
it4++;
|
|
3514
|
+
}
|
|
3515
|
+
var vch = new Uint8Array(zeroes + (size - it4));
|
|
3516
|
+
var j = zeroes;
|
|
3517
|
+
while (it4 !== size) {
|
|
3518
|
+
vch[j++] = b256[it4++];
|
|
3519
|
+
}
|
|
3520
|
+
return vch
|
|
3521
|
+
}
|
|
3522
|
+
function decode (string) {
|
|
3523
|
+
var buffer = decodeUnsafe(string);
|
|
3524
|
+
if (buffer) { return buffer }
|
|
3525
|
+
throw new Error('Non-base' + BASE + ' character')
|
|
3526
|
+
}
|
|
3527
|
+
return {
|
|
3528
|
+
encode: encode,
|
|
3529
|
+
decodeUnsafe: decodeUnsafe,
|
|
3530
|
+
decode: decode
|
|
3531
|
+
}
|
|
3532
|
+
}
|
|
3533
|
+
src = base;
|
|
3534
|
+
return src;
|
|
3535
|
+
}
|
|
3536
|
+
|
|
3537
|
+
var bs58$2;
|
|
3538
|
+
var hasRequiredBs58;
|
|
3539
|
+
|
|
3540
|
+
function requireBs58 () {
|
|
3541
|
+
if (hasRequiredBs58) return bs58$2;
|
|
3542
|
+
hasRequiredBs58 = 1;
|
|
3543
|
+
const basex = requireSrc();
|
|
3544
|
+
const ALPHABET = '123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz';
|
|
3545
|
+
|
|
3546
|
+
bs58$2 = basex(ALPHABET);
|
|
3547
|
+
return bs58$2;
|
|
3548
|
+
}
|
|
3549
|
+
|
|
3550
|
+
requireBs58();
|
|
3551
|
+
|
|
3552
|
+
// src/PhantomClient.ts
|
|
3553
|
+
var CAIP2_NETWORK_MAPPINGS = {
|
|
3554
|
+
// Solana networks
|
|
3555
|
+
[NetworkId.SOLANA_MAINNET]: {
|
|
3556
|
+
chain: "solana",
|
|
3557
|
+
network: "mainnet",
|
|
3558
|
+
description: "Solana Mainnet-Beta"
|
|
3559
|
+
},
|
|
3560
|
+
[NetworkId.SOLANA_DEVNET]: {
|
|
3561
|
+
chain: "solana",
|
|
3562
|
+
network: "devnet",
|
|
3563
|
+
description: "Solana Devnet"
|
|
3564
|
+
},
|
|
3565
|
+
[NetworkId.SOLANA_TESTNET]: {
|
|
3566
|
+
chain: "solana",
|
|
3567
|
+
network: "testnet",
|
|
3568
|
+
description: "Solana Testnet"
|
|
3569
|
+
},
|
|
3570
|
+
// Ethereum/EVM networks
|
|
3571
|
+
[NetworkId.ETHEREUM_MAINNET]: {
|
|
3572
|
+
chain: "ethereum",
|
|
3573
|
+
network: "mainnet",
|
|
3574
|
+
description: "Ethereum Mainnet"
|
|
3575
|
+
},
|
|
3576
|
+
[NetworkId.ETHEREUM_SEPOLIA]: {
|
|
3577
|
+
chain: "ethereum",
|
|
3578
|
+
network: "sepolia",
|
|
3579
|
+
description: "Sepolia Testnet"
|
|
3580
|
+
},
|
|
3581
|
+
[NetworkId.POLYGON_MAINNET]: {
|
|
3582
|
+
chain: "polygon",
|
|
3583
|
+
network: "mainnet",
|
|
3584
|
+
description: "Polygon Mainnet"
|
|
3585
|
+
},
|
|
3586
|
+
[NetworkId.POLYGON_AMOY]: {
|
|
3587
|
+
chain: "polygon",
|
|
3588
|
+
network: "amoy",
|
|
3589
|
+
description: "Polygon Amoy Testnet"
|
|
3590
|
+
},
|
|
3591
|
+
[NetworkId.BASE_MAINNET]: {
|
|
3592
|
+
chain: "base",
|
|
3593
|
+
network: "mainnet",
|
|
3594
|
+
description: "Base Mainnet"
|
|
3595
|
+
},
|
|
3596
|
+
[NetworkId.BASE_SEPOLIA]: {
|
|
3597
|
+
chain: "base",
|
|
3598
|
+
network: "sepolia",
|
|
3599
|
+
description: "Base Sepolia Testnet"
|
|
3600
|
+
},
|
|
3601
|
+
[NetworkId.ARBITRUM_ONE]: {
|
|
3602
|
+
chain: "arbitrum",
|
|
3603
|
+
network: "mainnet",
|
|
3604
|
+
description: "Arbitrum One"
|
|
3605
|
+
},
|
|
3606
|
+
[NetworkId.ARBITRUM_SEPOLIA]: {
|
|
3607
|
+
chain: "arbitrum",
|
|
3608
|
+
network: "sepolia",
|
|
3609
|
+
description: "Arbitrum Sepolia Testnet"
|
|
3610
|
+
},
|
|
3611
|
+
[NetworkId.MONAD_MAINNET]: {
|
|
3612
|
+
chain: "monad",
|
|
3613
|
+
network: "mainnet",
|
|
3614
|
+
description: "Monad Mainnet"
|
|
3615
|
+
},
|
|
3616
|
+
[NetworkId.MONAD_TESTNET]: {
|
|
3617
|
+
chain: "monad",
|
|
3618
|
+
network: "testnet",
|
|
3619
|
+
description: "Monad Testnet"
|
|
3620
|
+
},
|
|
3621
|
+
// Bitcoin networks (for future support)
|
|
3622
|
+
[NetworkId.BITCOIN_MAINNET]: {
|
|
3623
|
+
chain: "bitcoin",
|
|
3624
|
+
network: "mainnet",
|
|
3625
|
+
description: "Bitcoin Mainnet"
|
|
3626
|
+
},
|
|
3627
|
+
[NetworkId.BITCOIN_TESTNET]: {
|
|
3628
|
+
chain: "bitcoin",
|
|
3629
|
+
network: "testnet",
|
|
3630
|
+
description: "Bitcoin Testnet"
|
|
3631
|
+
},
|
|
3632
|
+
// Sui networks (for future support)
|
|
3633
|
+
[NetworkId.SUI_MAINNET]: {
|
|
3634
|
+
chain: "sui",
|
|
3635
|
+
network: "mainnet",
|
|
3636
|
+
description: "Sui Mainnet"
|
|
3637
|
+
},
|
|
3638
|
+
[NetworkId.SUI_TESTNET]: {
|
|
3639
|
+
chain: "sui",
|
|
3640
|
+
network: "testnet",
|
|
3641
|
+
description: "Sui Testnet"
|
|
3642
|
+
}
|
|
3643
|
+
};
|
|
3644
|
+
function deriveSubmissionConfig(networkId) {
|
|
3645
|
+
const mapping = CAIP2_NETWORK_MAPPINGS[networkId];
|
|
3646
|
+
if (!mapping) {
|
|
3647
|
+
return void 0;
|
|
3648
|
+
}
|
|
3649
|
+
return {
|
|
3650
|
+
chain: mapping.chain,
|
|
3651
|
+
network: mapping.network
|
|
3652
|
+
};
|
|
3653
|
+
}
|
|
3654
|
+
var DerivationPath = {
|
|
3655
|
+
// Solana - BIP44 standard for Solana (coin type 501)
|
|
3656
|
+
Solana: (accountIndex = 0) => `m/44'/501'/${accountIndex}'/0'`,
|
|
3657
|
+
// Ethereum - BIP44 standard for Ethereum and all EVM-compatible chains (coin type 60)
|
|
3658
|
+
Ethereum: (accountIndex = 0) => `m/44'/60'/0'/0/${accountIndex}`,
|
|
3659
|
+
// Bitcoin - BIP84 standard for Bitcoin (coin type 0)
|
|
3660
|
+
Bitcoin: (accountIndex = 0) => `m/84'/0'/${accountIndex}'/0`,
|
|
3661
|
+
// Sui - BIP44 standard for Sui (coin type 784)
|
|
3662
|
+
Sui: (accountIndex = 0) => `m/44'/784'/${accountIndex}'/0'/0'`
|
|
3663
|
+
};
|
|
3664
|
+
function getNetworkConfig(networkId, accountIndex = 0) {
|
|
3665
|
+
const network = networkId.split(":")[0].toLowerCase();
|
|
3666
|
+
switch (network) {
|
|
3667
|
+
case "solana":
|
|
1264
3668
|
return {
|
|
1265
3669
|
derivationPath: DerivationPath.Solana(accountIndex),
|
|
1266
3670
|
curve: DerivationInfoCurveEnum.ed25519,
|
|
@@ -3100,13 +5504,13 @@ function createAutoConfirmPlugin() {
|
|
|
3100
5504
|
};
|
|
3101
5505
|
}
|
|
3102
5506
|
|
|
3103
|
-
var eventemitter3 = {exports: {}};
|
|
5507
|
+
var eventemitter3$1 = {exports: {}};
|
|
3104
5508
|
|
|
3105
|
-
var hasRequiredEventemitter3;
|
|
5509
|
+
var hasRequiredEventemitter3$1;
|
|
3106
5510
|
|
|
3107
|
-
function requireEventemitter3 () {
|
|
3108
|
-
if (hasRequiredEventemitter3) return eventemitter3.exports;
|
|
3109
|
-
hasRequiredEventemitter3 = 1;
|
|
5511
|
+
function requireEventemitter3$1 () {
|
|
5512
|
+
if (hasRequiredEventemitter3$1) return eventemitter3$1.exports;
|
|
5513
|
+
hasRequiredEventemitter3$1 = 1;
|
|
3110
5514
|
(function (module) {
|
|
3111
5515
|
|
|
3112
5516
|
var has = Object.prototype.hasOwnProperty
|
|
@@ -3443,12 +5847,12 @@ function requireEventemitter3 () {
|
|
|
3443
5847
|
{
|
|
3444
5848
|
module.exports = EventEmitter;
|
|
3445
5849
|
}
|
|
3446
|
-
} (eventemitter3));
|
|
3447
|
-
return eventemitter3.exports;
|
|
5850
|
+
} (eventemitter3$1));
|
|
5851
|
+
return eventemitter3$1.exports;
|
|
3448
5852
|
}
|
|
3449
5853
|
|
|
3450
|
-
var eventemitter3Exports = requireEventemitter3();
|
|
3451
|
-
var EventEmitter3 = /*@__PURE__*/getDefaultExportFromCjs(eventemitter3Exports);
|
|
5854
|
+
var eventemitter3Exports$1 = requireEventemitter3$1();
|
|
5855
|
+
var EventEmitter3 = /*@__PURE__*/getDefaultExportFromCjs(eventemitter3Exports$1);
|
|
3452
5856
|
|
|
3453
5857
|
// src/index.ts
|
|
3454
5858
|
var isBrowser = typeof window !== "undefined" && typeof window.btoa !== "undefined";
|
|
@@ -8769,300 +11173,904 @@ class Transaction {
|
|
|
8769
11173
|
assertArgument(result.isSigned(), "unsigned transaction cannot define '.hash'", "tx", tx);
|
|
8770
11174
|
assertArgument(result.hash === tx.hash, "hash mismatch", "tx", tx);
|
|
8771
11175
|
}
|
|
8772
|
-
if (tx.from != null) {
|
|
8773
|
-
assertArgument(result.isSigned(), "unsigned transaction cannot define '.from'", "tx", tx);
|
|
8774
|
-
assertArgument(result.from.toLowerCase() === (tx.from || "").toLowerCase(), "from mismatch", "tx", tx);
|
|
11176
|
+
if (tx.from != null) {
|
|
11177
|
+
assertArgument(result.isSigned(), "unsigned transaction cannot define '.from'", "tx", tx);
|
|
11178
|
+
assertArgument(result.from.toLowerCase() === (tx.from || "").toLowerCase(), "from mismatch", "tx", tx);
|
|
11179
|
+
}
|
|
11180
|
+
return result;
|
|
11181
|
+
}
|
|
11182
|
+
}
|
|
11183
|
+
|
|
11184
|
+
// src/index.ts
|
|
11185
|
+
function parseSignMessageResponse(base64Response, networkId) {
|
|
11186
|
+
const networkPrefix = networkId.split(":")[0].toLowerCase();
|
|
11187
|
+
switch (networkPrefix) {
|
|
11188
|
+
case "solana":
|
|
11189
|
+
return parseSolanaSignatureResponse(base64Response);
|
|
11190
|
+
case "eip155":
|
|
11191
|
+
case "ethereum":
|
|
11192
|
+
return parseEVMSignatureResponse(base64Response);
|
|
11193
|
+
case "sui":
|
|
11194
|
+
return parseSuiSignatureResponse(base64Response);
|
|
11195
|
+
case "bip122":
|
|
11196
|
+
case "bitcoin":
|
|
11197
|
+
return parseBitcoinSignatureResponse(base64Response);
|
|
11198
|
+
default:
|
|
11199
|
+
return {
|
|
11200
|
+
signature: base64Response,
|
|
11201
|
+
rawSignature: base64Response
|
|
11202
|
+
};
|
|
11203
|
+
}
|
|
11204
|
+
}
|
|
11205
|
+
function parseTransactionResponse(base64RawTransaction, networkId, hash) {
|
|
11206
|
+
let rawTransaction = base64RawTransaction;
|
|
11207
|
+
if (isEthereumChain(networkId)) {
|
|
11208
|
+
try {
|
|
11209
|
+
const txBytes = base64urlDecode(base64RawTransaction);
|
|
11210
|
+
rawTransaction = "0x" + bufferExports.Buffer.from(txBytes).toString("hex");
|
|
11211
|
+
} catch (error) {
|
|
11212
|
+
rawTransaction = base64RawTransaction.startsWith("0x") ? base64RawTransaction : "0x" + base64RawTransaction;
|
|
11213
|
+
}
|
|
11214
|
+
}
|
|
11215
|
+
if (hash) {
|
|
11216
|
+
return {
|
|
11217
|
+
hash,
|
|
11218
|
+
rawTransaction,
|
|
11219
|
+
blockExplorer: getExplorerUrl(networkId, "transaction", hash)
|
|
11220
|
+
};
|
|
11221
|
+
} else {
|
|
11222
|
+
return {
|
|
11223
|
+
rawTransaction
|
|
11224
|
+
};
|
|
11225
|
+
}
|
|
11226
|
+
}
|
|
11227
|
+
function parseSolanaSignatureResponse(base64Response) {
|
|
11228
|
+
try {
|
|
11229
|
+
const signatureBytes = base64urlDecode(base64Response);
|
|
11230
|
+
const signature = base58.encode(signatureBytes);
|
|
11231
|
+
return {
|
|
11232
|
+
signature,
|
|
11233
|
+
rawSignature: base64Response
|
|
11234
|
+
};
|
|
11235
|
+
} catch (error) {
|
|
11236
|
+
return {
|
|
11237
|
+
signature: base64Response,
|
|
11238
|
+
rawSignature: base64Response
|
|
11239
|
+
};
|
|
11240
|
+
}
|
|
11241
|
+
}
|
|
11242
|
+
function parseEVMSignatureResponse(base64Response) {
|
|
11243
|
+
const signatureBytes = base64urlDecode(base64Response);
|
|
11244
|
+
const signature = "0x" + bufferExports.Buffer.from(signatureBytes).toString("hex");
|
|
11245
|
+
return {
|
|
11246
|
+
signature,
|
|
11247
|
+
rawSignature: base64Response
|
|
11248
|
+
};
|
|
11249
|
+
}
|
|
11250
|
+
function parseSuiSignatureResponse(base64Response) {
|
|
11251
|
+
try {
|
|
11252
|
+
const signatureBytes = base64urlDecode(base64Response);
|
|
11253
|
+
const signature = bufferExports.Buffer.from(signatureBytes).toString("base64");
|
|
11254
|
+
return {
|
|
11255
|
+
signature,
|
|
11256
|
+
rawSignature: base64Response
|
|
11257
|
+
};
|
|
11258
|
+
} catch (error) {
|
|
11259
|
+
return {
|
|
11260
|
+
signature: base64Response,
|
|
11261
|
+
rawSignature: base64Response
|
|
11262
|
+
};
|
|
11263
|
+
}
|
|
11264
|
+
}
|
|
11265
|
+
function parseBitcoinSignatureResponse(base64Response) {
|
|
11266
|
+
try {
|
|
11267
|
+
const signatureBytes = base64urlDecode(base64Response);
|
|
11268
|
+
const signature = bufferExports.Buffer.from(signatureBytes).toString("hex");
|
|
11269
|
+
return {
|
|
11270
|
+
signature,
|
|
11271
|
+
rawSignature: base64Response
|
|
11272
|
+
};
|
|
11273
|
+
} catch (error) {
|
|
11274
|
+
return {
|
|
11275
|
+
signature: base64Response,
|
|
11276
|
+
rawSignature: base64Response
|
|
11277
|
+
};
|
|
11278
|
+
}
|
|
11279
|
+
}
|
|
11280
|
+
function parseSolanaSignedTransaction(base64RawTransaction) {
|
|
11281
|
+
try {
|
|
11282
|
+
const transactionBytes = base64urlDecode(base64RawTransaction);
|
|
11283
|
+
return deserializeSolanaTransaction(transactionBytes);
|
|
11284
|
+
} catch (error) {
|
|
11285
|
+
return null;
|
|
11286
|
+
}
|
|
11287
|
+
}
|
|
11288
|
+
function deserializeSolanaTransaction(transactionBytes) {
|
|
11289
|
+
try {
|
|
11290
|
+
const transaction = Transaction$1.from(transactionBytes);
|
|
11291
|
+
return transaction;
|
|
11292
|
+
} catch (legacyError) {
|
|
11293
|
+
if (legacyError instanceof Error && legacyError.message.includes("Versioned messages")) {
|
|
11294
|
+
const versionedTransaction = VersionedTransaction.deserialize(transactionBytes);
|
|
11295
|
+
return versionedTransaction;
|
|
11296
|
+
}
|
|
11297
|
+
throw legacyError;
|
|
11298
|
+
}
|
|
11299
|
+
}
|
|
11300
|
+
|
|
11301
|
+
// src/index.ts
|
|
11302
|
+
async function parseToKmsTransaction(transaction, networkId) {
|
|
11303
|
+
const networkPrefix = networkId.split(":")[0].toLowerCase();
|
|
11304
|
+
switch (networkPrefix) {
|
|
11305
|
+
case "solana":
|
|
11306
|
+
return parseSolanaTransactionToBase64Url(transaction);
|
|
11307
|
+
case "ethereum":
|
|
11308
|
+
case "eip155":
|
|
11309
|
+
case "polygon":
|
|
11310
|
+
case "optimism":
|
|
11311
|
+
case "arbitrum":
|
|
11312
|
+
case "base":
|
|
11313
|
+
return parseEVMTransactionToHex(transaction);
|
|
11314
|
+
case "sui":
|
|
11315
|
+
return await parseSuiTransactionToBase64Url(transaction);
|
|
11316
|
+
case "bitcoin":
|
|
11317
|
+
return parseBitcoinTransactionToBase64Url(transaction);
|
|
11318
|
+
default:
|
|
11319
|
+
throw new Error(`Unsupported network: ${networkPrefix}`);
|
|
11320
|
+
}
|
|
11321
|
+
}
|
|
11322
|
+
function parseSolanaTransactionToBase64Url(transaction) {
|
|
11323
|
+
if (transaction?.messageBytes != null) {
|
|
11324
|
+
return {
|
|
11325
|
+
parsed: base64urlEncode(transaction.messageBytes),
|
|
11326
|
+
originalFormat: "@solana/kit"
|
|
11327
|
+
};
|
|
11328
|
+
}
|
|
11329
|
+
if (typeof transaction?.serialize === "function") {
|
|
11330
|
+
const serialized = transaction.serialize({
|
|
11331
|
+
requireAllSignatures: false,
|
|
11332
|
+
verifySignatures: false
|
|
11333
|
+
});
|
|
11334
|
+
return {
|
|
11335
|
+
parsed: base64urlEncode(serialized),
|
|
11336
|
+
originalFormat: "@solana/web3.js"
|
|
11337
|
+
};
|
|
11338
|
+
}
|
|
11339
|
+
if (transaction instanceof Uint8Array) {
|
|
11340
|
+
return {
|
|
11341
|
+
parsed: base64urlEncode(transaction),
|
|
11342
|
+
originalFormat: "bytes"
|
|
11343
|
+
};
|
|
11344
|
+
}
|
|
11345
|
+
if (typeof transaction === "string") {
|
|
11346
|
+
try {
|
|
11347
|
+
const bytes = bufferExports.Buffer.from(transaction, "base64");
|
|
11348
|
+
return {
|
|
11349
|
+
parsed: base64urlEncode(new Uint8Array(bytes)),
|
|
11350
|
+
originalFormat: "base64"
|
|
11351
|
+
};
|
|
11352
|
+
} catch {
|
|
11353
|
+
throw new Error("Unsupported Solana transaction format");
|
|
11354
|
+
}
|
|
11355
|
+
}
|
|
11356
|
+
throw new Error("Unsupported Solana transaction format");
|
|
11357
|
+
}
|
|
11358
|
+
function parseEVMTransactionToHex(transaction) {
|
|
11359
|
+
if (typeof transaction === "string" && transaction.startsWith("0x")) {
|
|
11360
|
+
return {
|
|
11361
|
+
parsed: transaction,
|
|
11362
|
+
originalFormat: "hex"
|
|
11363
|
+
};
|
|
11364
|
+
}
|
|
11365
|
+
if (transaction?.serialize && typeof transaction.serialize === "function") {
|
|
11366
|
+
const serialized = transaction.serialize();
|
|
11367
|
+
const hex = serialized.startsWith("0x") ? serialized : "0x" + serialized;
|
|
11368
|
+
return {
|
|
11369
|
+
parsed: hex,
|
|
11370
|
+
originalFormat: "ethers"
|
|
11371
|
+
};
|
|
11372
|
+
}
|
|
11373
|
+
if (transaction instanceof Uint8Array) {
|
|
11374
|
+
const hex = "0x" + bufferExports.Buffer.from(transaction).toString("hex");
|
|
11375
|
+
return {
|
|
11376
|
+
parsed: hex,
|
|
11377
|
+
originalFormat: "bytes"
|
|
11378
|
+
};
|
|
11379
|
+
}
|
|
11380
|
+
if (transaction && typeof transaction === "object" && (transaction.to || transaction.data || transaction.from)) {
|
|
11381
|
+
try {
|
|
11382
|
+
const { from, gas, ...txForSerialization } = transaction;
|
|
11383
|
+
if (gas) {
|
|
11384
|
+
txForSerialization.gasLimit = gas;
|
|
11385
|
+
}
|
|
11386
|
+
if (!txForSerialization.gasLimit) {
|
|
11387
|
+
if (txForSerialization.to && txForSerialization.value && !txForSerialization.data) {
|
|
11388
|
+
txForSerialization.gasLimit = "0x5208";
|
|
11389
|
+
}
|
|
11390
|
+
}
|
|
11391
|
+
if (txForSerialization.to && typeof txForSerialization.to === "string") {
|
|
11392
|
+
try {
|
|
11393
|
+
txForSerialization.to = getAddress(txForSerialization.to);
|
|
11394
|
+
} catch {
|
|
11395
|
+
txForSerialization.to = txForSerialization.to.toLowerCase();
|
|
8775
11396
|
}
|
|
8776
|
-
|
|
11397
|
+
}
|
|
11398
|
+
const serialized = Transaction.from(txForSerialization).unsignedSerialized;
|
|
11399
|
+
const hex = serialized.startsWith("0x") ? serialized : "0x" + serialized;
|
|
11400
|
+
return {
|
|
11401
|
+
parsed: hex,
|
|
11402
|
+
originalFormat: "json"
|
|
11403
|
+
};
|
|
11404
|
+
} catch (error) {
|
|
11405
|
+
const errorMessage = error instanceof Error ? error.message : "Unknown error";
|
|
11406
|
+
const txKeys = transaction ? Object.keys(transaction).join(", ") : "N/A";
|
|
11407
|
+
const txValues = transaction ? JSON.stringify(transaction, null, 2) : "N/A";
|
|
11408
|
+
throw new Error(
|
|
11409
|
+
`Failed to RLP encode EVM transaction: ${errorMessage}.
|
|
11410
|
+
Transaction keys: [${txKeys}].
|
|
11411
|
+
Transaction: ${txValues}
|
|
11412
|
+
Please ensure the transaction object includes required fields (to, value, chainId, gasLimit or gasPrice, etc.)`
|
|
11413
|
+
);
|
|
11414
|
+
}
|
|
11415
|
+
}
|
|
11416
|
+
throw new Error(
|
|
11417
|
+
"Unsupported EVM transaction format. Expected hex string, bytes, or transaction object with 'to', 'data', or 'from' fields."
|
|
11418
|
+
);
|
|
11419
|
+
}
|
|
11420
|
+
async function parseSuiTransactionToBase64Url(transaction) {
|
|
11421
|
+
if (transaction?.serialize && typeof transaction.serialize === "function") {
|
|
11422
|
+
const serialized = transaction.serialize();
|
|
11423
|
+
return {
|
|
11424
|
+
parsed: base64urlEncode(serialized),
|
|
11425
|
+
originalFormat: "sui-sdk"
|
|
11426
|
+
};
|
|
11427
|
+
}
|
|
11428
|
+
if (transaction instanceof Uint8Array) {
|
|
11429
|
+
return {
|
|
11430
|
+
parsed: base64urlEncode(transaction),
|
|
11431
|
+
originalFormat: "bytes"
|
|
11432
|
+
};
|
|
11433
|
+
}
|
|
11434
|
+
if (transaction?.build && typeof transaction.build === "function") {
|
|
11435
|
+
const built = await transaction.build();
|
|
11436
|
+
if (built?.serialize && typeof built.serialize === "function") {
|
|
11437
|
+
const serialized = built.serialize();
|
|
11438
|
+
return {
|
|
11439
|
+
parsed: base64urlEncode(serialized),
|
|
11440
|
+
originalFormat: "transaction-block"
|
|
11441
|
+
};
|
|
11442
|
+
}
|
|
11443
|
+
}
|
|
11444
|
+
throw new Error("Unsupported Sui transaction format");
|
|
11445
|
+
}
|
|
11446
|
+
function parseBitcoinTransactionToBase64Url(transaction) {
|
|
11447
|
+
if (transaction?.toBuffer && typeof transaction.toBuffer === "function") {
|
|
11448
|
+
const buffer = transaction.toBuffer();
|
|
11449
|
+
return {
|
|
11450
|
+
parsed: base64urlEncode(new Uint8Array(buffer)),
|
|
11451
|
+
originalFormat: "bitcoinjs-lib"
|
|
11452
|
+
};
|
|
11453
|
+
}
|
|
11454
|
+
if (transaction instanceof Uint8Array) {
|
|
11455
|
+
return {
|
|
11456
|
+
parsed: base64urlEncode(transaction),
|
|
11457
|
+
originalFormat: "bytes"
|
|
11458
|
+
};
|
|
11459
|
+
}
|
|
11460
|
+
if (typeof transaction === "string") {
|
|
11461
|
+
const bytes = new Uint8Array(bufferExports.Buffer.from(transaction, "hex"));
|
|
11462
|
+
return {
|
|
11463
|
+
parsed: base64urlEncode(bytes),
|
|
11464
|
+
originalFormat: "hex"
|
|
11465
|
+
};
|
|
11466
|
+
}
|
|
11467
|
+
throw new Error("Unsupported Bitcoin transaction format");
|
|
11468
|
+
}
|
|
11469
|
+
|
|
11470
|
+
// base-x encoding / decoding
|
|
11471
|
+
// Copyright (c) 2018 base-x contributors
|
|
11472
|
+
// Copyright (c) 2014-2018 The Bitcoin Core developers (base58.cpp)
|
|
11473
|
+
// Distributed under the MIT software license, see the accompanying
|
|
11474
|
+
// file LICENSE or http://www.opensource.org/licenses/mit-license.php.
|
|
11475
|
+
function base$2 (ALPHABET) {
|
|
11476
|
+
if (ALPHABET.length >= 255) { throw new TypeError('Alphabet too long') }
|
|
11477
|
+
const BASE_MAP = new Uint8Array(256);
|
|
11478
|
+
for (let j = 0; j < BASE_MAP.length; j++) {
|
|
11479
|
+
BASE_MAP[j] = 255;
|
|
11480
|
+
}
|
|
11481
|
+
for (let i = 0; i < ALPHABET.length; i++) {
|
|
11482
|
+
const x = ALPHABET.charAt(i);
|
|
11483
|
+
const xc = x.charCodeAt(0);
|
|
11484
|
+
if (BASE_MAP[xc] !== 255) { throw new TypeError(x + ' is ambiguous') }
|
|
11485
|
+
BASE_MAP[xc] = i;
|
|
11486
|
+
}
|
|
11487
|
+
const BASE = ALPHABET.length;
|
|
11488
|
+
const LEADER = ALPHABET.charAt(0);
|
|
11489
|
+
const FACTOR = Math.log(BASE) / Math.log(256); // log(BASE) / log(256), rounded up
|
|
11490
|
+
const iFACTOR = Math.log(256) / Math.log(BASE); // log(256) / log(BASE), rounded up
|
|
11491
|
+
function encode (source) {
|
|
11492
|
+
// eslint-disable-next-line no-empty
|
|
11493
|
+
if (source instanceof Uint8Array) ; else if (ArrayBuffer.isView(source)) {
|
|
11494
|
+
source = new Uint8Array(source.buffer, source.byteOffset, source.byteLength);
|
|
11495
|
+
} else if (Array.isArray(source)) {
|
|
11496
|
+
source = Uint8Array.from(source);
|
|
11497
|
+
}
|
|
11498
|
+
if (!(source instanceof Uint8Array)) { throw new TypeError('Expected Uint8Array') }
|
|
11499
|
+
if (source.length === 0) { return '' }
|
|
11500
|
+
// Skip & count leading zeroes.
|
|
11501
|
+
let zeroes = 0;
|
|
11502
|
+
let length = 0;
|
|
11503
|
+
let pbegin = 0;
|
|
11504
|
+
const pend = source.length;
|
|
11505
|
+
while (pbegin !== pend && source[pbegin] === 0) {
|
|
11506
|
+
pbegin++;
|
|
11507
|
+
zeroes++;
|
|
11508
|
+
}
|
|
11509
|
+
// Allocate enough space in big-endian base58 representation.
|
|
11510
|
+
const size = ((pend - pbegin) * iFACTOR + 1) >>> 0;
|
|
11511
|
+
const b58 = new Uint8Array(size);
|
|
11512
|
+
// Process the bytes.
|
|
11513
|
+
while (pbegin !== pend) {
|
|
11514
|
+
let carry = source[pbegin];
|
|
11515
|
+
// Apply "b58 = b58 * 256 + ch".
|
|
11516
|
+
let i = 0;
|
|
11517
|
+
for (let it1 = size - 1; (carry !== 0 || i < length) && (it1 !== -1); it1--, i++) {
|
|
11518
|
+
carry += (256 * b58[it1]) >>> 0;
|
|
11519
|
+
b58[it1] = (carry % BASE) >>> 0;
|
|
11520
|
+
carry = (carry / BASE) >>> 0;
|
|
11521
|
+
}
|
|
11522
|
+
if (carry !== 0) { throw new Error('Non-zero carry') }
|
|
11523
|
+
length = i;
|
|
11524
|
+
pbegin++;
|
|
11525
|
+
}
|
|
11526
|
+
// Skip leading zeroes in base58 result.
|
|
11527
|
+
let it2 = size - length;
|
|
11528
|
+
while (it2 !== size && b58[it2] === 0) {
|
|
11529
|
+
it2++;
|
|
11530
|
+
}
|
|
11531
|
+
// Translate the result into a string.
|
|
11532
|
+
let str = LEADER.repeat(zeroes);
|
|
11533
|
+
for (; it2 < size; ++it2) { str += ALPHABET.charAt(b58[it2]); }
|
|
11534
|
+
return str
|
|
11535
|
+
}
|
|
11536
|
+
function decodeUnsafe (source) {
|
|
11537
|
+
if (typeof source !== 'string') { throw new TypeError('Expected String') }
|
|
11538
|
+
if (source.length === 0) { return new Uint8Array() }
|
|
11539
|
+
let psz = 0;
|
|
11540
|
+
// Skip and count leading '1's.
|
|
11541
|
+
let zeroes = 0;
|
|
11542
|
+
let length = 0;
|
|
11543
|
+
while (source[psz] === LEADER) {
|
|
11544
|
+
zeroes++;
|
|
11545
|
+
psz++;
|
|
11546
|
+
}
|
|
11547
|
+
// Allocate enough space in big-endian base256 representation.
|
|
11548
|
+
const size = (((source.length - psz) * FACTOR) + 1) >>> 0; // log(58) / log(256), rounded up.
|
|
11549
|
+
const b256 = new Uint8Array(size);
|
|
11550
|
+
// Process the characters.
|
|
11551
|
+
while (psz < source.length) {
|
|
11552
|
+
// Find code of next character
|
|
11553
|
+
const charCode = source.charCodeAt(psz);
|
|
11554
|
+
// Base map can not be indexed using char code
|
|
11555
|
+
if (charCode > 255) { return }
|
|
11556
|
+
// Decode character
|
|
11557
|
+
let carry = BASE_MAP[charCode];
|
|
11558
|
+
// Invalid character
|
|
11559
|
+
if (carry === 255) { return }
|
|
11560
|
+
let i = 0;
|
|
11561
|
+
for (let it3 = size - 1; (carry !== 0 || i < length) && (it3 !== -1); it3--, i++) {
|
|
11562
|
+
carry += (BASE * b256[it3]) >>> 0;
|
|
11563
|
+
b256[it3] = (carry % 256) >>> 0;
|
|
11564
|
+
carry = (carry / 256) >>> 0;
|
|
11565
|
+
}
|
|
11566
|
+
if (carry !== 0) { throw new Error('Non-zero carry') }
|
|
11567
|
+
length = i;
|
|
11568
|
+
psz++;
|
|
11569
|
+
}
|
|
11570
|
+
// Skip leading zeroes in b256.
|
|
11571
|
+
let it4 = size - length;
|
|
11572
|
+
while (it4 !== size && b256[it4] === 0) {
|
|
11573
|
+
it4++;
|
|
11574
|
+
}
|
|
11575
|
+
const vch = new Uint8Array(zeroes + (size - it4));
|
|
11576
|
+
let j = zeroes;
|
|
11577
|
+
while (it4 !== size) {
|
|
11578
|
+
vch[j++] = b256[it4++];
|
|
11579
|
+
}
|
|
11580
|
+
return vch
|
|
11581
|
+
}
|
|
11582
|
+
function decode (string) {
|
|
11583
|
+
const buffer = decodeUnsafe(string);
|
|
11584
|
+
if (buffer) { return buffer }
|
|
11585
|
+
throw new Error('Non-base' + BASE + ' character')
|
|
11586
|
+
}
|
|
11587
|
+
return {
|
|
11588
|
+
encode,
|
|
11589
|
+
decodeUnsafe,
|
|
11590
|
+
decode
|
|
11591
|
+
}
|
|
11592
|
+
}
|
|
11593
|
+
|
|
11594
|
+
var ALPHABET$2 = '123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz';
|
|
11595
|
+
var bs58$1 = base$2(ALPHABET$2);
|
|
11596
|
+
|
|
11597
|
+
// base-x encoding / decoding
|
|
11598
|
+
// Copyright (c) 2018 base-x contributors
|
|
11599
|
+
// Copyright (c) 2014-2018 The Bitcoin Core developers (base58.cpp)
|
|
11600
|
+
// Distributed under the MIT software license, see the accompanying
|
|
11601
|
+
// file LICENSE or http://www.opensource.org/licenses/mit-license.php.
|
|
11602
|
+
function base$1 (ALPHABET) {
|
|
11603
|
+
if (ALPHABET.length >= 255) { throw new TypeError('Alphabet too long') }
|
|
11604
|
+
const BASE_MAP = new Uint8Array(256);
|
|
11605
|
+
for (let j = 0; j < BASE_MAP.length; j++) {
|
|
11606
|
+
BASE_MAP[j] = 255;
|
|
11607
|
+
}
|
|
11608
|
+
for (let i = 0; i < ALPHABET.length; i++) {
|
|
11609
|
+
const x = ALPHABET.charAt(i);
|
|
11610
|
+
const xc = x.charCodeAt(0);
|
|
11611
|
+
if (BASE_MAP[xc] !== 255) { throw new TypeError(x + ' is ambiguous') }
|
|
11612
|
+
BASE_MAP[xc] = i;
|
|
11613
|
+
}
|
|
11614
|
+
const BASE = ALPHABET.length;
|
|
11615
|
+
const LEADER = ALPHABET.charAt(0);
|
|
11616
|
+
const FACTOR = Math.log(BASE) / Math.log(256); // log(BASE) / log(256), rounded up
|
|
11617
|
+
const iFACTOR = Math.log(256) / Math.log(BASE); // log(256) / log(BASE), rounded up
|
|
11618
|
+
function encode (source) {
|
|
11619
|
+
// eslint-disable-next-line no-empty
|
|
11620
|
+
if (source instanceof Uint8Array) ; else if (ArrayBuffer.isView(source)) {
|
|
11621
|
+
source = new Uint8Array(source.buffer, source.byteOffset, source.byteLength);
|
|
11622
|
+
} else if (Array.isArray(source)) {
|
|
11623
|
+
source = Uint8Array.from(source);
|
|
11624
|
+
}
|
|
11625
|
+
if (!(source instanceof Uint8Array)) { throw new TypeError('Expected Uint8Array') }
|
|
11626
|
+
if (source.length === 0) { return '' }
|
|
11627
|
+
// Skip & count leading zeroes.
|
|
11628
|
+
let zeroes = 0;
|
|
11629
|
+
let length = 0;
|
|
11630
|
+
let pbegin = 0;
|
|
11631
|
+
const pend = source.length;
|
|
11632
|
+
while (pbegin !== pend && source[pbegin] === 0) {
|
|
11633
|
+
pbegin++;
|
|
11634
|
+
zeroes++;
|
|
11635
|
+
}
|
|
11636
|
+
// Allocate enough space in big-endian base58 representation.
|
|
11637
|
+
const size = ((pend - pbegin) * iFACTOR + 1) >>> 0;
|
|
11638
|
+
const b58 = new Uint8Array(size);
|
|
11639
|
+
// Process the bytes.
|
|
11640
|
+
while (pbegin !== pend) {
|
|
11641
|
+
let carry = source[pbegin];
|
|
11642
|
+
// Apply "b58 = b58 * 256 + ch".
|
|
11643
|
+
let i = 0;
|
|
11644
|
+
for (let it1 = size - 1; (carry !== 0 || i < length) && (it1 !== -1); it1--, i++) {
|
|
11645
|
+
carry += (256 * b58[it1]) >>> 0;
|
|
11646
|
+
b58[it1] = (carry % BASE) >>> 0;
|
|
11647
|
+
carry = (carry / BASE) >>> 0;
|
|
11648
|
+
}
|
|
11649
|
+
if (carry !== 0) { throw new Error('Non-zero carry') }
|
|
11650
|
+
length = i;
|
|
11651
|
+
pbegin++;
|
|
11652
|
+
}
|
|
11653
|
+
// Skip leading zeroes in base58 result.
|
|
11654
|
+
let it2 = size - length;
|
|
11655
|
+
while (it2 !== size && b58[it2] === 0) {
|
|
11656
|
+
it2++;
|
|
11657
|
+
}
|
|
11658
|
+
// Translate the result into a string.
|
|
11659
|
+
let str = LEADER.repeat(zeroes);
|
|
11660
|
+
for (; it2 < size; ++it2) { str += ALPHABET.charAt(b58[it2]); }
|
|
11661
|
+
return str
|
|
11662
|
+
}
|
|
11663
|
+
function decodeUnsafe (source) {
|
|
11664
|
+
if (typeof source !== 'string') { throw new TypeError('Expected String') }
|
|
11665
|
+
if (source.length === 0) { return new Uint8Array() }
|
|
11666
|
+
let psz = 0;
|
|
11667
|
+
// Skip and count leading '1's.
|
|
11668
|
+
let zeroes = 0;
|
|
11669
|
+
let length = 0;
|
|
11670
|
+
while (source[psz] === LEADER) {
|
|
11671
|
+
zeroes++;
|
|
11672
|
+
psz++;
|
|
11673
|
+
}
|
|
11674
|
+
// Allocate enough space in big-endian base256 representation.
|
|
11675
|
+
const size = (((source.length - psz) * FACTOR) + 1) >>> 0; // log(58) / log(256), rounded up.
|
|
11676
|
+
const b256 = new Uint8Array(size);
|
|
11677
|
+
// Process the characters.
|
|
11678
|
+
while (psz < source.length) {
|
|
11679
|
+
// Find code of next character
|
|
11680
|
+
const charCode = source.charCodeAt(psz);
|
|
11681
|
+
// Base map can not be indexed using char code
|
|
11682
|
+
if (charCode > 255) { return }
|
|
11683
|
+
// Decode character
|
|
11684
|
+
let carry = BASE_MAP[charCode];
|
|
11685
|
+
// Invalid character
|
|
11686
|
+
if (carry === 255) { return }
|
|
11687
|
+
let i = 0;
|
|
11688
|
+
for (let it3 = size - 1; (carry !== 0 || i < length) && (it3 !== -1); it3--, i++) {
|
|
11689
|
+
carry += (BASE * b256[it3]) >>> 0;
|
|
11690
|
+
b256[it3] = (carry % 256) >>> 0;
|
|
11691
|
+
carry = (carry / 256) >>> 0;
|
|
11692
|
+
}
|
|
11693
|
+
if (carry !== 0) { throw new Error('Non-zero carry') }
|
|
11694
|
+
length = i;
|
|
11695
|
+
psz++;
|
|
11696
|
+
}
|
|
11697
|
+
// Skip leading zeroes in b256.
|
|
11698
|
+
let it4 = size - length;
|
|
11699
|
+
while (it4 !== size && b256[it4] === 0) {
|
|
11700
|
+
it4++;
|
|
8777
11701
|
}
|
|
11702
|
+
const vch = new Uint8Array(zeroes + (size - it4));
|
|
11703
|
+
let j = zeroes;
|
|
11704
|
+
while (it4 !== size) {
|
|
11705
|
+
vch[j++] = b256[it4++];
|
|
11706
|
+
}
|
|
11707
|
+
return vch
|
|
11708
|
+
}
|
|
11709
|
+
function decode (string) {
|
|
11710
|
+
const buffer = decodeUnsafe(string);
|
|
11711
|
+
if (buffer) { return buffer }
|
|
11712
|
+
throw new Error('Non-base' + BASE + ' character')
|
|
11713
|
+
}
|
|
11714
|
+
return {
|
|
11715
|
+
encode,
|
|
11716
|
+
decodeUnsafe,
|
|
11717
|
+
decode
|
|
11718
|
+
}
|
|
8778
11719
|
}
|
|
8779
11720
|
|
|
8780
|
-
|
|
8781
|
-
|
|
8782
|
-
|
|
8783
|
-
|
|
8784
|
-
|
|
8785
|
-
|
|
8786
|
-
|
|
8787
|
-
|
|
8788
|
-
|
|
8789
|
-
|
|
8790
|
-
|
|
8791
|
-
|
|
8792
|
-
|
|
8793
|
-
|
|
8794
|
-
|
|
8795
|
-
|
|
8796
|
-
|
|
8797
|
-
|
|
8798
|
-
|
|
8799
|
-
|
|
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
|
-
|
|
11721
|
+
var ALPHABET$1 = '123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz';
|
|
11722
|
+
var bs582 = base$1(ALPHABET$1);
|
|
11723
|
+
|
|
11724
|
+
var eventemitter3 = {exports: {}};
|
|
11725
|
+
|
|
11726
|
+
var hasRequiredEventemitter3;
|
|
11727
|
+
|
|
11728
|
+
function requireEventemitter3 () {
|
|
11729
|
+
if (hasRequiredEventemitter3) return eventemitter3.exports;
|
|
11730
|
+
hasRequiredEventemitter3 = 1;
|
|
11731
|
+
(function (module) {
|
|
11732
|
+
|
|
11733
|
+
var has = Object.prototype.hasOwnProperty
|
|
11734
|
+
, prefix = '~';
|
|
11735
|
+
|
|
11736
|
+
/**
|
|
11737
|
+
* Constructor to create a storage for our `EE` objects.
|
|
11738
|
+
* An `Events` instance is a plain object whose properties are event names.
|
|
11739
|
+
*
|
|
11740
|
+
* @constructor
|
|
11741
|
+
* @private
|
|
11742
|
+
*/
|
|
11743
|
+
function Events() {}
|
|
11744
|
+
|
|
11745
|
+
//
|
|
11746
|
+
// We try to not inherit from `Object.prototype`. In some engines creating an
|
|
11747
|
+
// instance in this way is faster than calling `Object.create(null)` directly.
|
|
11748
|
+
// If `Object.create(null)` is not supported we prefix the event names with a
|
|
11749
|
+
// character to make sure that the built-in object properties are not
|
|
11750
|
+
// overridden or used as an attack vector.
|
|
11751
|
+
//
|
|
11752
|
+
if (Object.create) {
|
|
11753
|
+
Events.prototype = Object.create(null);
|
|
11754
|
+
|
|
11755
|
+
//
|
|
11756
|
+
// This hack is needed because the `__proto__` property is still inherited in
|
|
11757
|
+
// some old browsers like Android 4, iPhone 5.1, Opera 11 and Safari 5.
|
|
11758
|
+
//
|
|
11759
|
+
if (!new Events().__proto__) prefix = false;
|
|
11760
|
+
}
|
|
11761
|
+
|
|
11762
|
+
/**
|
|
11763
|
+
* Representation of a single event listener.
|
|
11764
|
+
*
|
|
11765
|
+
* @param {Function} fn The listener function.
|
|
11766
|
+
* @param {*} context The context to invoke the listener with.
|
|
11767
|
+
* @param {Boolean} [once=false] Specify if the listener is a one-time listener.
|
|
11768
|
+
* @constructor
|
|
11769
|
+
* @private
|
|
11770
|
+
*/
|
|
11771
|
+
function EE(fn, context, once) {
|
|
11772
|
+
this.fn = fn;
|
|
11773
|
+
this.context = context;
|
|
11774
|
+
this.once = once || false;
|
|
11775
|
+
}
|
|
11776
|
+
|
|
11777
|
+
/**
|
|
11778
|
+
* Add a listener for a given event.
|
|
11779
|
+
*
|
|
11780
|
+
* @param {EventEmitter} emitter Reference to the `EventEmitter` instance.
|
|
11781
|
+
* @param {(String|Symbol)} event The event name.
|
|
11782
|
+
* @param {Function} fn The listener function.
|
|
11783
|
+
* @param {*} context The context to invoke the listener with.
|
|
11784
|
+
* @param {Boolean} once Specify if the listener is a one-time listener.
|
|
11785
|
+
* @returns {EventEmitter}
|
|
11786
|
+
* @private
|
|
11787
|
+
*/
|
|
11788
|
+
function addListener(emitter, event, fn, context, once) {
|
|
11789
|
+
if (typeof fn !== 'function') {
|
|
11790
|
+
throw new TypeError('The listener must be a function');
|
|
11791
|
+
}
|
|
11792
|
+
|
|
11793
|
+
var listener = new EE(fn, context || emitter, once)
|
|
11794
|
+
, evt = prefix ? prefix + event : event;
|
|
11795
|
+
|
|
11796
|
+
if (!emitter._events[evt]) emitter._events[evt] = listener, emitter._eventsCount++;
|
|
11797
|
+
else if (!emitter._events[evt].fn) emitter._events[evt].push(listener);
|
|
11798
|
+
else emitter._events[evt] = [emitter._events[evt], listener];
|
|
11799
|
+
|
|
11800
|
+
return emitter;
|
|
11801
|
+
}
|
|
11802
|
+
|
|
11803
|
+
/**
|
|
11804
|
+
* Clear event by name.
|
|
11805
|
+
*
|
|
11806
|
+
* @param {EventEmitter} emitter Reference to the `EventEmitter` instance.
|
|
11807
|
+
* @param {(String|Symbol)} evt The Event name.
|
|
11808
|
+
* @private
|
|
11809
|
+
*/
|
|
11810
|
+
function clearEvent(emitter, evt) {
|
|
11811
|
+
if (--emitter._eventsCount === 0) emitter._events = new Events();
|
|
11812
|
+
else delete emitter._events[evt];
|
|
11813
|
+
}
|
|
11814
|
+
|
|
11815
|
+
/**
|
|
11816
|
+
* Minimal `EventEmitter` interface that is molded against the Node.js
|
|
11817
|
+
* `EventEmitter` interface.
|
|
11818
|
+
*
|
|
11819
|
+
* @constructor
|
|
11820
|
+
* @public
|
|
11821
|
+
*/
|
|
11822
|
+
function EventEmitter() {
|
|
11823
|
+
this._events = new Events();
|
|
11824
|
+
this._eventsCount = 0;
|
|
11825
|
+
}
|
|
11826
|
+
|
|
11827
|
+
/**
|
|
11828
|
+
* Return an array listing the events for which the emitter has registered
|
|
11829
|
+
* listeners.
|
|
11830
|
+
*
|
|
11831
|
+
* @returns {Array}
|
|
11832
|
+
* @public
|
|
11833
|
+
*/
|
|
11834
|
+
EventEmitter.prototype.eventNames = function eventNames() {
|
|
11835
|
+
var names = []
|
|
11836
|
+
, events
|
|
11837
|
+
, name;
|
|
11838
|
+
|
|
11839
|
+
if (this._eventsCount === 0) return names;
|
|
11840
|
+
|
|
11841
|
+
for (name in (events = this._events)) {
|
|
11842
|
+
if (has.call(events, name)) names.push(prefix ? name.slice(1) : name);
|
|
11843
|
+
}
|
|
11844
|
+
|
|
11845
|
+
if (Object.getOwnPropertySymbols) {
|
|
11846
|
+
return names.concat(Object.getOwnPropertySymbols(events));
|
|
11847
|
+
}
|
|
11848
|
+
|
|
11849
|
+
return names;
|
|
11850
|
+
};
|
|
11851
|
+
|
|
11852
|
+
/**
|
|
11853
|
+
* Return the listeners registered for a given event.
|
|
11854
|
+
*
|
|
11855
|
+
* @param {(String|Symbol)} event The event name.
|
|
11856
|
+
* @returns {Array} The registered listeners.
|
|
11857
|
+
* @public
|
|
11858
|
+
*/
|
|
11859
|
+
EventEmitter.prototype.listeners = function listeners(event) {
|
|
11860
|
+
var evt = prefix ? prefix + event : event
|
|
11861
|
+
, handlers = this._events[evt];
|
|
11862
|
+
|
|
11863
|
+
if (!handlers) return [];
|
|
11864
|
+
if (handlers.fn) return [handlers.fn];
|
|
11865
|
+
|
|
11866
|
+
for (var i = 0, l = handlers.length, ee = new Array(l); i < l; i++) {
|
|
11867
|
+
ee[i] = handlers[i].fn;
|
|
11868
|
+
}
|
|
11869
|
+
|
|
11870
|
+
return ee;
|
|
11871
|
+
};
|
|
11872
|
+
|
|
11873
|
+
/**
|
|
11874
|
+
* Return the number of listeners listening to a given event.
|
|
11875
|
+
*
|
|
11876
|
+
* @param {(String|Symbol)} event The event name.
|
|
11877
|
+
* @returns {Number} The number of listeners.
|
|
11878
|
+
* @public
|
|
11879
|
+
*/
|
|
11880
|
+
EventEmitter.prototype.listenerCount = function listenerCount(event) {
|
|
11881
|
+
var evt = prefix ? prefix + event : event
|
|
11882
|
+
, listeners = this._events[evt];
|
|
11883
|
+
|
|
11884
|
+
if (!listeners) return 0;
|
|
11885
|
+
if (listeners.fn) return 1;
|
|
11886
|
+
return listeners.length;
|
|
11887
|
+
};
|
|
11888
|
+
|
|
11889
|
+
/**
|
|
11890
|
+
* Calls each of the listeners registered for a given event.
|
|
11891
|
+
*
|
|
11892
|
+
* @param {(String|Symbol)} event The event name.
|
|
11893
|
+
* @returns {Boolean} `true` if the event had listeners, else `false`.
|
|
11894
|
+
* @public
|
|
11895
|
+
*/
|
|
11896
|
+
EventEmitter.prototype.emit = function emit(event, a1, a2, a3, a4, a5) {
|
|
11897
|
+
var evt = prefix ? prefix + event : event;
|
|
11898
|
+
|
|
11899
|
+
if (!this._events[evt]) return false;
|
|
11900
|
+
|
|
11901
|
+
var listeners = this._events[evt]
|
|
11902
|
+
, len = arguments.length
|
|
11903
|
+
, args
|
|
11904
|
+
, i;
|
|
11905
|
+
|
|
11906
|
+
if (listeners.fn) {
|
|
11907
|
+
if (listeners.once) this.removeListener(event, listeners.fn, undefined, true);
|
|
11908
|
+
|
|
11909
|
+
switch (len) {
|
|
11910
|
+
case 1: return listeners.fn.call(listeners.context), true;
|
|
11911
|
+
case 2: return listeners.fn.call(listeners.context, a1), true;
|
|
11912
|
+
case 3: return listeners.fn.call(listeners.context, a1, a2), true;
|
|
11913
|
+
case 4: return listeners.fn.call(listeners.context, a1, a2, a3), true;
|
|
11914
|
+
case 5: return listeners.fn.call(listeners.context, a1, a2, a3, a4), true;
|
|
11915
|
+
case 6: return listeners.fn.call(listeners.context, a1, a2, a3, a4, a5), true;
|
|
11916
|
+
}
|
|
11917
|
+
|
|
11918
|
+
for (i = 1, args = new Array(len -1); i < len; i++) {
|
|
11919
|
+
args[i - 1] = arguments[i];
|
|
11920
|
+
}
|
|
11921
|
+
|
|
11922
|
+
listeners.fn.apply(listeners.context, args);
|
|
11923
|
+
} else {
|
|
11924
|
+
var length = listeners.length
|
|
11925
|
+
, j;
|
|
11926
|
+
|
|
11927
|
+
for (i = 0; i < length; i++) {
|
|
11928
|
+
if (listeners[i].once) this.removeListener(event, listeners[i].fn, undefined, true);
|
|
11929
|
+
|
|
11930
|
+
switch (len) {
|
|
11931
|
+
case 1: listeners[i].fn.call(listeners[i].context); break;
|
|
11932
|
+
case 2: listeners[i].fn.call(listeners[i].context, a1); break;
|
|
11933
|
+
case 3: listeners[i].fn.call(listeners[i].context, a1, a2); break;
|
|
11934
|
+
case 4: listeners[i].fn.call(listeners[i].context, a1, a2, a3); break;
|
|
11935
|
+
default:
|
|
11936
|
+
if (!args) for (j = 1, args = new Array(len -1); j < len; j++) {
|
|
11937
|
+
args[j - 1] = arguments[j];
|
|
11938
|
+
}
|
|
11939
|
+
|
|
11940
|
+
listeners[i].fn.apply(listeners[i].context, args);
|
|
11941
|
+
}
|
|
11942
|
+
}
|
|
11943
|
+
}
|
|
11944
|
+
|
|
11945
|
+
return true;
|
|
11946
|
+
};
|
|
11947
|
+
|
|
11948
|
+
/**
|
|
11949
|
+
* Add a listener for a given event.
|
|
11950
|
+
*
|
|
11951
|
+
* @param {(String|Symbol)} event The event name.
|
|
11952
|
+
* @param {Function} fn The listener function.
|
|
11953
|
+
* @param {*} [context=this] The context to invoke the listener with.
|
|
11954
|
+
* @returns {EventEmitter} `this`.
|
|
11955
|
+
* @public
|
|
11956
|
+
*/
|
|
11957
|
+
EventEmitter.prototype.on = function on(event, fn, context) {
|
|
11958
|
+
return addListener(this, event, fn, context, false);
|
|
11959
|
+
};
|
|
11960
|
+
|
|
11961
|
+
/**
|
|
11962
|
+
* Add a one-time listener for a given event.
|
|
11963
|
+
*
|
|
11964
|
+
* @param {(String|Symbol)} event The event name.
|
|
11965
|
+
* @param {Function} fn The listener function.
|
|
11966
|
+
* @param {*} [context=this] The context to invoke the listener with.
|
|
11967
|
+
* @returns {EventEmitter} `this`.
|
|
11968
|
+
* @public
|
|
11969
|
+
*/
|
|
11970
|
+
EventEmitter.prototype.once = function once(event, fn, context) {
|
|
11971
|
+
return addListener(this, event, fn, context, true);
|
|
11972
|
+
};
|
|
11973
|
+
|
|
11974
|
+
/**
|
|
11975
|
+
* Remove the listeners of a given event.
|
|
11976
|
+
*
|
|
11977
|
+
* @param {(String|Symbol)} event The event name.
|
|
11978
|
+
* @param {Function} fn Only remove the listeners that match this function.
|
|
11979
|
+
* @param {*} context Only remove the listeners that have this context.
|
|
11980
|
+
* @param {Boolean} once Only remove one-time listeners.
|
|
11981
|
+
* @returns {EventEmitter} `this`.
|
|
11982
|
+
* @public
|
|
11983
|
+
*/
|
|
11984
|
+
EventEmitter.prototype.removeListener = function removeListener(event, fn, context, once) {
|
|
11985
|
+
var evt = prefix ? prefix + event : event;
|
|
11986
|
+
|
|
11987
|
+
if (!this._events[evt]) return this;
|
|
11988
|
+
if (!fn) {
|
|
11989
|
+
clearEvent(this, evt);
|
|
11990
|
+
return this;
|
|
11991
|
+
}
|
|
11992
|
+
|
|
11993
|
+
var listeners = this._events[evt];
|
|
11994
|
+
|
|
11995
|
+
if (listeners.fn) {
|
|
11996
|
+
if (
|
|
11997
|
+
listeners.fn === fn &&
|
|
11998
|
+
(!once || listeners.once) &&
|
|
11999
|
+
(!context || listeners.context === context)
|
|
12000
|
+
) {
|
|
12001
|
+
clearEvent(this, evt);
|
|
12002
|
+
}
|
|
12003
|
+
} else {
|
|
12004
|
+
for (var i = 0, events = [], length = listeners.length; i < length; i++) {
|
|
12005
|
+
if (
|
|
12006
|
+
listeners[i].fn !== fn ||
|
|
12007
|
+
(once && !listeners[i].once) ||
|
|
12008
|
+
(context && listeners[i].context !== context)
|
|
12009
|
+
) {
|
|
12010
|
+
events.push(listeners[i]);
|
|
12011
|
+
}
|
|
12012
|
+
}
|
|
8896
12013
|
|
|
8897
|
-
//
|
|
8898
|
-
|
|
8899
|
-
|
|
8900
|
-
|
|
8901
|
-
|
|
8902
|
-
|
|
8903
|
-
|
|
8904
|
-
|
|
8905
|
-
|
|
8906
|
-
|
|
8907
|
-
|
|
8908
|
-
|
|
8909
|
-
|
|
8910
|
-
|
|
8911
|
-
|
|
8912
|
-
|
|
8913
|
-
|
|
8914
|
-
|
|
8915
|
-
|
|
8916
|
-
|
|
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
|
-
throw new Error("Unsupported Solana transaction format");
|
|
8953
|
-
}
|
|
8954
|
-
function parseEVMTransactionToHex(transaction) {
|
|
8955
|
-
if (typeof transaction === "string" && transaction.startsWith("0x")) {
|
|
8956
|
-
return {
|
|
8957
|
-
parsed: transaction,
|
|
8958
|
-
originalFormat: "hex"
|
|
8959
|
-
};
|
|
8960
|
-
}
|
|
8961
|
-
if (transaction?.serialize && typeof transaction.serialize === "function") {
|
|
8962
|
-
const serialized = transaction.serialize();
|
|
8963
|
-
const hex = serialized.startsWith("0x") ? serialized : "0x" + serialized;
|
|
8964
|
-
return {
|
|
8965
|
-
parsed: hex,
|
|
8966
|
-
originalFormat: "ethers"
|
|
8967
|
-
};
|
|
8968
|
-
}
|
|
8969
|
-
if (transaction instanceof Uint8Array) {
|
|
8970
|
-
const hex = "0x" + bufferExports.Buffer.from(transaction).toString("hex");
|
|
8971
|
-
return {
|
|
8972
|
-
parsed: hex,
|
|
8973
|
-
originalFormat: "bytes"
|
|
8974
|
-
};
|
|
8975
|
-
}
|
|
8976
|
-
if (transaction && typeof transaction === "object" && (transaction.to || transaction.data || transaction.from)) {
|
|
8977
|
-
try {
|
|
8978
|
-
const { from, gas, ...txForSerialization } = transaction;
|
|
8979
|
-
if (gas) {
|
|
8980
|
-
txForSerialization.gasLimit = gas;
|
|
8981
|
-
}
|
|
8982
|
-
if (!txForSerialization.gasLimit) {
|
|
8983
|
-
if (txForSerialization.to && txForSerialization.value && !txForSerialization.data) {
|
|
8984
|
-
txForSerialization.gasLimit = "0x5208";
|
|
8985
|
-
}
|
|
8986
|
-
}
|
|
8987
|
-
if (txForSerialization.to && typeof txForSerialization.to === "string") {
|
|
8988
|
-
try {
|
|
8989
|
-
txForSerialization.to = getAddress(txForSerialization.to);
|
|
8990
|
-
} catch {
|
|
8991
|
-
txForSerialization.to = txForSerialization.to.toLowerCase();
|
|
8992
|
-
}
|
|
8993
|
-
}
|
|
8994
|
-
const serialized = Transaction.from(txForSerialization).unsignedSerialized;
|
|
8995
|
-
const hex = serialized.startsWith("0x") ? serialized : "0x" + serialized;
|
|
8996
|
-
return {
|
|
8997
|
-
parsed: hex,
|
|
8998
|
-
originalFormat: "json"
|
|
8999
|
-
};
|
|
9000
|
-
} catch (error) {
|
|
9001
|
-
const errorMessage = error instanceof Error ? error.message : "Unknown error";
|
|
9002
|
-
const txKeys = transaction ? Object.keys(transaction).join(", ") : "N/A";
|
|
9003
|
-
const txValues = transaction ? JSON.stringify(transaction, null, 2) : "N/A";
|
|
9004
|
-
throw new Error(
|
|
9005
|
-
`Failed to RLP encode EVM transaction: ${errorMessage}.
|
|
9006
|
-
Transaction keys: [${txKeys}].
|
|
9007
|
-
Transaction: ${txValues}
|
|
9008
|
-
Please ensure the transaction object includes required fields (to, value, chainId, gasLimit or gasPrice, etc.)`
|
|
9009
|
-
);
|
|
9010
|
-
}
|
|
9011
|
-
}
|
|
9012
|
-
throw new Error(
|
|
9013
|
-
"Unsupported EVM transaction format. Expected hex string, bytes, or transaction object with 'to', 'data', or 'from' fields."
|
|
9014
|
-
);
|
|
9015
|
-
}
|
|
9016
|
-
async function parseSuiTransactionToBase64Url(transaction) {
|
|
9017
|
-
if (transaction?.serialize && typeof transaction.serialize === "function") {
|
|
9018
|
-
const serialized = transaction.serialize();
|
|
9019
|
-
return {
|
|
9020
|
-
parsed: base64urlEncode(serialized),
|
|
9021
|
-
originalFormat: "sui-sdk"
|
|
9022
|
-
};
|
|
9023
|
-
}
|
|
9024
|
-
if (transaction instanceof Uint8Array) {
|
|
9025
|
-
return {
|
|
9026
|
-
parsed: base64urlEncode(transaction),
|
|
9027
|
-
originalFormat: "bytes"
|
|
9028
|
-
};
|
|
9029
|
-
}
|
|
9030
|
-
if (transaction?.build && typeof transaction.build === "function") {
|
|
9031
|
-
const built = await transaction.build();
|
|
9032
|
-
if (built?.serialize && typeof built.serialize === "function") {
|
|
9033
|
-
const serialized = built.serialize();
|
|
9034
|
-
return {
|
|
9035
|
-
parsed: base64urlEncode(serialized),
|
|
9036
|
-
originalFormat: "transaction-block"
|
|
9037
|
-
};
|
|
9038
|
-
}
|
|
9039
|
-
}
|
|
9040
|
-
throw new Error("Unsupported Sui transaction format");
|
|
9041
|
-
}
|
|
9042
|
-
function parseBitcoinTransactionToBase64Url(transaction) {
|
|
9043
|
-
if (transaction?.toBuffer && typeof transaction.toBuffer === "function") {
|
|
9044
|
-
const buffer = transaction.toBuffer();
|
|
9045
|
-
return {
|
|
9046
|
-
parsed: base64urlEncode(new Uint8Array(buffer)),
|
|
9047
|
-
originalFormat: "bitcoinjs-lib"
|
|
9048
|
-
};
|
|
9049
|
-
}
|
|
9050
|
-
if (transaction instanceof Uint8Array) {
|
|
9051
|
-
return {
|
|
9052
|
-
parsed: base64urlEncode(transaction),
|
|
9053
|
-
originalFormat: "bytes"
|
|
9054
|
-
};
|
|
9055
|
-
}
|
|
9056
|
-
if (typeof transaction === "string") {
|
|
9057
|
-
const bytes = new Uint8Array(bufferExports.Buffer.from(transaction, "hex"));
|
|
9058
|
-
return {
|
|
9059
|
-
parsed: base64urlEncode(bytes),
|
|
9060
|
-
originalFormat: "hex"
|
|
9061
|
-
};
|
|
9062
|
-
}
|
|
9063
|
-
throw new Error("Unsupported Bitcoin transaction format");
|
|
12014
|
+
//
|
|
12015
|
+
// Reset the array, or remove it completely if we have no more listeners.
|
|
12016
|
+
//
|
|
12017
|
+
if (events.length) this._events[evt] = events.length === 1 ? events[0] : events;
|
|
12018
|
+
else clearEvent(this, evt);
|
|
12019
|
+
}
|
|
12020
|
+
|
|
12021
|
+
return this;
|
|
12022
|
+
};
|
|
12023
|
+
|
|
12024
|
+
/**
|
|
12025
|
+
* Remove all listeners, or those of the specified event.
|
|
12026
|
+
*
|
|
12027
|
+
* @param {(String|Symbol)} [event] The event name.
|
|
12028
|
+
* @returns {EventEmitter} `this`.
|
|
12029
|
+
* @public
|
|
12030
|
+
*/
|
|
12031
|
+
EventEmitter.prototype.removeAllListeners = function removeAllListeners(event) {
|
|
12032
|
+
var evt;
|
|
12033
|
+
|
|
12034
|
+
if (event) {
|
|
12035
|
+
evt = prefix ? prefix + event : event;
|
|
12036
|
+
if (this._events[evt]) clearEvent(this, evt);
|
|
12037
|
+
} else {
|
|
12038
|
+
this._events = new Events();
|
|
12039
|
+
this._eventsCount = 0;
|
|
12040
|
+
}
|
|
12041
|
+
|
|
12042
|
+
return this;
|
|
12043
|
+
};
|
|
12044
|
+
|
|
12045
|
+
//
|
|
12046
|
+
// Alias methods names because people roll like that.
|
|
12047
|
+
//
|
|
12048
|
+
EventEmitter.prototype.off = EventEmitter.prototype.removeListener;
|
|
12049
|
+
EventEmitter.prototype.addListener = EventEmitter.prototype.on;
|
|
12050
|
+
|
|
12051
|
+
//
|
|
12052
|
+
// Expose the prefix.
|
|
12053
|
+
//
|
|
12054
|
+
EventEmitter.prefixed = prefix;
|
|
12055
|
+
|
|
12056
|
+
//
|
|
12057
|
+
// Allow `EventEmitter` to be imported as module namespace.
|
|
12058
|
+
//
|
|
12059
|
+
EventEmitter.EventEmitter = EventEmitter;
|
|
12060
|
+
|
|
12061
|
+
//
|
|
12062
|
+
// Expose the module.
|
|
12063
|
+
//
|
|
12064
|
+
{
|
|
12065
|
+
module.exports = EventEmitter;
|
|
12066
|
+
}
|
|
12067
|
+
} (eventemitter3));
|
|
12068
|
+
return eventemitter3.exports;
|
|
9064
12069
|
}
|
|
9065
12070
|
|
|
12071
|
+
var eventemitter3Exports = requireEventemitter3();
|
|
12072
|
+
var EventEmitter2 = /*@__PURE__*/getDefaultExportFromCjs(eventemitter3Exports);
|
|
12073
|
+
|
|
9066
12074
|
// src/embedded-provider.ts
|
|
9067
12075
|
|
|
9068
12076
|
// src/constants.ts
|
|
@@ -9074,7 +12082,7 @@ var EmbeddedSolanaChain = class {
|
|
|
9074
12082
|
this.currentNetworkId = NetworkId.SOLANA_MAINNET;
|
|
9075
12083
|
this._connected = false;
|
|
9076
12084
|
this._publicKey = null;
|
|
9077
|
-
this.eventEmitter = new
|
|
12085
|
+
this.eventEmitter = new EventEmitter2();
|
|
9078
12086
|
this.setupEventListeners();
|
|
9079
12087
|
this.syncInitialState();
|
|
9080
12088
|
}
|
|
@@ -9098,7 +12106,7 @@ var EmbeddedSolanaChain = class {
|
|
|
9098
12106
|
message: messageStr,
|
|
9099
12107
|
networkId: this.currentNetworkId
|
|
9100
12108
|
});
|
|
9101
|
-
const signature = typeof result.signature === "string" ? new Uint8Array(
|
|
12109
|
+
const signature = typeof result.signature === "string" ? new Uint8Array(bs582.decode(result.signature)) : result.signature;
|
|
9102
12110
|
return {
|
|
9103
12111
|
signature,
|
|
9104
12112
|
publicKey: this._publicKey || ""
|
|
@@ -9204,7 +12212,7 @@ var EmbeddedEthereumChain = class {
|
|
|
9204
12212
|
this.currentNetworkId = NetworkId.ETHEREUM_MAINNET;
|
|
9205
12213
|
this._connected = false;
|
|
9206
12214
|
this._accounts = [];
|
|
9207
|
-
this.eventEmitter = new
|
|
12215
|
+
this.eventEmitter = new EventEmitter2();
|
|
9208
12216
|
this.setupEventListeners();
|
|
9209
12217
|
this.syncInitialState();
|
|
9210
12218
|
}
|
|
@@ -9781,7 +12789,7 @@ var EmbeddedProvider$1 = class EmbeddedProvider {
|
|
|
9781
12789
|
publicKey: stamperInfo.publicKey,
|
|
9782
12790
|
platform: platformName
|
|
9783
12791
|
});
|
|
9784
|
-
const base64urlPublicKey = base64urlEncode(
|
|
12792
|
+
const base64urlPublicKey = base64urlEncode(bs582.decode(stamperInfo.publicKey));
|
|
9785
12793
|
const username = `user-${randomUUID()}`;
|
|
9786
12794
|
const { organizationId } = await tempClient.createOrganization(organizationName, [
|
|
9787
12795
|
{
|
|
@@ -10370,6 +13378,133 @@ var EmbeddedProvider$1 = class EmbeddedProvider {
|
|
|
10370
13378
|
}
|
|
10371
13379
|
};
|
|
10372
13380
|
|
|
13381
|
+
// base-x encoding / decoding
|
|
13382
|
+
// Copyright (c) 2018 base-x contributors
|
|
13383
|
+
// Copyright (c) 2014-2018 The Bitcoin Core developers (base58.cpp)
|
|
13384
|
+
// Distributed under the MIT software license, see the accompanying
|
|
13385
|
+
// file LICENSE or http://www.opensource.org/licenses/mit-license.php.
|
|
13386
|
+
function base (ALPHABET) {
|
|
13387
|
+
if (ALPHABET.length >= 255) { throw new TypeError('Alphabet too long') }
|
|
13388
|
+
const BASE_MAP = new Uint8Array(256);
|
|
13389
|
+
for (let j = 0; j < BASE_MAP.length; j++) {
|
|
13390
|
+
BASE_MAP[j] = 255;
|
|
13391
|
+
}
|
|
13392
|
+
for (let i = 0; i < ALPHABET.length; i++) {
|
|
13393
|
+
const x = ALPHABET.charAt(i);
|
|
13394
|
+
const xc = x.charCodeAt(0);
|
|
13395
|
+
if (BASE_MAP[xc] !== 255) { throw new TypeError(x + ' is ambiguous') }
|
|
13396
|
+
BASE_MAP[xc] = i;
|
|
13397
|
+
}
|
|
13398
|
+
const BASE = ALPHABET.length;
|
|
13399
|
+
const LEADER = ALPHABET.charAt(0);
|
|
13400
|
+
const FACTOR = Math.log(BASE) / Math.log(256); // log(BASE) / log(256), rounded up
|
|
13401
|
+
const iFACTOR = Math.log(256) / Math.log(BASE); // log(256) / log(BASE), rounded up
|
|
13402
|
+
function encode (source) {
|
|
13403
|
+
// eslint-disable-next-line no-empty
|
|
13404
|
+
if (source instanceof Uint8Array) ; else if (ArrayBuffer.isView(source)) {
|
|
13405
|
+
source = new Uint8Array(source.buffer, source.byteOffset, source.byteLength);
|
|
13406
|
+
} else if (Array.isArray(source)) {
|
|
13407
|
+
source = Uint8Array.from(source);
|
|
13408
|
+
}
|
|
13409
|
+
if (!(source instanceof Uint8Array)) { throw new TypeError('Expected Uint8Array') }
|
|
13410
|
+
if (source.length === 0) { return '' }
|
|
13411
|
+
// Skip & count leading zeroes.
|
|
13412
|
+
let zeroes = 0;
|
|
13413
|
+
let length = 0;
|
|
13414
|
+
let pbegin = 0;
|
|
13415
|
+
const pend = source.length;
|
|
13416
|
+
while (pbegin !== pend && source[pbegin] === 0) {
|
|
13417
|
+
pbegin++;
|
|
13418
|
+
zeroes++;
|
|
13419
|
+
}
|
|
13420
|
+
// Allocate enough space in big-endian base58 representation.
|
|
13421
|
+
const size = ((pend - pbegin) * iFACTOR + 1) >>> 0;
|
|
13422
|
+
const b58 = new Uint8Array(size);
|
|
13423
|
+
// Process the bytes.
|
|
13424
|
+
while (pbegin !== pend) {
|
|
13425
|
+
let carry = source[pbegin];
|
|
13426
|
+
// Apply "b58 = b58 * 256 + ch".
|
|
13427
|
+
let i = 0;
|
|
13428
|
+
for (let it1 = size - 1; (carry !== 0 || i < length) && (it1 !== -1); it1--, i++) {
|
|
13429
|
+
carry += (256 * b58[it1]) >>> 0;
|
|
13430
|
+
b58[it1] = (carry % BASE) >>> 0;
|
|
13431
|
+
carry = (carry / BASE) >>> 0;
|
|
13432
|
+
}
|
|
13433
|
+
if (carry !== 0) { throw new Error('Non-zero carry') }
|
|
13434
|
+
length = i;
|
|
13435
|
+
pbegin++;
|
|
13436
|
+
}
|
|
13437
|
+
// Skip leading zeroes in base58 result.
|
|
13438
|
+
let it2 = size - length;
|
|
13439
|
+
while (it2 !== size && b58[it2] === 0) {
|
|
13440
|
+
it2++;
|
|
13441
|
+
}
|
|
13442
|
+
// Translate the result into a string.
|
|
13443
|
+
let str = LEADER.repeat(zeroes);
|
|
13444
|
+
for (; it2 < size; ++it2) { str += ALPHABET.charAt(b58[it2]); }
|
|
13445
|
+
return str
|
|
13446
|
+
}
|
|
13447
|
+
function decodeUnsafe (source) {
|
|
13448
|
+
if (typeof source !== 'string') { throw new TypeError('Expected String') }
|
|
13449
|
+
if (source.length === 0) { return new Uint8Array() }
|
|
13450
|
+
let psz = 0;
|
|
13451
|
+
// Skip and count leading '1's.
|
|
13452
|
+
let zeroes = 0;
|
|
13453
|
+
let length = 0;
|
|
13454
|
+
while (source[psz] === LEADER) {
|
|
13455
|
+
zeroes++;
|
|
13456
|
+
psz++;
|
|
13457
|
+
}
|
|
13458
|
+
// Allocate enough space in big-endian base256 representation.
|
|
13459
|
+
const size = (((source.length - psz) * FACTOR) + 1) >>> 0; // log(58) / log(256), rounded up.
|
|
13460
|
+
const b256 = new Uint8Array(size);
|
|
13461
|
+
// Process the characters.
|
|
13462
|
+
while (psz < source.length) {
|
|
13463
|
+
// Find code of next character
|
|
13464
|
+
const charCode = source.charCodeAt(psz);
|
|
13465
|
+
// Base map can not be indexed using char code
|
|
13466
|
+
if (charCode > 255) { return }
|
|
13467
|
+
// Decode character
|
|
13468
|
+
let carry = BASE_MAP[charCode];
|
|
13469
|
+
// Invalid character
|
|
13470
|
+
if (carry === 255) { return }
|
|
13471
|
+
let i = 0;
|
|
13472
|
+
for (let it3 = size - 1; (carry !== 0 || i < length) && (it3 !== -1); it3--, i++) {
|
|
13473
|
+
carry += (BASE * b256[it3]) >>> 0;
|
|
13474
|
+
b256[it3] = (carry % 256) >>> 0;
|
|
13475
|
+
carry = (carry / 256) >>> 0;
|
|
13476
|
+
}
|
|
13477
|
+
if (carry !== 0) { throw new Error('Non-zero carry') }
|
|
13478
|
+
length = i;
|
|
13479
|
+
psz++;
|
|
13480
|
+
}
|
|
13481
|
+
// Skip leading zeroes in b256.
|
|
13482
|
+
let it4 = size - length;
|
|
13483
|
+
while (it4 !== size && b256[it4] === 0) {
|
|
13484
|
+
it4++;
|
|
13485
|
+
}
|
|
13486
|
+
const vch = new Uint8Array(zeroes + (size - it4));
|
|
13487
|
+
let j = zeroes;
|
|
13488
|
+
while (it4 !== size) {
|
|
13489
|
+
vch[j++] = b256[it4++];
|
|
13490
|
+
}
|
|
13491
|
+
return vch
|
|
13492
|
+
}
|
|
13493
|
+
function decode (string) {
|
|
13494
|
+
const buffer = decodeUnsafe(string);
|
|
13495
|
+
if (buffer) { return buffer }
|
|
13496
|
+
throw new Error('Non-base' + BASE + ' character')
|
|
13497
|
+
}
|
|
13498
|
+
return {
|
|
13499
|
+
encode,
|
|
13500
|
+
decodeUnsafe,
|
|
13501
|
+
decode
|
|
13502
|
+
}
|
|
13503
|
+
}
|
|
13504
|
+
|
|
13505
|
+
var ALPHABET = '123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz';
|
|
13506
|
+
var bs58 = base(ALPHABET);
|
|
13507
|
+
|
|
10373
13508
|
// src/index.ts
|
|
10374
13509
|
var IndexedDbStamper = class {
|
|
10375
13510
|
// Optional for PKI, required for OIDC
|
|
@@ -10443,14 +13578,14 @@ var IndexedDbStamper = class {
|
|
|
10443
13578
|
const salt = params.type === "OIDC" ? params.salt : this.salt;
|
|
10444
13579
|
const stampData = stampType === "PKI" ? {
|
|
10445
13580
|
// Decode base58 public key to bytes, then encode as base64url (consistent with ApiKeyStamper)
|
|
10446
|
-
publicKey: base64urlEncode(bs58
|
|
13581
|
+
publicKey: base64urlEncode(bs58.decode(this.activeKeyPairRecord.keyInfo.publicKey)),
|
|
10447
13582
|
signature: signatureBase64url,
|
|
10448
13583
|
kind: "PKI",
|
|
10449
13584
|
algorithm: this.algorithm
|
|
10450
13585
|
} : {
|
|
10451
13586
|
kind: "OIDC",
|
|
10452
13587
|
idToken,
|
|
10453
|
-
publicKey: base64urlEncode(bs58
|
|
13588
|
+
publicKey: base64urlEncode(bs58.decode(this.activeKeyPairRecord.keyInfo.publicKey)),
|
|
10454
13589
|
salt,
|
|
10455
13590
|
algorithm: this.algorithm,
|
|
10456
13591
|
signature: signatureBase64url
|
|
@@ -10553,7 +13688,7 @@ var IndexedDbStamper = class {
|
|
|
10553
13688
|
["sign", "verify"]
|
|
10554
13689
|
);
|
|
10555
13690
|
const rawPublicKeyBuffer = await crypto.subtle.exportKey("raw", keyPair.publicKey);
|
|
10556
|
-
const publicKeyBase58 = bs58
|
|
13691
|
+
const publicKeyBase58 = bs58.encode(new Uint8Array(rawPublicKeyBuffer));
|
|
10557
13692
|
const keyIdBuffer = await crypto.subtle.digest("SHA-256", rawPublicKeyBuffer);
|
|
10558
13693
|
const keyId = base64urlEncode(new Uint8Array(keyIdBuffer)).substring(0, 16);
|
|
10559
13694
|
const now = Date.now();
|
|
@@ -15883,4 +19018,4 @@ function ConnectBox({ maxWidth = "350px", transparent = false, appIcon, appName
|
|
|
15883
19018
|
}
|
|
15884
19019
|
|
|
15885
19020
|
export { DerivationInfoAddressFormatEnum as AddressType, ConnectBox, ConnectButton, DebugLevel, NetworkId, PhantomProvider, darkTheme, debug, isMobileDevice, lightTheme, mergeTheme, useAccounts, useAutoConfirm, useConnect, useDisconnect, useDiscoveredWallets, useEthereum, useIsExtensionInstalled, useIsPhantomLoginAvailable, useModal, usePhantom, useSolana, useTheme };
|
|
15886
|
-
//# sourceMappingURL=index-
|
|
19021
|
+
//# sourceMappingURL=index-dcJIjFrs.esm.js.map
|