@pooflabs/web 0.0.82 → 0.0.83
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/{index-BsY_Lgiu.esm.js → index-B7yaLhND.esm.js} +17 -17
- package/dist/index-B7yaLhND.esm.js.map +1 -0
- package/dist/{index-DlKo76M3.js → index-BxXQhFLQ.js} +10 -3069
- package/dist/index-BxXQhFLQ.js.map +1 -0
- package/dist/{index-DWf2AOhe.esm.js → index-CP_wLmYu.esm.js} +9 -3068
- package/dist/index-CP_wLmYu.esm.js.map +1 -0
- package/dist/{index-CK_2Zn89.esm.js → index-CpaP1yGp.esm.js} +10 -3069
- package/dist/index-CpaP1yGp.esm.js.map +1 -0
- package/dist/{index-BicMkamC.js → index-DP0xF34Z.js} +17 -18
- package/dist/index-DP0xF34Z.js.map +1 -0
- package/dist/{index-Dz0bPXrU.js → index-DQWyH96R.js} +2 -2
- package/dist/index-DQWyH96R.js.map +1 -0
- package/dist/index-DfOd8wW4.esm.js +6 -0
- package/dist/index-DfOd8wW4.esm.js.map +1 -0
- package/dist/{index-Ci3m3diI.js → index-FviRSm3S.js} +9 -3068
- package/dist/index-FviRSm3S.js.map +1 -0
- package/dist/index.browser-1_M66nQ6.esm.js +1096 -0
- package/dist/index.browser-1_M66nQ6.esm.js.map +1 -0
- package/dist/{index.browser-DCOvqSUT.esm.js → index.browser-B_wQp2A8.esm.js} +1571 -1368
- package/dist/index.browser-B_wQp2A8.esm.js.map +1 -0
- package/dist/index.browser-BfnOoa_h.js +1099 -0
- package/dist/index.browser-BfnOoa_h.js.map +1 -0
- package/dist/index.browser-BhppfDyf.js +105 -0
- package/dist/index.browser-BhppfDyf.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-BkMiHSON.js → index.browser-_zN3Uapq.js} +1571 -1368
- package/dist/index.browser-_zN3Uapq.js.map +1 -0
- package/dist/index.browser-vUinl_9y.esm.js +102 -0
- package/dist/index.browser-vUinl_9y.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.esm.js +1 -1
- package/dist/index.js +1 -1
- package/dist/{index.native-CLaHKvDv.esm.js → index.native-CyEwEeKr.esm.js} +16 -16
- package/dist/index.native-CyEwEeKr.esm.js.map +1 -0
- package/dist/{index.native-11supFRU.js → index.native-Dkf8NZ2O.js} +16 -18
- package/dist/index.native-Dkf8NZ2O.js.map +1 -0
- package/dist/index.native.esm.js +1 -1
- package/dist/index.native.js +1 -1
- package/dist/{phantom-wallet-provider-Xb070-O6.js → phantom-wallet-provider-CVyVJmH0.js} +4 -4
- package/dist/{phantom-wallet-provider-Xb070-O6.js.map → phantom-wallet-provider-CVyVJmH0.js.map} +1 -1
- package/dist/{phantom-wallet-provider-BN47klTp.esm.js → phantom-wallet-provider-fkcFbwPk.esm.js} +4 -4
- package/dist/{phantom-wallet-provider-BN47klTp.esm.js.map → phantom-wallet-provider-fkcFbwPk.esm.js.map} +1 -1
- package/dist/{privy-wallet-provider-DUJS5viU.esm.js → privy-wallet-provider-CpHAxPcv.esm.js} +4 -4
- package/dist/{privy-wallet-provider-DUJS5viU.esm.js.map → privy-wallet-provider-CpHAxPcv.esm.js.map} +1 -1
- package/dist/{privy-wallet-provider-Ch22rj_G.js → privy-wallet-provider-CrBZ52nR.js} +4 -4
- package/dist/{privy-wallet-provider-Ch22rj_G.js.map → privy-wallet-provider-CrBZ52nR.js.map} +1 -1
- package/dist/{solana-mobile-wallet-provider-BXm94fqW.js → solana-mobile-wallet-provider-CAaGfPZJ.js} +4 -4
- package/dist/{solana-mobile-wallet-provider-BXm94fqW.js.map → solana-mobile-wallet-provider-CAaGfPZJ.js.map} +1 -1
- package/dist/{solana-mobile-wallet-provider-BF04Xp8P.esm.js → solana-mobile-wallet-provider-DGyWHJVI.esm.js} +4 -4
- package/dist/{solana-mobile-wallet-provider-BF04Xp8P.esm.js.map → solana-mobile-wallet-provider-DGyWHJVI.esm.js.map} +1 -1
- package/package.json +2 -2
- package/dist/index-BicMkamC.js.map +0 -1
- package/dist/index-BsY_Lgiu.esm.js.map +0 -1
- package/dist/index-CHWmdXHE.esm.js +0 -6
- package/dist/index-CHWmdXHE.esm.js.map +0 -1
- package/dist/index-CK_2Zn89.esm.js.map +0 -1
- package/dist/index-Ci3m3diI.js.map +0 -1
- package/dist/index-DWf2AOhe.esm.js.map +0 -1
- package/dist/index-DlKo76M3.js.map +0 -1
- package/dist/index-Dz0bPXrU.js.map +0 -1
- package/dist/index.browser-BkMiHSON.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-C9bFQZyQ.esm.js +0 -1373
- package/dist/index.browser-C9bFQZyQ.esm.js.map +0 -1
- package/dist/index.browser-DCOvqSUT.esm.js.map +0 -1
- package/dist/index.browser-Dbq5Qf1G.esm.js +0 -242
- package/dist/index.browser-Dbq5Qf1G.esm.js.map +0 -1
- package/dist/index.browser-Df7yN8D5.js +0 -245
- package/dist/index.browser-Df7yN8D5.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-dszs5oe5.js +0 -1376
- package/dist/index.browser-dszs5oe5.js.map +0 -1
- package/dist/index.native-11supFRU.js.map +0 -1
- package/dist/index.native-CLaHKvDv.esm.js.map +0 -1
|
@@ -1,8 +1,8 @@
|
|
|
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 } from './index-
|
|
5
|
-
import { p as
|
|
4
|
+
import { b as bufferExports } from './index-DfOd8wW4.esm.js';
|
|
5
|
+
import { p as getDefaultExportFromCjs, d as base58 } from './index.native-CyEwEeKr.esm.js';
|
|
6
6
|
import { Transaction as Transaction$1, VersionedTransaction } from '@solana/web3.js';
|
|
7
7
|
import { jsx, jsxs, Fragment } from 'react/jsx-runtime';
|
|
8
8
|
import '@coral-xyz/anchor';
|
|
@@ -999,2557 +999,6 @@ function isSolanaChain(networkId) {
|
|
|
999
999
|
return network === "solana";
|
|
1000
1000
|
}
|
|
1001
1001
|
|
|
1002
|
-
var naclFast = {exports: {}};
|
|
1003
|
-
|
|
1004
|
-
var hasRequiredNaclFast;
|
|
1005
|
-
|
|
1006
|
-
function requireNaclFast () {
|
|
1007
|
-
if (hasRequiredNaclFast) return naclFast.exports;
|
|
1008
|
-
hasRequiredNaclFast = 1;
|
|
1009
|
-
(function (module) {
|
|
1010
|
-
(function(nacl) {
|
|
1011
|
-
|
|
1012
|
-
// Ported in 2014 by Dmitry Chestnykh and Devi Mandiri.
|
|
1013
|
-
// Public domain.
|
|
1014
|
-
//
|
|
1015
|
-
// Implementation derived from TweetNaCl version 20140427.
|
|
1016
|
-
// See for details: http://tweetnacl.cr.yp.to/
|
|
1017
|
-
|
|
1018
|
-
var gf = function(init) {
|
|
1019
|
-
var i, r = new Float64Array(16);
|
|
1020
|
-
if (init) for (i = 0; i < init.length; i++) r[i] = init[i];
|
|
1021
|
-
return r;
|
|
1022
|
-
};
|
|
1023
|
-
|
|
1024
|
-
// Pluggable, initialized in high-level API below.
|
|
1025
|
-
var randombytes = function(/* x, n */) { throw new Error('no PRNG'); };
|
|
1026
|
-
|
|
1027
|
-
var _0 = new Uint8Array(16);
|
|
1028
|
-
var _9 = new Uint8Array(32); _9[0] = 9;
|
|
1029
|
-
|
|
1030
|
-
var gf0 = gf(),
|
|
1031
|
-
gf1 = gf([1]),
|
|
1032
|
-
_121665 = gf([0xdb41, 1]),
|
|
1033
|
-
D = gf([0x78a3, 0x1359, 0x4dca, 0x75eb, 0xd8ab, 0x4141, 0x0a4d, 0x0070, 0xe898, 0x7779, 0x4079, 0x8cc7, 0xfe73, 0x2b6f, 0x6cee, 0x5203]),
|
|
1034
|
-
D2 = gf([0xf159, 0x26b2, 0x9b94, 0xebd6, 0xb156, 0x8283, 0x149a, 0x00e0, 0xd130, 0xeef3, 0x80f2, 0x198e, 0xfce7, 0x56df, 0xd9dc, 0x2406]),
|
|
1035
|
-
X = gf([0xd51a, 0x8f25, 0x2d60, 0xc956, 0xa7b2, 0x9525, 0xc760, 0x692c, 0xdc5c, 0xfdd6, 0xe231, 0xc0a4, 0x53fe, 0xcd6e, 0x36d3, 0x2169]),
|
|
1036
|
-
Y = gf([0x6658, 0x6666, 0x6666, 0x6666, 0x6666, 0x6666, 0x6666, 0x6666, 0x6666, 0x6666, 0x6666, 0x6666, 0x6666, 0x6666, 0x6666, 0x6666]),
|
|
1037
|
-
I = gf([0xa0b0, 0x4a0e, 0x1b27, 0xc4ee, 0xe478, 0xad2f, 0x1806, 0x2f43, 0xd7a7, 0x3dfb, 0x0099, 0x2b4d, 0xdf0b, 0x4fc1, 0x2480, 0x2b83]);
|
|
1038
|
-
|
|
1039
|
-
function ts64(x, i, h, l) {
|
|
1040
|
-
x[i] = (h >> 24) & 0xff;
|
|
1041
|
-
x[i+1] = (h >> 16) & 0xff;
|
|
1042
|
-
x[i+2] = (h >> 8) & 0xff;
|
|
1043
|
-
x[i+3] = h & 0xff;
|
|
1044
|
-
x[i+4] = (l >> 24) & 0xff;
|
|
1045
|
-
x[i+5] = (l >> 16) & 0xff;
|
|
1046
|
-
x[i+6] = (l >> 8) & 0xff;
|
|
1047
|
-
x[i+7] = l & 0xff;
|
|
1048
|
-
}
|
|
1049
|
-
|
|
1050
|
-
function vn(x, xi, y, yi, n) {
|
|
1051
|
-
var i,d = 0;
|
|
1052
|
-
for (i = 0; i < n; i++) d |= x[xi+i]^y[yi+i];
|
|
1053
|
-
return (1 & ((d - 1) >>> 8)) - 1;
|
|
1054
|
-
}
|
|
1055
|
-
|
|
1056
|
-
function crypto_verify_16(x, xi, y, yi) {
|
|
1057
|
-
return vn(x,xi,y,yi,16);
|
|
1058
|
-
}
|
|
1059
|
-
|
|
1060
|
-
function crypto_verify_32(x, xi, y, yi) {
|
|
1061
|
-
return vn(x,xi,y,yi,32);
|
|
1062
|
-
}
|
|
1063
|
-
|
|
1064
|
-
function core_salsa20(o, p, k, c) {
|
|
1065
|
-
var j0 = c[ 0] & 0xff | (c[ 1] & 0xff)<<8 | (c[ 2] & 0xff)<<16 | (c[ 3] & 0xff)<<24,
|
|
1066
|
-
j1 = k[ 0] & 0xff | (k[ 1] & 0xff)<<8 | (k[ 2] & 0xff)<<16 | (k[ 3] & 0xff)<<24,
|
|
1067
|
-
j2 = k[ 4] & 0xff | (k[ 5] & 0xff)<<8 | (k[ 6] & 0xff)<<16 | (k[ 7] & 0xff)<<24,
|
|
1068
|
-
j3 = k[ 8] & 0xff | (k[ 9] & 0xff)<<8 | (k[10] & 0xff)<<16 | (k[11] & 0xff)<<24,
|
|
1069
|
-
j4 = k[12] & 0xff | (k[13] & 0xff)<<8 | (k[14] & 0xff)<<16 | (k[15] & 0xff)<<24,
|
|
1070
|
-
j5 = c[ 4] & 0xff | (c[ 5] & 0xff)<<8 | (c[ 6] & 0xff)<<16 | (c[ 7] & 0xff)<<24,
|
|
1071
|
-
j6 = p[ 0] & 0xff | (p[ 1] & 0xff)<<8 | (p[ 2] & 0xff)<<16 | (p[ 3] & 0xff)<<24,
|
|
1072
|
-
j7 = p[ 4] & 0xff | (p[ 5] & 0xff)<<8 | (p[ 6] & 0xff)<<16 | (p[ 7] & 0xff)<<24,
|
|
1073
|
-
j8 = p[ 8] & 0xff | (p[ 9] & 0xff)<<8 | (p[10] & 0xff)<<16 | (p[11] & 0xff)<<24,
|
|
1074
|
-
j9 = p[12] & 0xff | (p[13] & 0xff)<<8 | (p[14] & 0xff)<<16 | (p[15] & 0xff)<<24,
|
|
1075
|
-
j10 = c[ 8] & 0xff | (c[ 9] & 0xff)<<8 | (c[10] & 0xff)<<16 | (c[11] & 0xff)<<24,
|
|
1076
|
-
j11 = k[16] & 0xff | (k[17] & 0xff)<<8 | (k[18] & 0xff)<<16 | (k[19] & 0xff)<<24,
|
|
1077
|
-
j12 = k[20] & 0xff | (k[21] & 0xff)<<8 | (k[22] & 0xff)<<16 | (k[23] & 0xff)<<24,
|
|
1078
|
-
j13 = k[24] & 0xff | (k[25] & 0xff)<<8 | (k[26] & 0xff)<<16 | (k[27] & 0xff)<<24,
|
|
1079
|
-
j14 = k[28] & 0xff | (k[29] & 0xff)<<8 | (k[30] & 0xff)<<16 | (k[31] & 0xff)<<24,
|
|
1080
|
-
j15 = c[12] & 0xff | (c[13] & 0xff)<<8 | (c[14] & 0xff)<<16 | (c[15] & 0xff)<<24;
|
|
1081
|
-
|
|
1082
|
-
var x0 = j0, x1 = j1, x2 = j2, x3 = j3, x4 = j4, x5 = j5, x6 = j6, x7 = j7,
|
|
1083
|
-
x8 = j8, x9 = j9, x10 = j10, x11 = j11, x12 = j12, x13 = j13, x14 = j14,
|
|
1084
|
-
x15 = j15, u;
|
|
1085
|
-
|
|
1086
|
-
for (var i = 0; i < 20; i += 2) {
|
|
1087
|
-
u = x0 + x12 | 0;
|
|
1088
|
-
x4 ^= u<<7 | u>>>(32-7);
|
|
1089
|
-
u = x4 + x0 | 0;
|
|
1090
|
-
x8 ^= u<<9 | u>>>(32-9);
|
|
1091
|
-
u = x8 + x4 | 0;
|
|
1092
|
-
x12 ^= u<<13 | u>>>(32-13);
|
|
1093
|
-
u = x12 + x8 | 0;
|
|
1094
|
-
x0 ^= u<<18 | u>>>(32-18);
|
|
1095
|
-
|
|
1096
|
-
u = x5 + x1 | 0;
|
|
1097
|
-
x9 ^= u<<7 | u>>>(32-7);
|
|
1098
|
-
u = x9 + x5 | 0;
|
|
1099
|
-
x13 ^= u<<9 | u>>>(32-9);
|
|
1100
|
-
u = x13 + x9 | 0;
|
|
1101
|
-
x1 ^= u<<13 | u>>>(32-13);
|
|
1102
|
-
u = x1 + x13 | 0;
|
|
1103
|
-
x5 ^= u<<18 | u>>>(32-18);
|
|
1104
|
-
|
|
1105
|
-
u = x10 + x6 | 0;
|
|
1106
|
-
x14 ^= u<<7 | u>>>(32-7);
|
|
1107
|
-
u = x14 + x10 | 0;
|
|
1108
|
-
x2 ^= u<<9 | u>>>(32-9);
|
|
1109
|
-
u = x2 + x14 | 0;
|
|
1110
|
-
x6 ^= u<<13 | u>>>(32-13);
|
|
1111
|
-
u = x6 + x2 | 0;
|
|
1112
|
-
x10 ^= u<<18 | u>>>(32-18);
|
|
1113
|
-
|
|
1114
|
-
u = x15 + x11 | 0;
|
|
1115
|
-
x3 ^= u<<7 | u>>>(32-7);
|
|
1116
|
-
u = x3 + x15 | 0;
|
|
1117
|
-
x7 ^= u<<9 | u>>>(32-9);
|
|
1118
|
-
u = x7 + x3 | 0;
|
|
1119
|
-
x11 ^= u<<13 | u>>>(32-13);
|
|
1120
|
-
u = x11 + x7 | 0;
|
|
1121
|
-
x15 ^= u<<18 | u>>>(32-18);
|
|
1122
|
-
|
|
1123
|
-
u = x0 + x3 | 0;
|
|
1124
|
-
x1 ^= u<<7 | u>>>(32-7);
|
|
1125
|
-
u = x1 + x0 | 0;
|
|
1126
|
-
x2 ^= u<<9 | u>>>(32-9);
|
|
1127
|
-
u = x2 + x1 | 0;
|
|
1128
|
-
x3 ^= u<<13 | u>>>(32-13);
|
|
1129
|
-
u = x3 + x2 | 0;
|
|
1130
|
-
x0 ^= u<<18 | u>>>(32-18);
|
|
1131
|
-
|
|
1132
|
-
u = x5 + x4 | 0;
|
|
1133
|
-
x6 ^= u<<7 | u>>>(32-7);
|
|
1134
|
-
u = x6 + x5 | 0;
|
|
1135
|
-
x7 ^= u<<9 | u>>>(32-9);
|
|
1136
|
-
u = x7 + x6 | 0;
|
|
1137
|
-
x4 ^= u<<13 | u>>>(32-13);
|
|
1138
|
-
u = x4 + x7 | 0;
|
|
1139
|
-
x5 ^= u<<18 | u>>>(32-18);
|
|
1140
|
-
|
|
1141
|
-
u = x10 + x9 | 0;
|
|
1142
|
-
x11 ^= u<<7 | u>>>(32-7);
|
|
1143
|
-
u = x11 + x10 | 0;
|
|
1144
|
-
x8 ^= u<<9 | u>>>(32-9);
|
|
1145
|
-
u = x8 + x11 | 0;
|
|
1146
|
-
x9 ^= u<<13 | u>>>(32-13);
|
|
1147
|
-
u = x9 + x8 | 0;
|
|
1148
|
-
x10 ^= u<<18 | u>>>(32-18);
|
|
1149
|
-
|
|
1150
|
-
u = x15 + x14 | 0;
|
|
1151
|
-
x12 ^= u<<7 | u>>>(32-7);
|
|
1152
|
-
u = x12 + x15 | 0;
|
|
1153
|
-
x13 ^= u<<9 | u>>>(32-9);
|
|
1154
|
-
u = x13 + x12 | 0;
|
|
1155
|
-
x14 ^= u<<13 | u>>>(32-13);
|
|
1156
|
-
u = x14 + x13 | 0;
|
|
1157
|
-
x15 ^= u<<18 | u>>>(32-18);
|
|
1158
|
-
}
|
|
1159
|
-
x0 = x0 + j0 | 0;
|
|
1160
|
-
x1 = x1 + j1 | 0;
|
|
1161
|
-
x2 = x2 + j2 | 0;
|
|
1162
|
-
x3 = x3 + j3 | 0;
|
|
1163
|
-
x4 = x4 + j4 | 0;
|
|
1164
|
-
x5 = x5 + j5 | 0;
|
|
1165
|
-
x6 = x6 + j6 | 0;
|
|
1166
|
-
x7 = x7 + j7 | 0;
|
|
1167
|
-
x8 = x8 + j8 | 0;
|
|
1168
|
-
x9 = x9 + j9 | 0;
|
|
1169
|
-
x10 = x10 + j10 | 0;
|
|
1170
|
-
x11 = x11 + j11 | 0;
|
|
1171
|
-
x12 = x12 + j12 | 0;
|
|
1172
|
-
x13 = x13 + j13 | 0;
|
|
1173
|
-
x14 = x14 + j14 | 0;
|
|
1174
|
-
x15 = x15 + j15 | 0;
|
|
1175
|
-
|
|
1176
|
-
o[ 0] = x0 >>> 0 & 0xff;
|
|
1177
|
-
o[ 1] = x0 >>> 8 & 0xff;
|
|
1178
|
-
o[ 2] = x0 >>> 16 & 0xff;
|
|
1179
|
-
o[ 3] = x0 >>> 24 & 0xff;
|
|
1180
|
-
|
|
1181
|
-
o[ 4] = x1 >>> 0 & 0xff;
|
|
1182
|
-
o[ 5] = x1 >>> 8 & 0xff;
|
|
1183
|
-
o[ 6] = x1 >>> 16 & 0xff;
|
|
1184
|
-
o[ 7] = x1 >>> 24 & 0xff;
|
|
1185
|
-
|
|
1186
|
-
o[ 8] = x2 >>> 0 & 0xff;
|
|
1187
|
-
o[ 9] = x2 >>> 8 & 0xff;
|
|
1188
|
-
o[10] = x2 >>> 16 & 0xff;
|
|
1189
|
-
o[11] = x2 >>> 24 & 0xff;
|
|
1190
|
-
|
|
1191
|
-
o[12] = x3 >>> 0 & 0xff;
|
|
1192
|
-
o[13] = x3 >>> 8 & 0xff;
|
|
1193
|
-
o[14] = x3 >>> 16 & 0xff;
|
|
1194
|
-
o[15] = x3 >>> 24 & 0xff;
|
|
1195
|
-
|
|
1196
|
-
o[16] = x4 >>> 0 & 0xff;
|
|
1197
|
-
o[17] = x4 >>> 8 & 0xff;
|
|
1198
|
-
o[18] = x4 >>> 16 & 0xff;
|
|
1199
|
-
o[19] = x4 >>> 24 & 0xff;
|
|
1200
|
-
|
|
1201
|
-
o[20] = x5 >>> 0 & 0xff;
|
|
1202
|
-
o[21] = x5 >>> 8 & 0xff;
|
|
1203
|
-
o[22] = x5 >>> 16 & 0xff;
|
|
1204
|
-
o[23] = x5 >>> 24 & 0xff;
|
|
1205
|
-
|
|
1206
|
-
o[24] = x6 >>> 0 & 0xff;
|
|
1207
|
-
o[25] = x6 >>> 8 & 0xff;
|
|
1208
|
-
o[26] = x6 >>> 16 & 0xff;
|
|
1209
|
-
o[27] = x6 >>> 24 & 0xff;
|
|
1210
|
-
|
|
1211
|
-
o[28] = x7 >>> 0 & 0xff;
|
|
1212
|
-
o[29] = x7 >>> 8 & 0xff;
|
|
1213
|
-
o[30] = x7 >>> 16 & 0xff;
|
|
1214
|
-
o[31] = x7 >>> 24 & 0xff;
|
|
1215
|
-
|
|
1216
|
-
o[32] = x8 >>> 0 & 0xff;
|
|
1217
|
-
o[33] = x8 >>> 8 & 0xff;
|
|
1218
|
-
o[34] = x8 >>> 16 & 0xff;
|
|
1219
|
-
o[35] = x8 >>> 24 & 0xff;
|
|
1220
|
-
|
|
1221
|
-
o[36] = x9 >>> 0 & 0xff;
|
|
1222
|
-
o[37] = x9 >>> 8 & 0xff;
|
|
1223
|
-
o[38] = x9 >>> 16 & 0xff;
|
|
1224
|
-
o[39] = x9 >>> 24 & 0xff;
|
|
1225
|
-
|
|
1226
|
-
o[40] = x10 >>> 0 & 0xff;
|
|
1227
|
-
o[41] = x10 >>> 8 & 0xff;
|
|
1228
|
-
o[42] = x10 >>> 16 & 0xff;
|
|
1229
|
-
o[43] = x10 >>> 24 & 0xff;
|
|
1230
|
-
|
|
1231
|
-
o[44] = x11 >>> 0 & 0xff;
|
|
1232
|
-
o[45] = x11 >>> 8 & 0xff;
|
|
1233
|
-
o[46] = x11 >>> 16 & 0xff;
|
|
1234
|
-
o[47] = x11 >>> 24 & 0xff;
|
|
1235
|
-
|
|
1236
|
-
o[48] = x12 >>> 0 & 0xff;
|
|
1237
|
-
o[49] = x12 >>> 8 & 0xff;
|
|
1238
|
-
o[50] = x12 >>> 16 & 0xff;
|
|
1239
|
-
o[51] = x12 >>> 24 & 0xff;
|
|
1240
|
-
|
|
1241
|
-
o[52] = x13 >>> 0 & 0xff;
|
|
1242
|
-
o[53] = x13 >>> 8 & 0xff;
|
|
1243
|
-
o[54] = x13 >>> 16 & 0xff;
|
|
1244
|
-
o[55] = x13 >>> 24 & 0xff;
|
|
1245
|
-
|
|
1246
|
-
o[56] = x14 >>> 0 & 0xff;
|
|
1247
|
-
o[57] = x14 >>> 8 & 0xff;
|
|
1248
|
-
o[58] = x14 >>> 16 & 0xff;
|
|
1249
|
-
o[59] = x14 >>> 24 & 0xff;
|
|
1250
|
-
|
|
1251
|
-
o[60] = x15 >>> 0 & 0xff;
|
|
1252
|
-
o[61] = x15 >>> 8 & 0xff;
|
|
1253
|
-
o[62] = x15 >>> 16 & 0xff;
|
|
1254
|
-
o[63] = x15 >>> 24 & 0xff;
|
|
1255
|
-
}
|
|
1256
|
-
|
|
1257
|
-
function core_hsalsa20(o,p,k,c) {
|
|
1258
|
-
var j0 = c[ 0] & 0xff | (c[ 1] & 0xff)<<8 | (c[ 2] & 0xff)<<16 | (c[ 3] & 0xff)<<24,
|
|
1259
|
-
j1 = k[ 0] & 0xff | (k[ 1] & 0xff)<<8 | (k[ 2] & 0xff)<<16 | (k[ 3] & 0xff)<<24,
|
|
1260
|
-
j2 = k[ 4] & 0xff | (k[ 5] & 0xff)<<8 | (k[ 6] & 0xff)<<16 | (k[ 7] & 0xff)<<24,
|
|
1261
|
-
j3 = k[ 8] & 0xff | (k[ 9] & 0xff)<<8 | (k[10] & 0xff)<<16 | (k[11] & 0xff)<<24,
|
|
1262
|
-
j4 = k[12] & 0xff | (k[13] & 0xff)<<8 | (k[14] & 0xff)<<16 | (k[15] & 0xff)<<24,
|
|
1263
|
-
j5 = c[ 4] & 0xff | (c[ 5] & 0xff)<<8 | (c[ 6] & 0xff)<<16 | (c[ 7] & 0xff)<<24,
|
|
1264
|
-
j6 = p[ 0] & 0xff | (p[ 1] & 0xff)<<8 | (p[ 2] & 0xff)<<16 | (p[ 3] & 0xff)<<24,
|
|
1265
|
-
j7 = p[ 4] & 0xff | (p[ 5] & 0xff)<<8 | (p[ 6] & 0xff)<<16 | (p[ 7] & 0xff)<<24,
|
|
1266
|
-
j8 = p[ 8] & 0xff | (p[ 9] & 0xff)<<8 | (p[10] & 0xff)<<16 | (p[11] & 0xff)<<24,
|
|
1267
|
-
j9 = p[12] & 0xff | (p[13] & 0xff)<<8 | (p[14] & 0xff)<<16 | (p[15] & 0xff)<<24,
|
|
1268
|
-
j10 = c[ 8] & 0xff | (c[ 9] & 0xff)<<8 | (c[10] & 0xff)<<16 | (c[11] & 0xff)<<24,
|
|
1269
|
-
j11 = k[16] & 0xff | (k[17] & 0xff)<<8 | (k[18] & 0xff)<<16 | (k[19] & 0xff)<<24,
|
|
1270
|
-
j12 = k[20] & 0xff | (k[21] & 0xff)<<8 | (k[22] & 0xff)<<16 | (k[23] & 0xff)<<24,
|
|
1271
|
-
j13 = k[24] & 0xff | (k[25] & 0xff)<<8 | (k[26] & 0xff)<<16 | (k[27] & 0xff)<<24,
|
|
1272
|
-
j14 = k[28] & 0xff | (k[29] & 0xff)<<8 | (k[30] & 0xff)<<16 | (k[31] & 0xff)<<24,
|
|
1273
|
-
j15 = c[12] & 0xff | (c[13] & 0xff)<<8 | (c[14] & 0xff)<<16 | (c[15] & 0xff)<<24;
|
|
1274
|
-
|
|
1275
|
-
var x0 = j0, x1 = j1, x2 = j2, x3 = j3, x4 = j4, x5 = j5, x6 = j6, x7 = j7,
|
|
1276
|
-
x8 = j8, x9 = j9, x10 = j10, x11 = j11, x12 = j12, x13 = j13, x14 = j14,
|
|
1277
|
-
x15 = j15, u;
|
|
1278
|
-
|
|
1279
|
-
for (var i = 0; i < 20; i += 2) {
|
|
1280
|
-
u = x0 + x12 | 0;
|
|
1281
|
-
x4 ^= u<<7 | u>>>(32-7);
|
|
1282
|
-
u = x4 + x0 | 0;
|
|
1283
|
-
x8 ^= u<<9 | u>>>(32-9);
|
|
1284
|
-
u = x8 + x4 | 0;
|
|
1285
|
-
x12 ^= u<<13 | u>>>(32-13);
|
|
1286
|
-
u = x12 + x8 | 0;
|
|
1287
|
-
x0 ^= u<<18 | u>>>(32-18);
|
|
1288
|
-
|
|
1289
|
-
u = x5 + x1 | 0;
|
|
1290
|
-
x9 ^= u<<7 | u>>>(32-7);
|
|
1291
|
-
u = x9 + x5 | 0;
|
|
1292
|
-
x13 ^= u<<9 | u>>>(32-9);
|
|
1293
|
-
u = x13 + x9 | 0;
|
|
1294
|
-
x1 ^= u<<13 | u>>>(32-13);
|
|
1295
|
-
u = x1 + x13 | 0;
|
|
1296
|
-
x5 ^= u<<18 | u>>>(32-18);
|
|
1297
|
-
|
|
1298
|
-
u = x10 + x6 | 0;
|
|
1299
|
-
x14 ^= u<<7 | u>>>(32-7);
|
|
1300
|
-
u = x14 + x10 | 0;
|
|
1301
|
-
x2 ^= u<<9 | u>>>(32-9);
|
|
1302
|
-
u = x2 + x14 | 0;
|
|
1303
|
-
x6 ^= u<<13 | u>>>(32-13);
|
|
1304
|
-
u = x6 + x2 | 0;
|
|
1305
|
-
x10 ^= u<<18 | u>>>(32-18);
|
|
1306
|
-
|
|
1307
|
-
u = x15 + x11 | 0;
|
|
1308
|
-
x3 ^= u<<7 | u>>>(32-7);
|
|
1309
|
-
u = x3 + x15 | 0;
|
|
1310
|
-
x7 ^= u<<9 | u>>>(32-9);
|
|
1311
|
-
u = x7 + x3 | 0;
|
|
1312
|
-
x11 ^= u<<13 | u>>>(32-13);
|
|
1313
|
-
u = x11 + x7 | 0;
|
|
1314
|
-
x15 ^= u<<18 | u>>>(32-18);
|
|
1315
|
-
|
|
1316
|
-
u = x0 + x3 | 0;
|
|
1317
|
-
x1 ^= u<<7 | u>>>(32-7);
|
|
1318
|
-
u = x1 + x0 | 0;
|
|
1319
|
-
x2 ^= u<<9 | u>>>(32-9);
|
|
1320
|
-
u = x2 + x1 | 0;
|
|
1321
|
-
x3 ^= u<<13 | u>>>(32-13);
|
|
1322
|
-
u = x3 + x2 | 0;
|
|
1323
|
-
x0 ^= u<<18 | u>>>(32-18);
|
|
1324
|
-
|
|
1325
|
-
u = x5 + x4 | 0;
|
|
1326
|
-
x6 ^= u<<7 | u>>>(32-7);
|
|
1327
|
-
u = x6 + x5 | 0;
|
|
1328
|
-
x7 ^= u<<9 | u>>>(32-9);
|
|
1329
|
-
u = x7 + x6 | 0;
|
|
1330
|
-
x4 ^= u<<13 | u>>>(32-13);
|
|
1331
|
-
u = x4 + x7 | 0;
|
|
1332
|
-
x5 ^= u<<18 | u>>>(32-18);
|
|
1333
|
-
|
|
1334
|
-
u = x10 + x9 | 0;
|
|
1335
|
-
x11 ^= u<<7 | u>>>(32-7);
|
|
1336
|
-
u = x11 + x10 | 0;
|
|
1337
|
-
x8 ^= u<<9 | u>>>(32-9);
|
|
1338
|
-
u = x8 + x11 | 0;
|
|
1339
|
-
x9 ^= u<<13 | u>>>(32-13);
|
|
1340
|
-
u = x9 + x8 | 0;
|
|
1341
|
-
x10 ^= u<<18 | u>>>(32-18);
|
|
1342
|
-
|
|
1343
|
-
u = x15 + x14 | 0;
|
|
1344
|
-
x12 ^= u<<7 | u>>>(32-7);
|
|
1345
|
-
u = x12 + x15 | 0;
|
|
1346
|
-
x13 ^= u<<9 | u>>>(32-9);
|
|
1347
|
-
u = x13 + x12 | 0;
|
|
1348
|
-
x14 ^= u<<13 | u>>>(32-13);
|
|
1349
|
-
u = x14 + x13 | 0;
|
|
1350
|
-
x15 ^= u<<18 | u>>>(32-18);
|
|
1351
|
-
}
|
|
1352
|
-
|
|
1353
|
-
o[ 0] = x0 >>> 0 & 0xff;
|
|
1354
|
-
o[ 1] = x0 >>> 8 & 0xff;
|
|
1355
|
-
o[ 2] = x0 >>> 16 & 0xff;
|
|
1356
|
-
o[ 3] = x0 >>> 24 & 0xff;
|
|
1357
|
-
|
|
1358
|
-
o[ 4] = x5 >>> 0 & 0xff;
|
|
1359
|
-
o[ 5] = x5 >>> 8 & 0xff;
|
|
1360
|
-
o[ 6] = x5 >>> 16 & 0xff;
|
|
1361
|
-
o[ 7] = x5 >>> 24 & 0xff;
|
|
1362
|
-
|
|
1363
|
-
o[ 8] = x10 >>> 0 & 0xff;
|
|
1364
|
-
o[ 9] = x10 >>> 8 & 0xff;
|
|
1365
|
-
o[10] = x10 >>> 16 & 0xff;
|
|
1366
|
-
o[11] = x10 >>> 24 & 0xff;
|
|
1367
|
-
|
|
1368
|
-
o[12] = x15 >>> 0 & 0xff;
|
|
1369
|
-
o[13] = x15 >>> 8 & 0xff;
|
|
1370
|
-
o[14] = x15 >>> 16 & 0xff;
|
|
1371
|
-
o[15] = x15 >>> 24 & 0xff;
|
|
1372
|
-
|
|
1373
|
-
o[16] = x6 >>> 0 & 0xff;
|
|
1374
|
-
o[17] = x6 >>> 8 & 0xff;
|
|
1375
|
-
o[18] = x6 >>> 16 & 0xff;
|
|
1376
|
-
o[19] = x6 >>> 24 & 0xff;
|
|
1377
|
-
|
|
1378
|
-
o[20] = x7 >>> 0 & 0xff;
|
|
1379
|
-
o[21] = x7 >>> 8 & 0xff;
|
|
1380
|
-
o[22] = x7 >>> 16 & 0xff;
|
|
1381
|
-
o[23] = x7 >>> 24 & 0xff;
|
|
1382
|
-
|
|
1383
|
-
o[24] = x8 >>> 0 & 0xff;
|
|
1384
|
-
o[25] = x8 >>> 8 & 0xff;
|
|
1385
|
-
o[26] = x8 >>> 16 & 0xff;
|
|
1386
|
-
o[27] = x8 >>> 24 & 0xff;
|
|
1387
|
-
|
|
1388
|
-
o[28] = x9 >>> 0 & 0xff;
|
|
1389
|
-
o[29] = x9 >>> 8 & 0xff;
|
|
1390
|
-
o[30] = x9 >>> 16 & 0xff;
|
|
1391
|
-
o[31] = x9 >>> 24 & 0xff;
|
|
1392
|
-
}
|
|
1393
|
-
|
|
1394
|
-
function crypto_core_salsa20(out,inp,k,c) {
|
|
1395
|
-
core_salsa20(out,inp,k,c);
|
|
1396
|
-
}
|
|
1397
|
-
|
|
1398
|
-
function crypto_core_hsalsa20(out,inp,k,c) {
|
|
1399
|
-
core_hsalsa20(out,inp,k,c);
|
|
1400
|
-
}
|
|
1401
|
-
|
|
1402
|
-
var sigma = new Uint8Array([101, 120, 112, 97, 110, 100, 32, 51, 50, 45, 98, 121, 116, 101, 32, 107]);
|
|
1403
|
-
// "expand 32-byte k"
|
|
1404
|
-
|
|
1405
|
-
function crypto_stream_salsa20_xor(c,cpos,m,mpos,b,n,k) {
|
|
1406
|
-
var z = new Uint8Array(16), x = new Uint8Array(64);
|
|
1407
|
-
var u, i;
|
|
1408
|
-
for (i = 0; i < 16; i++) z[i] = 0;
|
|
1409
|
-
for (i = 0; i < 8; i++) z[i] = n[i];
|
|
1410
|
-
while (b >= 64) {
|
|
1411
|
-
crypto_core_salsa20(x,z,k,sigma);
|
|
1412
|
-
for (i = 0; i < 64; i++) c[cpos+i] = m[mpos+i] ^ x[i];
|
|
1413
|
-
u = 1;
|
|
1414
|
-
for (i = 8; i < 16; i++) {
|
|
1415
|
-
u = u + (z[i] & 0xff) | 0;
|
|
1416
|
-
z[i] = u & 0xff;
|
|
1417
|
-
u >>>= 8;
|
|
1418
|
-
}
|
|
1419
|
-
b -= 64;
|
|
1420
|
-
cpos += 64;
|
|
1421
|
-
mpos += 64;
|
|
1422
|
-
}
|
|
1423
|
-
if (b > 0) {
|
|
1424
|
-
crypto_core_salsa20(x,z,k,sigma);
|
|
1425
|
-
for (i = 0; i < b; i++) c[cpos+i] = m[mpos+i] ^ x[i];
|
|
1426
|
-
}
|
|
1427
|
-
return 0;
|
|
1428
|
-
}
|
|
1429
|
-
|
|
1430
|
-
function crypto_stream_salsa20(c,cpos,b,n,k) {
|
|
1431
|
-
var z = new Uint8Array(16), x = new Uint8Array(64);
|
|
1432
|
-
var u, i;
|
|
1433
|
-
for (i = 0; i < 16; i++) z[i] = 0;
|
|
1434
|
-
for (i = 0; i < 8; i++) z[i] = n[i];
|
|
1435
|
-
while (b >= 64) {
|
|
1436
|
-
crypto_core_salsa20(x,z,k,sigma);
|
|
1437
|
-
for (i = 0; i < 64; i++) c[cpos+i] = x[i];
|
|
1438
|
-
u = 1;
|
|
1439
|
-
for (i = 8; i < 16; i++) {
|
|
1440
|
-
u = u + (z[i] & 0xff) | 0;
|
|
1441
|
-
z[i] = u & 0xff;
|
|
1442
|
-
u >>>= 8;
|
|
1443
|
-
}
|
|
1444
|
-
b -= 64;
|
|
1445
|
-
cpos += 64;
|
|
1446
|
-
}
|
|
1447
|
-
if (b > 0) {
|
|
1448
|
-
crypto_core_salsa20(x,z,k,sigma);
|
|
1449
|
-
for (i = 0; i < b; i++) c[cpos+i] = x[i];
|
|
1450
|
-
}
|
|
1451
|
-
return 0;
|
|
1452
|
-
}
|
|
1453
|
-
|
|
1454
|
-
function crypto_stream(c,cpos,d,n,k) {
|
|
1455
|
-
var s = new Uint8Array(32);
|
|
1456
|
-
crypto_core_hsalsa20(s,n,k,sigma);
|
|
1457
|
-
var sn = new Uint8Array(8);
|
|
1458
|
-
for (var i = 0; i < 8; i++) sn[i] = n[i+16];
|
|
1459
|
-
return crypto_stream_salsa20(c,cpos,d,sn,s);
|
|
1460
|
-
}
|
|
1461
|
-
|
|
1462
|
-
function crypto_stream_xor(c,cpos,m,mpos,d,n,k) {
|
|
1463
|
-
var s = new Uint8Array(32);
|
|
1464
|
-
crypto_core_hsalsa20(s,n,k,sigma);
|
|
1465
|
-
var sn = new Uint8Array(8);
|
|
1466
|
-
for (var i = 0; i < 8; i++) sn[i] = n[i+16];
|
|
1467
|
-
return crypto_stream_salsa20_xor(c,cpos,m,mpos,d,sn,s);
|
|
1468
|
-
}
|
|
1469
|
-
|
|
1470
|
-
/*
|
|
1471
|
-
* Port of Andrew Moon's Poly1305-donna-16. Public domain.
|
|
1472
|
-
* https://github.com/floodyberry/poly1305-donna
|
|
1473
|
-
*/
|
|
1474
|
-
|
|
1475
|
-
var poly1305 = function(key) {
|
|
1476
|
-
this.buffer = new Uint8Array(16);
|
|
1477
|
-
this.r = new Uint16Array(10);
|
|
1478
|
-
this.h = new Uint16Array(10);
|
|
1479
|
-
this.pad = new Uint16Array(8);
|
|
1480
|
-
this.leftover = 0;
|
|
1481
|
-
this.fin = 0;
|
|
1482
|
-
|
|
1483
|
-
var t0, t1, t2, t3, t4, t5, t6, t7;
|
|
1484
|
-
|
|
1485
|
-
t0 = key[ 0] & 0xff | (key[ 1] & 0xff) << 8; this.r[0] = ( t0 ) & 0x1fff;
|
|
1486
|
-
t1 = key[ 2] & 0xff | (key[ 3] & 0xff) << 8; this.r[1] = ((t0 >>> 13) | (t1 << 3)) & 0x1fff;
|
|
1487
|
-
t2 = key[ 4] & 0xff | (key[ 5] & 0xff) << 8; this.r[2] = ((t1 >>> 10) | (t2 << 6)) & 0x1f03;
|
|
1488
|
-
t3 = key[ 6] & 0xff | (key[ 7] & 0xff) << 8; this.r[3] = ((t2 >>> 7) | (t3 << 9)) & 0x1fff;
|
|
1489
|
-
t4 = key[ 8] & 0xff | (key[ 9] & 0xff) << 8; this.r[4] = ((t3 >>> 4) | (t4 << 12)) & 0x00ff;
|
|
1490
|
-
this.r[5] = ((t4 >>> 1)) & 0x1ffe;
|
|
1491
|
-
t5 = key[10] & 0xff | (key[11] & 0xff) << 8; this.r[6] = ((t4 >>> 14) | (t5 << 2)) & 0x1fff;
|
|
1492
|
-
t6 = key[12] & 0xff | (key[13] & 0xff) << 8; this.r[7] = ((t5 >>> 11) | (t6 << 5)) & 0x1f81;
|
|
1493
|
-
t7 = key[14] & 0xff | (key[15] & 0xff) << 8; this.r[8] = ((t6 >>> 8) | (t7 << 8)) & 0x1fff;
|
|
1494
|
-
this.r[9] = ((t7 >>> 5)) & 0x007f;
|
|
1495
|
-
|
|
1496
|
-
this.pad[0] = key[16] & 0xff | (key[17] & 0xff) << 8;
|
|
1497
|
-
this.pad[1] = key[18] & 0xff | (key[19] & 0xff) << 8;
|
|
1498
|
-
this.pad[2] = key[20] & 0xff | (key[21] & 0xff) << 8;
|
|
1499
|
-
this.pad[3] = key[22] & 0xff | (key[23] & 0xff) << 8;
|
|
1500
|
-
this.pad[4] = key[24] & 0xff | (key[25] & 0xff) << 8;
|
|
1501
|
-
this.pad[5] = key[26] & 0xff | (key[27] & 0xff) << 8;
|
|
1502
|
-
this.pad[6] = key[28] & 0xff | (key[29] & 0xff) << 8;
|
|
1503
|
-
this.pad[7] = key[30] & 0xff | (key[31] & 0xff) << 8;
|
|
1504
|
-
};
|
|
1505
|
-
|
|
1506
|
-
poly1305.prototype.blocks = function(m, mpos, bytes) {
|
|
1507
|
-
var hibit = this.fin ? 0 : (1 << 11);
|
|
1508
|
-
var t0, t1, t2, t3, t4, t5, t6, t7, c;
|
|
1509
|
-
var d0, d1, d2, d3, d4, d5, d6, d7, d8, d9;
|
|
1510
|
-
|
|
1511
|
-
var h0 = this.h[0],
|
|
1512
|
-
h1 = this.h[1],
|
|
1513
|
-
h2 = this.h[2],
|
|
1514
|
-
h3 = this.h[3],
|
|
1515
|
-
h4 = this.h[4],
|
|
1516
|
-
h5 = this.h[5],
|
|
1517
|
-
h6 = this.h[6],
|
|
1518
|
-
h7 = this.h[7],
|
|
1519
|
-
h8 = this.h[8],
|
|
1520
|
-
h9 = this.h[9];
|
|
1521
|
-
|
|
1522
|
-
var r0 = this.r[0],
|
|
1523
|
-
r1 = this.r[1],
|
|
1524
|
-
r2 = this.r[2],
|
|
1525
|
-
r3 = this.r[3],
|
|
1526
|
-
r4 = this.r[4],
|
|
1527
|
-
r5 = this.r[5],
|
|
1528
|
-
r6 = this.r[6],
|
|
1529
|
-
r7 = this.r[7],
|
|
1530
|
-
r8 = this.r[8],
|
|
1531
|
-
r9 = this.r[9];
|
|
1532
|
-
|
|
1533
|
-
while (bytes >= 16) {
|
|
1534
|
-
t0 = m[mpos+ 0] & 0xff | (m[mpos+ 1] & 0xff) << 8; h0 += ( t0 ) & 0x1fff;
|
|
1535
|
-
t1 = m[mpos+ 2] & 0xff | (m[mpos+ 3] & 0xff) << 8; h1 += ((t0 >>> 13) | (t1 << 3)) & 0x1fff;
|
|
1536
|
-
t2 = m[mpos+ 4] & 0xff | (m[mpos+ 5] & 0xff) << 8; h2 += ((t1 >>> 10) | (t2 << 6)) & 0x1fff;
|
|
1537
|
-
t3 = m[mpos+ 6] & 0xff | (m[mpos+ 7] & 0xff) << 8; h3 += ((t2 >>> 7) | (t3 << 9)) & 0x1fff;
|
|
1538
|
-
t4 = m[mpos+ 8] & 0xff | (m[mpos+ 9] & 0xff) << 8; h4 += ((t3 >>> 4) | (t4 << 12)) & 0x1fff;
|
|
1539
|
-
h5 += ((t4 >>> 1)) & 0x1fff;
|
|
1540
|
-
t5 = m[mpos+10] & 0xff | (m[mpos+11] & 0xff) << 8; h6 += ((t4 >>> 14) | (t5 << 2)) & 0x1fff;
|
|
1541
|
-
t6 = m[mpos+12] & 0xff | (m[mpos+13] & 0xff) << 8; h7 += ((t5 >>> 11) | (t6 << 5)) & 0x1fff;
|
|
1542
|
-
t7 = m[mpos+14] & 0xff | (m[mpos+15] & 0xff) << 8; h8 += ((t6 >>> 8) | (t7 << 8)) & 0x1fff;
|
|
1543
|
-
h9 += ((t7 >>> 5)) | hibit;
|
|
1544
|
-
|
|
1545
|
-
c = 0;
|
|
1546
|
-
|
|
1547
|
-
d0 = c;
|
|
1548
|
-
d0 += h0 * r0;
|
|
1549
|
-
d0 += h1 * (5 * r9);
|
|
1550
|
-
d0 += h2 * (5 * r8);
|
|
1551
|
-
d0 += h3 * (5 * r7);
|
|
1552
|
-
d0 += h4 * (5 * r6);
|
|
1553
|
-
c = (d0 >>> 13); d0 &= 0x1fff;
|
|
1554
|
-
d0 += h5 * (5 * r5);
|
|
1555
|
-
d0 += h6 * (5 * r4);
|
|
1556
|
-
d0 += h7 * (5 * r3);
|
|
1557
|
-
d0 += h8 * (5 * r2);
|
|
1558
|
-
d0 += h9 * (5 * r1);
|
|
1559
|
-
c += (d0 >>> 13); d0 &= 0x1fff;
|
|
1560
|
-
|
|
1561
|
-
d1 = c;
|
|
1562
|
-
d1 += h0 * r1;
|
|
1563
|
-
d1 += h1 * r0;
|
|
1564
|
-
d1 += h2 * (5 * r9);
|
|
1565
|
-
d1 += h3 * (5 * r8);
|
|
1566
|
-
d1 += h4 * (5 * r7);
|
|
1567
|
-
c = (d1 >>> 13); d1 &= 0x1fff;
|
|
1568
|
-
d1 += h5 * (5 * r6);
|
|
1569
|
-
d1 += h6 * (5 * r5);
|
|
1570
|
-
d1 += h7 * (5 * r4);
|
|
1571
|
-
d1 += h8 * (5 * r3);
|
|
1572
|
-
d1 += h9 * (5 * r2);
|
|
1573
|
-
c += (d1 >>> 13); d1 &= 0x1fff;
|
|
1574
|
-
|
|
1575
|
-
d2 = c;
|
|
1576
|
-
d2 += h0 * r2;
|
|
1577
|
-
d2 += h1 * r1;
|
|
1578
|
-
d2 += h2 * r0;
|
|
1579
|
-
d2 += h3 * (5 * r9);
|
|
1580
|
-
d2 += h4 * (5 * r8);
|
|
1581
|
-
c = (d2 >>> 13); d2 &= 0x1fff;
|
|
1582
|
-
d2 += h5 * (5 * r7);
|
|
1583
|
-
d2 += h6 * (5 * r6);
|
|
1584
|
-
d2 += h7 * (5 * r5);
|
|
1585
|
-
d2 += h8 * (5 * r4);
|
|
1586
|
-
d2 += h9 * (5 * r3);
|
|
1587
|
-
c += (d2 >>> 13); d2 &= 0x1fff;
|
|
1588
|
-
|
|
1589
|
-
d3 = c;
|
|
1590
|
-
d3 += h0 * r3;
|
|
1591
|
-
d3 += h1 * r2;
|
|
1592
|
-
d3 += h2 * r1;
|
|
1593
|
-
d3 += h3 * r0;
|
|
1594
|
-
d3 += h4 * (5 * r9);
|
|
1595
|
-
c = (d3 >>> 13); d3 &= 0x1fff;
|
|
1596
|
-
d3 += h5 * (5 * r8);
|
|
1597
|
-
d3 += h6 * (5 * r7);
|
|
1598
|
-
d3 += h7 * (5 * r6);
|
|
1599
|
-
d3 += h8 * (5 * r5);
|
|
1600
|
-
d3 += h9 * (5 * r4);
|
|
1601
|
-
c += (d3 >>> 13); d3 &= 0x1fff;
|
|
1602
|
-
|
|
1603
|
-
d4 = c;
|
|
1604
|
-
d4 += h0 * r4;
|
|
1605
|
-
d4 += h1 * r3;
|
|
1606
|
-
d4 += h2 * r2;
|
|
1607
|
-
d4 += h3 * r1;
|
|
1608
|
-
d4 += h4 * r0;
|
|
1609
|
-
c = (d4 >>> 13); d4 &= 0x1fff;
|
|
1610
|
-
d4 += h5 * (5 * r9);
|
|
1611
|
-
d4 += h6 * (5 * r8);
|
|
1612
|
-
d4 += h7 * (5 * r7);
|
|
1613
|
-
d4 += h8 * (5 * r6);
|
|
1614
|
-
d4 += h9 * (5 * r5);
|
|
1615
|
-
c += (d4 >>> 13); d4 &= 0x1fff;
|
|
1616
|
-
|
|
1617
|
-
d5 = c;
|
|
1618
|
-
d5 += h0 * r5;
|
|
1619
|
-
d5 += h1 * r4;
|
|
1620
|
-
d5 += h2 * r3;
|
|
1621
|
-
d5 += h3 * r2;
|
|
1622
|
-
d5 += h4 * r1;
|
|
1623
|
-
c = (d5 >>> 13); d5 &= 0x1fff;
|
|
1624
|
-
d5 += h5 * r0;
|
|
1625
|
-
d5 += h6 * (5 * r9);
|
|
1626
|
-
d5 += h7 * (5 * r8);
|
|
1627
|
-
d5 += h8 * (5 * r7);
|
|
1628
|
-
d5 += h9 * (5 * r6);
|
|
1629
|
-
c += (d5 >>> 13); d5 &= 0x1fff;
|
|
1630
|
-
|
|
1631
|
-
d6 = c;
|
|
1632
|
-
d6 += h0 * r6;
|
|
1633
|
-
d6 += h1 * r5;
|
|
1634
|
-
d6 += h2 * r4;
|
|
1635
|
-
d6 += h3 * r3;
|
|
1636
|
-
d6 += h4 * r2;
|
|
1637
|
-
c = (d6 >>> 13); d6 &= 0x1fff;
|
|
1638
|
-
d6 += h5 * r1;
|
|
1639
|
-
d6 += h6 * r0;
|
|
1640
|
-
d6 += h7 * (5 * r9);
|
|
1641
|
-
d6 += h8 * (5 * r8);
|
|
1642
|
-
d6 += h9 * (5 * r7);
|
|
1643
|
-
c += (d6 >>> 13); d6 &= 0x1fff;
|
|
1644
|
-
|
|
1645
|
-
d7 = c;
|
|
1646
|
-
d7 += h0 * r7;
|
|
1647
|
-
d7 += h1 * r6;
|
|
1648
|
-
d7 += h2 * r5;
|
|
1649
|
-
d7 += h3 * r4;
|
|
1650
|
-
d7 += h4 * r3;
|
|
1651
|
-
c = (d7 >>> 13); d7 &= 0x1fff;
|
|
1652
|
-
d7 += h5 * r2;
|
|
1653
|
-
d7 += h6 * r1;
|
|
1654
|
-
d7 += h7 * r0;
|
|
1655
|
-
d7 += h8 * (5 * r9);
|
|
1656
|
-
d7 += h9 * (5 * r8);
|
|
1657
|
-
c += (d7 >>> 13); d7 &= 0x1fff;
|
|
1658
|
-
|
|
1659
|
-
d8 = c;
|
|
1660
|
-
d8 += h0 * r8;
|
|
1661
|
-
d8 += h1 * r7;
|
|
1662
|
-
d8 += h2 * r6;
|
|
1663
|
-
d8 += h3 * r5;
|
|
1664
|
-
d8 += h4 * r4;
|
|
1665
|
-
c = (d8 >>> 13); d8 &= 0x1fff;
|
|
1666
|
-
d8 += h5 * r3;
|
|
1667
|
-
d8 += h6 * r2;
|
|
1668
|
-
d8 += h7 * r1;
|
|
1669
|
-
d8 += h8 * r0;
|
|
1670
|
-
d8 += h9 * (5 * r9);
|
|
1671
|
-
c += (d8 >>> 13); d8 &= 0x1fff;
|
|
1672
|
-
|
|
1673
|
-
d9 = c;
|
|
1674
|
-
d9 += h0 * r9;
|
|
1675
|
-
d9 += h1 * r8;
|
|
1676
|
-
d9 += h2 * r7;
|
|
1677
|
-
d9 += h3 * r6;
|
|
1678
|
-
d9 += h4 * r5;
|
|
1679
|
-
c = (d9 >>> 13); d9 &= 0x1fff;
|
|
1680
|
-
d9 += h5 * r4;
|
|
1681
|
-
d9 += h6 * r3;
|
|
1682
|
-
d9 += h7 * r2;
|
|
1683
|
-
d9 += h8 * r1;
|
|
1684
|
-
d9 += h9 * r0;
|
|
1685
|
-
c += (d9 >>> 13); d9 &= 0x1fff;
|
|
1686
|
-
|
|
1687
|
-
c = (((c << 2) + c)) | 0;
|
|
1688
|
-
c = (c + d0) | 0;
|
|
1689
|
-
d0 = c & 0x1fff;
|
|
1690
|
-
c = (c >>> 13);
|
|
1691
|
-
d1 += c;
|
|
1692
|
-
|
|
1693
|
-
h0 = d0;
|
|
1694
|
-
h1 = d1;
|
|
1695
|
-
h2 = d2;
|
|
1696
|
-
h3 = d3;
|
|
1697
|
-
h4 = d4;
|
|
1698
|
-
h5 = d5;
|
|
1699
|
-
h6 = d6;
|
|
1700
|
-
h7 = d7;
|
|
1701
|
-
h8 = d8;
|
|
1702
|
-
h9 = d9;
|
|
1703
|
-
|
|
1704
|
-
mpos += 16;
|
|
1705
|
-
bytes -= 16;
|
|
1706
|
-
}
|
|
1707
|
-
this.h[0] = h0;
|
|
1708
|
-
this.h[1] = h1;
|
|
1709
|
-
this.h[2] = h2;
|
|
1710
|
-
this.h[3] = h3;
|
|
1711
|
-
this.h[4] = h4;
|
|
1712
|
-
this.h[5] = h5;
|
|
1713
|
-
this.h[6] = h6;
|
|
1714
|
-
this.h[7] = h7;
|
|
1715
|
-
this.h[8] = h8;
|
|
1716
|
-
this.h[9] = h9;
|
|
1717
|
-
};
|
|
1718
|
-
|
|
1719
|
-
poly1305.prototype.finish = function(mac, macpos) {
|
|
1720
|
-
var g = new Uint16Array(10);
|
|
1721
|
-
var c, mask, f, i;
|
|
1722
|
-
|
|
1723
|
-
if (this.leftover) {
|
|
1724
|
-
i = this.leftover;
|
|
1725
|
-
this.buffer[i++] = 1;
|
|
1726
|
-
for (; i < 16; i++) this.buffer[i] = 0;
|
|
1727
|
-
this.fin = 1;
|
|
1728
|
-
this.blocks(this.buffer, 0, 16);
|
|
1729
|
-
}
|
|
1730
|
-
|
|
1731
|
-
c = this.h[1] >>> 13;
|
|
1732
|
-
this.h[1] &= 0x1fff;
|
|
1733
|
-
for (i = 2; i < 10; i++) {
|
|
1734
|
-
this.h[i] += c;
|
|
1735
|
-
c = this.h[i] >>> 13;
|
|
1736
|
-
this.h[i] &= 0x1fff;
|
|
1737
|
-
}
|
|
1738
|
-
this.h[0] += (c * 5);
|
|
1739
|
-
c = this.h[0] >>> 13;
|
|
1740
|
-
this.h[0] &= 0x1fff;
|
|
1741
|
-
this.h[1] += c;
|
|
1742
|
-
c = this.h[1] >>> 13;
|
|
1743
|
-
this.h[1] &= 0x1fff;
|
|
1744
|
-
this.h[2] += c;
|
|
1745
|
-
|
|
1746
|
-
g[0] = this.h[0] + 5;
|
|
1747
|
-
c = g[0] >>> 13;
|
|
1748
|
-
g[0] &= 0x1fff;
|
|
1749
|
-
for (i = 1; i < 10; i++) {
|
|
1750
|
-
g[i] = this.h[i] + c;
|
|
1751
|
-
c = g[i] >>> 13;
|
|
1752
|
-
g[i] &= 0x1fff;
|
|
1753
|
-
}
|
|
1754
|
-
g[9] -= (1 << 13);
|
|
1755
|
-
|
|
1756
|
-
mask = (c ^ 1) - 1;
|
|
1757
|
-
for (i = 0; i < 10; i++) g[i] &= mask;
|
|
1758
|
-
mask = ~mask;
|
|
1759
|
-
for (i = 0; i < 10; i++) this.h[i] = (this.h[i] & mask) | g[i];
|
|
1760
|
-
|
|
1761
|
-
this.h[0] = ((this.h[0] ) | (this.h[1] << 13) ) & 0xffff;
|
|
1762
|
-
this.h[1] = ((this.h[1] >>> 3) | (this.h[2] << 10) ) & 0xffff;
|
|
1763
|
-
this.h[2] = ((this.h[2] >>> 6) | (this.h[3] << 7) ) & 0xffff;
|
|
1764
|
-
this.h[3] = ((this.h[3] >>> 9) | (this.h[4] << 4) ) & 0xffff;
|
|
1765
|
-
this.h[4] = ((this.h[4] >>> 12) | (this.h[5] << 1) | (this.h[6] << 14)) & 0xffff;
|
|
1766
|
-
this.h[5] = ((this.h[6] >>> 2) | (this.h[7] << 11) ) & 0xffff;
|
|
1767
|
-
this.h[6] = ((this.h[7] >>> 5) | (this.h[8] << 8) ) & 0xffff;
|
|
1768
|
-
this.h[7] = ((this.h[8] >>> 8) | (this.h[9] << 5) ) & 0xffff;
|
|
1769
|
-
|
|
1770
|
-
f = this.h[0] + this.pad[0];
|
|
1771
|
-
this.h[0] = f & 0xffff;
|
|
1772
|
-
for (i = 1; i < 8; i++) {
|
|
1773
|
-
f = (((this.h[i] + this.pad[i]) | 0) + (f >>> 16)) | 0;
|
|
1774
|
-
this.h[i] = f & 0xffff;
|
|
1775
|
-
}
|
|
1776
|
-
|
|
1777
|
-
mac[macpos+ 0] = (this.h[0] >>> 0) & 0xff;
|
|
1778
|
-
mac[macpos+ 1] = (this.h[0] >>> 8) & 0xff;
|
|
1779
|
-
mac[macpos+ 2] = (this.h[1] >>> 0) & 0xff;
|
|
1780
|
-
mac[macpos+ 3] = (this.h[1] >>> 8) & 0xff;
|
|
1781
|
-
mac[macpos+ 4] = (this.h[2] >>> 0) & 0xff;
|
|
1782
|
-
mac[macpos+ 5] = (this.h[2] >>> 8) & 0xff;
|
|
1783
|
-
mac[macpos+ 6] = (this.h[3] >>> 0) & 0xff;
|
|
1784
|
-
mac[macpos+ 7] = (this.h[3] >>> 8) & 0xff;
|
|
1785
|
-
mac[macpos+ 8] = (this.h[4] >>> 0) & 0xff;
|
|
1786
|
-
mac[macpos+ 9] = (this.h[4] >>> 8) & 0xff;
|
|
1787
|
-
mac[macpos+10] = (this.h[5] >>> 0) & 0xff;
|
|
1788
|
-
mac[macpos+11] = (this.h[5] >>> 8) & 0xff;
|
|
1789
|
-
mac[macpos+12] = (this.h[6] >>> 0) & 0xff;
|
|
1790
|
-
mac[macpos+13] = (this.h[6] >>> 8) & 0xff;
|
|
1791
|
-
mac[macpos+14] = (this.h[7] >>> 0) & 0xff;
|
|
1792
|
-
mac[macpos+15] = (this.h[7] >>> 8) & 0xff;
|
|
1793
|
-
};
|
|
1794
|
-
|
|
1795
|
-
poly1305.prototype.update = function(m, mpos, bytes) {
|
|
1796
|
-
var i, want;
|
|
1797
|
-
|
|
1798
|
-
if (this.leftover) {
|
|
1799
|
-
want = (16 - this.leftover);
|
|
1800
|
-
if (want > bytes)
|
|
1801
|
-
want = bytes;
|
|
1802
|
-
for (i = 0; i < want; i++)
|
|
1803
|
-
this.buffer[this.leftover + i] = m[mpos+i];
|
|
1804
|
-
bytes -= want;
|
|
1805
|
-
mpos += want;
|
|
1806
|
-
this.leftover += want;
|
|
1807
|
-
if (this.leftover < 16)
|
|
1808
|
-
return;
|
|
1809
|
-
this.blocks(this.buffer, 0, 16);
|
|
1810
|
-
this.leftover = 0;
|
|
1811
|
-
}
|
|
1812
|
-
|
|
1813
|
-
if (bytes >= 16) {
|
|
1814
|
-
want = bytes - (bytes % 16);
|
|
1815
|
-
this.blocks(m, mpos, want);
|
|
1816
|
-
mpos += want;
|
|
1817
|
-
bytes -= want;
|
|
1818
|
-
}
|
|
1819
|
-
|
|
1820
|
-
if (bytes) {
|
|
1821
|
-
for (i = 0; i < bytes; i++)
|
|
1822
|
-
this.buffer[this.leftover + i] = m[mpos+i];
|
|
1823
|
-
this.leftover += bytes;
|
|
1824
|
-
}
|
|
1825
|
-
};
|
|
1826
|
-
|
|
1827
|
-
function crypto_onetimeauth(out, outpos, m, mpos, n, k) {
|
|
1828
|
-
var s = new poly1305(k);
|
|
1829
|
-
s.update(m, mpos, n);
|
|
1830
|
-
s.finish(out, outpos);
|
|
1831
|
-
return 0;
|
|
1832
|
-
}
|
|
1833
|
-
|
|
1834
|
-
function crypto_onetimeauth_verify(h, hpos, m, mpos, n, k) {
|
|
1835
|
-
var x = new Uint8Array(16);
|
|
1836
|
-
crypto_onetimeauth(x,0,m,mpos,n,k);
|
|
1837
|
-
return crypto_verify_16(h,hpos,x,0);
|
|
1838
|
-
}
|
|
1839
|
-
|
|
1840
|
-
function crypto_secretbox(c,m,d,n,k) {
|
|
1841
|
-
var i;
|
|
1842
|
-
if (d < 32) return -1;
|
|
1843
|
-
crypto_stream_xor(c,0,m,0,d,n,k);
|
|
1844
|
-
crypto_onetimeauth(c, 16, c, 32, d - 32, c);
|
|
1845
|
-
for (i = 0; i < 16; i++) c[i] = 0;
|
|
1846
|
-
return 0;
|
|
1847
|
-
}
|
|
1848
|
-
|
|
1849
|
-
function crypto_secretbox_open(m,c,d,n,k) {
|
|
1850
|
-
var i;
|
|
1851
|
-
var x = new Uint8Array(32);
|
|
1852
|
-
if (d < 32) return -1;
|
|
1853
|
-
crypto_stream(x,0,32,n,k);
|
|
1854
|
-
if (crypto_onetimeauth_verify(c, 16,c, 32,d - 32,x) !== 0) return -1;
|
|
1855
|
-
crypto_stream_xor(m,0,c,0,d,n,k);
|
|
1856
|
-
for (i = 0; i < 32; i++) m[i] = 0;
|
|
1857
|
-
return 0;
|
|
1858
|
-
}
|
|
1859
|
-
|
|
1860
|
-
function set25519(r, a) {
|
|
1861
|
-
var i;
|
|
1862
|
-
for (i = 0; i < 16; i++) r[i] = a[i]|0;
|
|
1863
|
-
}
|
|
1864
|
-
|
|
1865
|
-
function car25519(o) {
|
|
1866
|
-
var i, v, c = 1;
|
|
1867
|
-
for (i = 0; i < 16; i++) {
|
|
1868
|
-
v = o[i] + c + 65535;
|
|
1869
|
-
c = Math.floor(v / 65536);
|
|
1870
|
-
o[i] = v - c * 65536;
|
|
1871
|
-
}
|
|
1872
|
-
o[0] += c-1 + 37 * (c-1);
|
|
1873
|
-
}
|
|
1874
|
-
|
|
1875
|
-
function sel25519(p, q, b) {
|
|
1876
|
-
var t, c = ~(b-1);
|
|
1877
|
-
for (var i = 0; i < 16; i++) {
|
|
1878
|
-
t = c & (p[i] ^ q[i]);
|
|
1879
|
-
p[i] ^= t;
|
|
1880
|
-
q[i] ^= t;
|
|
1881
|
-
}
|
|
1882
|
-
}
|
|
1883
|
-
|
|
1884
|
-
function pack25519(o, n) {
|
|
1885
|
-
var i, j, b;
|
|
1886
|
-
var m = gf(), t = gf();
|
|
1887
|
-
for (i = 0; i < 16; i++) t[i] = n[i];
|
|
1888
|
-
car25519(t);
|
|
1889
|
-
car25519(t);
|
|
1890
|
-
car25519(t);
|
|
1891
|
-
for (j = 0; j < 2; j++) {
|
|
1892
|
-
m[0] = t[0] - 0xffed;
|
|
1893
|
-
for (i = 1; i < 15; i++) {
|
|
1894
|
-
m[i] = t[i] - 0xffff - ((m[i-1]>>16) & 1);
|
|
1895
|
-
m[i-1] &= 0xffff;
|
|
1896
|
-
}
|
|
1897
|
-
m[15] = t[15] - 0x7fff - ((m[14]>>16) & 1);
|
|
1898
|
-
b = (m[15]>>16) & 1;
|
|
1899
|
-
m[14] &= 0xffff;
|
|
1900
|
-
sel25519(t, m, 1-b);
|
|
1901
|
-
}
|
|
1902
|
-
for (i = 0; i < 16; i++) {
|
|
1903
|
-
o[2*i] = t[i] & 0xff;
|
|
1904
|
-
o[2*i+1] = t[i]>>8;
|
|
1905
|
-
}
|
|
1906
|
-
}
|
|
1907
|
-
|
|
1908
|
-
function neq25519(a, b) {
|
|
1909
|
-
var c = new Uint8Array(32), d = new Uint8Array(32);
|
|
1910
|
-
pack25519(c, a);
|
|
1911
|
-
pack25519(d, b);
|
|
1912
|
-
return crypto_verify_32(c, 0, d, 0);
|
|
1913
|
-
}
|
|
1914
|
-
|
|
1915
|
-
function par25519(a) {
|
|
1916
|
-
var d = new Uint8Array(32);
|
|
1917
|
-
pack25519(d, a);
|
|
1918
|
-
return d[0] & 1;
|
|
1919
|
-
}
|
|
1920
|
-
|
|
1921
|
-
function unpack25519(o, n) {
|
|
1922
|
-
var i;
|
|
1923
|
-
for (i = 0; i < 16; i++) o[i] = n[2*i] + (n[2*i+1] << 8);
|
|
1924
|
-
o[15] &= 0x7fff;
|
|
1925
|
-
}
|
|
1926
|
-
|
|
1927
|
-
function A(o, a, b) {
|
|
1928
|
-
for (var i = 0; i < 16; i++) o[i] = a[i] + b[i];
|
|
1929
|
-
}
|
|
1930
|
-
|
|
1931
|
-
function Z(o, a, b) {
|
|
1932
|
-
for (var i = 0; i < 16; i++) o[i] = a[i] - b[i];
|
|
1933
|
-
}
|
|
1934
|
-
|
|
1935
|
-
function M(o, a, b) {
|
|
1936
|
-
var v, c,
|
|
1937
|
-
t0 = 0, t1 = 0, t2 = 0, t3 = 0, t4 = 0, t5 = 0, t6 = 0, t7 = 0,
|
|
1938
|
-
t8 = 0, t9 = 0, t10 = 0, t11 = 0, t12 = 0, t13 = 0, t14 = 0, t15 = 0,
|
|
1939
|
-
t16 = 0, t17 = 0, t18 = 0, t19 = 0, t20 = 0, t21 = 0, t22 = 0, t23 = 0,
|
|
1940
|
-
t24 = 0, t25 = 0, t26 = 0, t27 = 0, t28 = 0, t29 = 0, t30 = 0,
|
|
1941
|
-
b0 = b[0],
|
|
1942
|
-
b1 = b[1],
|
|
1943
|
-
b2 = b[2],
|
|
1944
|
-
b3 = b[3],
|
|
1945
|
-
b4 = b[4],
|
|
1946
|
-
b5 = b[5],
|
|
1947
|
-
b6 = b[6],
|
|
1948
|
-
b7 = b[7],
|
|
1949
|
-
b8 = b[8],
|
|
1950
|
-
b9 = b[9],
|
|
1951
|
-
b10 = b[10],
|
|
1952
|
-
b11 = b[11],
|
|
1953
|
-
b12 = b[12],
|
|
1954
|
-
b13 = b[13],
|
|
1955
|
-
b14 = b[14],
|
|
1956
|
-
b15 = b[15];
|
|
1957
|
-
|
|
1958
|
-
v = a[0];
|
|
1959
|
-
t0 += v * b0;
|
|
1960
|
-
t1 += v * b1;
|
|
1961
|
-
t2 += v * b2;
|
|
1962
|
-
t3 += v * b3;
|
|
1963
|
-
t4 += v * b4;
|
|
1964
|
-
t5 += v * b5;
|
|
1965
|
-
t6 += v * b6;
|
|
1966
|
-
t7 += v * b7;
|
|
1967
|
-
t8 += v * b8;
|
|
1968
|
-
t9 += v * b9;
|
|
1969
|
-
t10 += v * b10;
|
|
1970
|
-
t11 += v * b11;
|
|
1971
|
-
t12 += v * b12;
|
|
1972
|
-
t13 += v * b13;
|
|
1973
|
-
t14 += v * b14;
|
|
1974
|
-
t15 += v * b15;
|
|
1975
|
-
v = a[1];
|
|
1976
|
-
t1 += v * b0;
|
|
1977
|
-
t2 += v * b1;
|
|
1978
|
-
t3 += v * b2;
|
|
1979
|
-
t4 += v * b3;
|
|
1980
|
-
t5 += v * b4;
|
|
1981
|
-
t6 += v * b5;
|
|
1982
|
-
t7 += v * b6;
|
|
1983
|
-
t8 += v * b7;
|
|
1984
|
-
t9 += v * b8;
|
|
1985
|
-
t10 += v * b9;
|
|
1986
|
-
t11 += v * b10;
|
|
1987
|
-
t12 += v * b11;
|
|
1988
|
-
t13 += v * b12;
|
|
1989
|
-
t14 += v * b13;
|
|
1990
|
-
t15 += v * b14;
|
|
1991
|
-
t16 += v * b15;
|
|
1992
|
-
v = a[2];
|
|
1993
|
-
t2 += v * b0;
|
|
1994
|
-
t3 += v * b1;
|
|
1995
|
-
t4 += v * b2;
|
|
1996
|
-
t5 += v * b3;
|
|
1997
|
-
t6 += v * b4;
|
|
1998
|
-
t7 += v * b5;
|
|
1999
|
-
t8 += v * b6;
|
|
2000
|
-
t9 += v * b7;
|
|
2001
|
-
t10 += v * b8;
|
|
2002
|
-
t11 += v * b9;
|
|
2003
|
-
t12 += v * b10;
|
|
2004
|
-
t13 += v * b11;
|
|
2005
|
-
t14 += v * b12;
|
|
2006
|
-
t15 += v * b13;
|
|
2007
|
-
t16 += v * b14;
|
|
2008
|
-
t17 += v * b15;
|
|
2009
|
-
v = a[3];
|
|
2010
|
-
t3 += v * b0;
|
|
2011
|
-
t4 += v * b1;
|
|
2012
|
-
t5 += v * b2;
|
|
2013
|
-
t6 += v * b3;
|
|
2014
|
-
t7 += v * b4;
|
|
2015
|
-
t8 += v * b5;
|
|
2016
|
-
t9 += v * b6;
|
|
2017
|
-
t10 += v * b7;
|
|
2018
|
-
t11 += v * b8;
|
|
2019
|
-
t12 += v * b9;
|
|
2020
|
-
t13 += v * b10;
|
|
2021
|
-
t14 += v * b11;
|
|
2022
|
-
t15 += v * b12;
|
|
2023
|
-
t16 += v * b13;
|
|
2024
|
-
t17 += v * b14;
|
|
2025
|
-
t18 += v * b15;
|
|
2026
|
-
v = a[4];
|
|
2027
|
-
t4 += v * b0;
|
|
2028
|
-
t5 += v * b1;
|
|
2029
|
-
t6 += v * b2;
|
|
2030
|
-
t7 += v * b3;
|
|
2031
|
-
t8 += v * b4;
|
|
2032
|
-
t9 += v * b5;
|
|
2033
|
-
t10 += v * b6;
|
|
2034
|
-
t11 += v * b7;
|
|
2035
|
-
t12 += v * b8;
|
|
2036
|
-
t13 += v * b9;
|
|
2037
|
-
t14 += v * b10;
|
|
2038
|
-
t15 += v * b11;
|
|
2039
|
-
t16 += v * b12;
|
|
2040
|
-
t17 += v * b13;
|
|
2041
|
-
t18 += v * b14;
|
|
2042
|
-
t19 += v * b15;
|
|
2043
|
-
v = a[5];
|
|
2044
|
-
t5 += v * b0;
|
|
2045
|
-
t6 += v * b1;
|
|
2046
|
-
t7 += v * b2;
|
|
2047
|
-
t8 += v * b3;
|
|
2048
|
-
t9 += v * b4;
|
|
2049
|
-
t10 += v * b5;
|
|
2050
|
-
t11 += v * b6;
|
|
2051
|
-
t12 += v * b7;
|
|
2052
|
-
t13 += v * b8;
|
|
2053
|
-
t14 += v * b9;
|
|
2054
|
-
t15 += v * b10;
|
|
2055
|
-
t16 += v * b11;
|
|
2056
|
-
t17 += v * b12;
|
|
2057
|
-
t18 += v * b13;
|
|
2058
|
-
t19 += v * b14;
|
|
2059
|
-
t20 += v * b15;
|
|
2060
|
-
v = a[6];
|
|
2061
|
-
t6 += v * b0;
|
|
2062
|
-
t7 += v * b1;
|
|
2063
|
-
t8 += v * b2;
|
|
2064
|
-
t9 += v * b3;
|
|
2065
|
-
t10 += v * b4;
|
|
2066
|
-
t11 += v * b5;
|
|
2067
|
-
t12 += v * b6;
|
|
2068
|
-
t13 += v * b7;
|
|
2069
|
-
t14 += v * b8;
|
|
2070
|
-
t15 += v * b9;
|
|
2071
|
-
t16 += v * b10;
|
|
2072
|
-
t17 += v * b11;
|
|
2073
|
-
t18 += v * b12;
|
|
2074
|
-
t19 += v * b13;
|
|
2075
|
-
t20 += v * b14;
|
|
2076
|
-
t21 += v * b15;
|
|
2077
|
-
v = a[7];
|
|
2078
|
-
t7 += v * b0;
|
|
2079
|
-
t8 += v * b1;
|
|
2080
|
-
t9 += v * b2;
|
|
2081
|
-
t10 += v * b3;
|
|
2082
|
-
t11 += v * b4;
|
|
2083
|
-
t12 += v * b5;
|
|
2084
|
-
t13 += v * b6;
|
|
2085
|
-
t14 += v * b7;
|
|
2086
|
-
t15 += v * b8;
|
|
2087
|
-
t16 += v * b9;
|
|
2088
|
-
t17 += v * b10;
|
|
2089
|
-
t18 += v * b11;
|
|
2090
|
-
t19 += v * b12;
|
|
2091
|
-
t20 += v * b13;
|
|
2092
|
-
t21 += v * b14;
|
|
2093
|
-
t22 += v * b15;
|
|
2094
|
-
v = a[8];
|
|
2095
|
-
t8 += v * b0;
|
|
2096
|
-
t9 += v * b1;
|
|
2097
|
-
t10 += v * b2;
|
|
2098
|
-
t11 += v * b3;
|
|
2099
|
-
t12 += v * b4;
|
|
2100
|
-
t13 += v * b5;
|
|
2101
|
-
t14 += v * b6;
|
|
2102
|
-
t15 += v * b7;
|
|
2103
|
-
t16 += v * b8;
|
|
2104
|
-
t17 += v * b9;
|
|
2105
|
-
t18 += v * b10;
|
|
2106
|
-
t19 += v * b11;
|
|
2107
|
-
t20 += v * b12;
|
|
2108
|
-
t21 += v * b13;
|
|
2109
|
-
t22 += v * b14;
|
|
2110
|
-
t23 += v * b15;
|
|
2111
|
-
v = a[9];
|
|
2112
|
-
t9 += v * b0;
|
|
2113
|
-
t10 += v * b1;
|
|
2114
|
-
t11 += v * b2;
|
|
2115
|
-
t12 += v * b3;
|
|
2116
|
-
t13 += v * b4;
|
|
2117
|
-
t14 += v * b5;
|
|
2118
|
-
t15 += v * b6;
|
|
2119
|
-
t16 += v * b7;
|
|
2120
|
-
t17 += v * b8;
|
|
2121
|
-
t18 += v * b9;
|
|
2122
|
-
t19 += v * b10;
|
|
2123
|
-
t20 += v * b11;
|
|
2124
|
-
t21 += v * b12;
|
|
2125
|
-
t22 += v * b13;
|
|
2126
|
-
t23 += v * b14;
|
|
2127
|
-
t24 += v * b15;
|
|
2128
|
-
v = a[10];
|
|
2129
|
-
t10 += v * b0;
|
|
2130
|
-
t11 += v * b1;
|
|
2131
|
-
t12 += v * b2;
|
|
2132
|
-
t13 += v * b3;
|
|
2133
|
-
t14 += v * b4;
|
|
2134
|
-
t15 += v * b5;
|
|
2135
|
-
t16 += v * b6;
|
|
2136
|
-
t17 += v * b7;
|
|
2137
|
-
t18 += v * b8;
|
|
2138
|
-
t19 += v * b9;
|
|
2139
|
-
t20 += v * b10;
|
|
2140
|
-
t21 += v * b11;
|
|
2141
|
-
t22 += v * b12;
|
|
2142
|
-
t23 += v * b13;
|
|
2143
|
-
t24 += v * b14;
|
|
2144
|
-
t25 += v * b15;
|
|
2145
|
-
v = a[11];
|
|
2146
|
-
t11 += v * b0;
|
|
2147
|
-
t12 += v * b1;
|
|
2148
|
-
t13 += v * b2;
|
|
2149
|
-
t14 += v * b3;
|
|
2150
|
-
t15 += v * b4;
|
|
2151
|
-
t16 += v * b5;
|
|
2152
|
-
t17 += v * b6;
|
|
2153
|
-
t18 += v * b7;
|
|
2154
|
-
t19 += v * b8;
|
|
2155
|
-
t20 += v * b9;
|
|
2156
|
-
t21 += v * b10;
|
|
2157
|
-
t22 += v * b11;
|
|
2158
|
-
t23 += v * b12;
|
|
2159
|
-
t24 += v * b13;
|
|
2160
|
-
t25 += v * b14;
|
|
2161
|
-
t26 += v * b15;
|
|
2162
|
-
v = a[12];
|
|
2163
|
-
t12 += v * b0;
|
|
2164
|
-
t13 += v * b1;
|
|
2165
|
-
t14 += v * b2;
|
|
2166
|
-
t15 += v * b3;
|
|
2167
|
-
t16 += v * b4;
|
|
2168
|
-
t17 += v * b5;
|
|
2169
|
-
t18 += v * b6;
|
|
2170
|
-
t19 += v * b7;
|
|
2171
|
-
t20 += v * b8;
|
|
2172
|
-
t21 += v * b9;
|
|
2173
|
-
t22 += v * b10;
|
|
2174
|
-
t23 += v * b11;
|
|
2175
|
-
t24 += v * b12;
|
|
2176
|
-
t25 += v * b13;
|
|
2177
|
-
t26 += v * b14;
|
|
2178
|
-
t27 += v * b15;
|
|
2179
|
-
v = a[13];
|
|
2180
|
-
t13 += v * b0;
|
|
2181
|
-
t14 += v * b1;
|
|
2182
|
-
t15 += v * b2;
|
|
2183
|
-
t16 += v * b3;
|
|
2184
|
-
t17 += v * b4;
|
|
2185
|
-
t18 += v * b5;
|
|
2186
|
-
t19 += v * b6;
|
|
2187
|
-
t20 += v * b7;
|
|
2188
|
-
t21 += v * b8;
|
|
2189
|
-
t22 += v * b9;
|
|
2190
|
-
t23 += v * b10;
|
|
2191
|
-
t24 += v * b11;
|
|
2192
|
-
t25 += v * b12;
|
|
2193
|
-
t26 += v * b13;
|
|
2194
|
-
t27 += v * b14;
|
|
2195
|
-
t28 += v * b15;
|
|
2196
|
-
v = a[14];
|
|
2197
|
-
t14 += v * b0;
|
|
2198
|
-
t15 += v * b1;
|
|
2199
|
-
t16 += v * b2;
|
|
2200
|
-
t17 += v * b3;
|
|
2201
|
-
t18 += v * b4;
|
|
2202
|
-
t19 += v * b5;
|
|
2203
|
-
t20 += v * b6;
|
|
2204
|
-
t21 += v * b7;
|
|
2205
|
-
t22 += v * b8;
|
|
2206
|
-
t23 += v * b9;
|
|
2207
|
-
t24 += v * b10;
|
|
2208
|
-
t25 += v * b11;
|
|
2209
|
-
t26 += v * b12;
|
|
2210
|
-
t27 += v * b13;
|
|
2211
|
-
t28 += v * b14;
|
|
2212
|
-
t29 += v * b15;
|
|
2213
|
-
v = a[15];
|
|
2214
|
-
t15 += v * b0;
|
|
2215
|
-
t16 += v * b1;
|
|
2216
|
-
t17 += v * b2;
|
|
2217
|
-
t18 += v * b3;
|
|
2218
|
-
t19 += v * b4;
|
|
2219
|
-
t20 += v * b5;
|
|
2220
|
-
t21 += v * b6;
|
|
2221
|
-
t22 += v * b7;
|
|
2222
|
-
t23 += v * b8;
|
|
2223
|
-
t24 += v * b9;
|
|
2224
|
-
t25 += v * b10;
|
|
2225
|
-
t26 += v * b11;
|
|
2226
|
-
t27 += v * b12;
|
|
2227
|
-
t28 += v * b13;
|
|
2228
|
-
t29 += v * b14;
|
|
2229
|
-
t30 += v * b15;
|
|
2230
|
-
|
|
2231
|
-
t0 += 38 * t16;
|
|
2232
|
-
t1 += 38 * t17;
|
|
2233
|
-
t2 += 38 * t18;
|
|
2234
|
-
t3 += 38 * t19;
|
|
2235
|
-
t4 += 38 * t20;
|
|
2236
|
-
t5 += 38 * t21;
|
|
2237
|
-
t6 += 38 * t22;
|
|
2238
|
-
t7 += 38 * t23;
|
|
2239
|
-
t8 += 38 * t24;
|
|
2240
|
-
t9 += 38 * t25;
|
|
2241
|
-
t10 += 38 * t26;
|
|
2242
|
-
t11 += 38 * t27;
|
|
2243
|
-
t12 += 38 * t28;
|
|
2244
|
-
t13 += 38 * t29;
|
|
2245
|
-
t14 += 38 * t30;
|
|
2246
|
-
// t15 left as is
|
|
2247
|
-
|
|
2248
|
-
// first car
|
|
2249
|
-
c = 1;
|
|
2250
|
-
v = t0 + c + 65535; c = Math.floor(v / 65536); t0 = v - c * 65536;
|
|
2251
|
-
v = t1 + c + 65535; c = Math.floor(v / 65536); t1 = v - c * 65536;
|
|
2252
|
-
v = t2 + c + 65535; c = Math.floor(v / 65536); t2 = v - c * 65536;
|
|
2253
|
-
v = t3 + c + 65535; c = Math.floor(v / 65536); t3 = v - c * 65536;
|
|
2254
|
-
v = t4 + c + 65535; c = Math.floor(v / 65536); t4 = v - c * 65536;
|
|
2255
|
-
v = t5 + c + 65535; c = Math.floor(v / 65536); t5 = v - c * 65536;
|
|
2256
|
-
v = t6 + c + 65535; c = Math.floor(v / 65536); t6 = v - c * 65536;
|
|
2257
|
-
v = t7 + c + 65535; c = Math.floor(v / 65536); t7 = v - c * 65536;
|
|
2258
|
-
v = t8 + c + 65535; c = Math.floor(v / 65536); t8 = v - c * 65536;
|
|
2259
|
-
v = t9 + c + 65535; c = Math.floor(v / 65536); t9 = v - c * 65536;
|
|
2260
|
-
v = t10 + c + 65535; c = Math.floor(v / 65536); t10 = v - c * 65536;
|
|
2261
|
-
v = t11 + c + 65535; c = Math.floor(v / 65536); t11 = v - c * 65536;
|
|
2262
|
-
v = t12 + c + 65535; c = Math.floor(v / 65536); t12 = v - c * 65536;
|
|
2263
|
-
v = t13 + c + 65535; c = Math.floor(v / 65536); t13 = v - c * 65536;
|
|
2264
|
-
v = t14 + c + 65535; c = Math.floor(v / 65536); t14 = v - c * 65536;
|
|
2265
|
-
v = t15 + c + 65535; c = Math.floor(v / 65536); t15 = v - c * 65536;
|
|
2266
|
-
t0 += c-1 + 37 * (c-1);
|
|
2267
|
-
|
|
2268
|
-
// second car
|
|
2269
|
-
c = 1;
|
|
2270
|
-
v = t0 + c + 65535; c = Math.floor(v / 65536); t0 = v - c * 65536;
|
|
2271
|
-
v = t1 + c + 65535; c = Math.floor(v / 65536); t1 = v - c * 65536;
|
|
2272
|
-
v = t2 + c + 65535; c = Math.floor(v / 65536); t2 = v - c * 65536;
|
|
2273
|
-
v = t3 + c + 65535; c = Math.floor(v / 65536); t3 = v - c * 65536;
|
|
2274
|
-
v = t4 + c + 65535; c = Math.floor(v / 65536); t4 = v - c * 65536;
|
|
2275
|
-
v = t5 + c + 65535; c = Math.floor(v / 65536); t5 = v - c * 65536;
|
|
2276
|
-
v = t6 + c + 65535; c = Math.floor(v / 65536); t6 = v - c * 65536;
|
|
2277
|
-
v = t7 + c + 65535; c = Math.floor(v / 65536); t7 = v - c * 65536;
|
|
2278
|
-
v = t8 + c + 65535; c = Math.floor(v / 65536); t8 = v - c * 65536;
|
|
2279
|
-
v = t9 + c + 65535; c = Math.floor(v / 65536); t9 = v - c * 65536;
|
|
2280
|
-
v = t10 + c + 65535; c = Math.floor(v / 65536); t10 = v - c * 65536;
|
|
2281
|
-
v = t11 + c + 65535; c = Math.floor(v / 65536); t11 = v - c * 65536;
|
|
2282
|
-
v = t12 + c + 65535; c = Math.floor(v / 65536); t12 = v - c * 65536;
|
|
2283
|
-
v = t13 + c + 65535; c = Math.floor(v / 65536); t13 = v - c * 65536;
|
|
2284
|
-
v = t14 + c + 65535; c = Math.floor(v / 65536); t14 = v - c * 65536;
|
|
2285
|
-
v = t15 + c + 65535; c = Math.floor(v / 65536); t15 = v - c * 65536;
|
|
2286
|
-
t0 += c-1 + 37 * (c-1);
|
|
2287
|
-
|
|
2288
|
-
o[ 0] = t0;
|
|
2289
|
-
o[ 1] = t1;
|
|
2290
|
-
o[ 2] = t2;
|
|
2291
|
-
o[ 3] = t3;
|
|
2292
|
-
o[ 4] = t4;
|
|
2293
|
-
o[ 5] = t5;
|
|
2294
|
-
o[ 6] = t6;
|
|
2295
|
-
o[ 7] = t7;
|
|
2296
|
-
o[ 8] = t8;
|
|
2297
|
-
o[ 9] = t9;
|
|
2298
|
-
o[10] = t10;
|
|
2299
|
-
o[11] = t11;
|
|
2300
|
-
o[12] = t12;
|
|
2301
|
-
o[13] = t13;
|
|
2302
|
-
o[14] = t14;
|
|
2303
|
-
o[15] = t15;
|
|
2304
|
-
}
|
|
2305
|
-
|
|
2306
|
-
function S(o, a) {
|
|
2307
|
-
M(o, a, a);
|
|
2308
|
-
}
|
|
2309
|
-
|
|
2310
|
-
function inv25519(o, i) {
|
|
2311
|
-
var c = gf();
|
|
2312
|
-
var a;
|
|
2313
|
-
for (a = 0; a < 16; a++) c[a] = i[a];
|
|
2314
|
-
for (a = 253; a >= 0; a--) {
|
|
2315
|
-
S(c, c);
|
|
2316
|
-
if(a !== 2 && a !== 4) M(c, c, i);
|
|
2317
|
-
}
|
|
2318
|
-
for (a = 0; a < 16; a++) o[a] = c[a];
|
|
2319
|
-
}
|
|
2320
|
-
|
|
2321
|
-
function pow2523(o, i) {
|
|
2322
|
-
var c = gf();
|
|
2323
|
-
var a;
|
|
2324
|
-
for (a = 0; a < 16; a++) c[a] = i[a];
|
|
2325
|
-
for (a = 250; a >= 0; a--) {
|
|
2326
|
-
S(c, c);
|
|
2327
|
-
if(a !== 1) M(c, c, i);
|
|
2328
|
-
}
|
|
2329
|
-
for (a = 0; a < 16; a++) o[a] = c[a];
|
|
2330
|
-
}
|
|
2331
|
-
|
|
2332
|
-
function crypto_scalarmult(q, n, p) {
|
|
2333
|
-
var z = new Uint8Array(32);
|
|
2334
|
-
var x = new Float64Array(80), r, i;
|
|
2335
|
-
var a = gf(), b = gf(), c = gf(),
|
|
2336
|
-
d = gf(), e = gf(), f = gf();
|
|
2337
|
-
for (i = 0; i < 31; i++) z[i] = n[i];
|
|
2338
|
-
z[31]=(n[31]&127)|64;
|
|
2339
|
-
z[0]&=248;
|
|
2340
|
-
unpack25519(x,p);
|
|
2341
|
-
for (i = 0; i < 16; i++) {
|
|
2342
|
-
b[i]=x[i];
|
|
2343
|
-
d[i]=a[i]=c[i]=0;
|
|
2344
|
-
}
|
|
2345
|
-
a[0]=d[0]=1;
|
|
2346
|
-
for (i=254; i>=0; --i) {
|
|
2347
|
-
r=(z[i>>>3]>>>(i&7))&1;
|
|
2348
|
-
sel25519(a,b,r);
|
|
2349
|
-
sel25519(c,d,r);
|
|
2350
|
-
A(e,a,c);
|
|
2351
|
-
Z(a,a,c);
|
|
2352
|
-
A(c,b,d);
|
|
2353
|
-
Z(b,b,d);
|
|
2354
|
-
S(d,e);
|
|
2355
|
-
S(f,a);
|
|
2356
|
-
M(a,c,a);
|
|
2357
|
-
M(c,b,e);
|
|
2358
|
-
A(e,a,c);
|
|
2359
|
-
Z(a,a,c);
|
|
2360
|
-
S(b,a);
|
|
2361
|
-
Z(c,d,f);
|
|
2362
|
-
M(a,c,_121665);
|
|
2363
|
-
A(a,a,d);
|
|
2364
|
-
M(c,c,a);
|
|
2365
|
-
M(a,d,f);
|
|
2366
|
-
M(d,b,x);
|
|
2367
|
-
S(b,e);
|
|
2368
|
-
sel25519(a,b,r);
|
|
2369
|
-
sel25519(c,d,r);
|
|
2370
|
-
}
|
|
2371
|
-
for (i = 0; i < 16; i++) {
|
|
2372
|
-
x[i+16]=a[i];
|
|
2373
|
-
x[i+32]=c[i];
|
|
2374
|
-
x[i+48]=b[i];
|
|
2375
|
-
x[i+64]=d[i];
|
|
2376
|
-
}
|
|
2377
|
-
var x32 = x.subarray(32);
|
|
2378
|
-
var x16 = x.subarray(16);
|
|
2379
|
-
inv25519(x32,x32);
|
|
2380
|
-
M(x16,x16,x32);
|
|
2381
|
-
pack25519(q,x16);
|
|
2382
|
-
return 0;
|
|
2383
|
-
}
|
|
2384
|
-
|
|
2385
|
-
function crypto_scalarmult_base(q, n) {
|
|
2386
|
-
return crypto_scalarmult(q, n, _9);
|
|
2387
|
-
}
|
|
2388
|
-
|
|
2389
|
-
function crypto_box_keypair(y, x) {
|
|
2390
|
-
randombytes(x, 32);
|
|
2391
|
-
return crypto_scalarmult_base(y, x);
|
|
2392
|
-
}
|
|
2393
|
-
|
|
2394
|
-
function crypto_box_beforenm(k, y, x) {
|
|
2395
|
-
var s = new Uint8Array(32);
|
|
2396
|
-
crypto_scalarmult(s, x, y);
|
|
2397
|
-
return crypto_core_hsalsa20(k, _0, s, sigma);
|
|
2398
|
-
}
|
|
2399
|
-
|
|
2400
|
-
var crypto_box_afternm = crypto_secretbox;
|
|
2401
|
-
var crypto_box_open_afternm = crypto_secretbox_open;
|
|
2402
|
-
|
|
2403
|
-
function crypto_box(c, m, d, n, y, x) {
|
|
2404
|
-
var k = new Uint8Array(32);
|
|
2405
|
-
crypto_box_beforenm(k, y, x);
|
|
2406
|
-
return crypto_box_afternm(c, m, d, n, k);
|
|
2407
|
-
}
|
|
2408
|
-
|
|
2409
|
-
function crypto_box_open(m, c, d, n, y, x) {
|
|
2410
|
-
var k = new Uint8Array(32);
|
|
2411
|
-
crypto_box_beforenm(k, y, x);
|
|
2412
|
-
return crypto_box_open_afternm(m, c, d, n, k);
|
|
2413
|
-
}
|
|
2414
|
-
|
|
2415
|
-
var K = [
|
|
2416
|
-
0x428a2f98, 0xd728ae22, 0x71374491, 0x23ef65cd,
|
|
2417
|
-
0xb5c0fbcf, 0xec4d3b2f, 0xe9b5dba5, 0x8189dbbc,
|
|
2418
|
-
0x3956c25b, 0xf348b538, 0x59f111f1, 0xb605d019,
|
|
2419
|
-
0x923f82a4, 0xaf194f9b, 0xab1c5ed5, 0xda6d8118,
|
|
2420
|
-
0xd807aa98, 0xa3030242, 0x12835b01, 0x45706fbe,
|
|
2421
|
-
0x243185be, 0x4ee4b28c, 0x550c7dc3, 0xd5ffb4e2,
|
|
2422
|
-
0x72be5d74, 0xf27b896f, 0x80deb1fe, 0x3b1696b1,
|
|
2423
|
-
0x9bdc06a7, 0x25c71235, 0xc19bf174, 0xcf692694,
|
|
2424
|
-
0xe49b69c1, 0x9ef14ad2, 0xefbe4786, 0x384f25e3,
|
|
2425
|
-
0x0fc19dc6, 0x8b8cd5b5, 0x240ca1cc, 0x77ac9c65,
|
|
2426
|
-
0x2de92c6f, 0x592b0275, 0x4a7484aa, 0x6ea6e483,
|
|
2427
|
-
0x5cb0a9dc, 0xbd41fbd4, 0x76f988da, 0x831153b5,
|
|
2428
|
-
0x983e5152, 0xee66dfab, 0xa831c66d, 0x2db43210,
|
|
2429
|
-
0xb00327c8, 0x98fb213f, 0xbf597fc7, 0xbeef0ee4,
|
|
2430
|
-
0xc6e00bf3, 0x3da88fc2, 0xd5a79147, 0x930aa725,
|
|
2431
|
-
0x06ca6351, 0xe003826f, 0x14292967, 0x0a0e6e70,
|
|
2432
|
-
0x27b70a85, 0x46d22ffc, 0x2e1b2138, 0x5c26c926,
|
|
2433
|
-
0x4d2c6dfc, 0x5ac42aed, 0x53380d13, 0x9d95b3df,
|
|
2434
|
-
0x650a7354, 0x8baf63de, 0x766a0abb, 0x3c77b2a8,
|
|
2435
|
-
0x81c2c92e, 0x47edaee6, 0x92722c85, 0x1482353b,
|
|
2436
|
-
0xa2bfe8a1, 0x4cf10364, 0xa81a664b, 0xbc423001,
|
|
2437
|
-
0xc24b8b70, 0xd0f89791, 0xc76c51a3, 0x0654be30,
|
|
2438
|
-
0xd192e819, 0xd6ef5218, 0xd6990624, 0x5565a910,
|
|
2439
|
-
0xf40e3585, 0x5771202a, 0x106aa070, 0x32bbd1b8,
|
|
2440
|
-
0x19a4c116, 0xb8d2d0c8, 0x1e376c08, 0x5141ab53,
|
|
2441
|
-
0x2748774c, 0xdf8eeb99, 0x34b0bcb5, 0xe19b48a8,
|
|
2442
|
-
0x391c0cb3, 0xc5c95a63, 0x4ed8aa4a, 0xe3418acb,
|
|
2443
|
-
0x5b9cca4f, 0x7763e373, 0x682e6ff3, 0xd6b2b8a3,
|
|
2444
|
-
0x748f82ee, 0x5defb2fc, 0x78a5636f, 0x43172f60,
|
|
2445
|
-
0x84c87814, 0xa1f0ab72, 0x8cc70208, 0x1a6439ec,
|
|
2446
|
-
0x90befffa, 0x23631e28, 0xa4506ceb, 0xde82bde9,
|
|
2447
|
-
0xbef9a3f7, 0xb2c67915, 0xc67178f2, 0xe372532b,
|
|
2448
|
-
0xca273ece, 0xea26619c, 0xd186b8c7, 0x21c0c207,
|
|
2449
|
-
0xeada7dd6, 0xcde0eb1e, 0xf57d4f7f, 0xee6ed178,
|
|
2450
|
-
0x06f067aa, 0x72176fba, 0x0a637dc5, 0xa2c898a6,
|
|
2451
|
-
0x113f9804, 0xbef90dae, 0x1b710b35, 0x131c471b,
|
|
2452
|
-
0x28db77f5, 0x23047d84, 0x32caab7b, 0x40c72493,
|
|
2453
|
-
0x3c9ebe0a, 0x15c9bebc, 0x431d67c4, 0x9c100d4c,
|
|
2454
|
-
0x4cc5d4be, 0xcb3e42b6, 0x597f299c, 0xfc657e2a,
|
|
2455
|
-
0x5fcb6fab, 0x3ad6faec, 0x6c44198c, 0x4a475817
|
|
2456
|
-
];
|
|
2457
|
-
|
|
2458
|
-
function crypto_hashblocks_hl(hh, hl, m, n) {
|
|
2459
|
-
var wh = new Int32Array(16), wl = new Int32Array(16),
|
|
2460
|
-
bh0, bh1, bh2, bh3, bh4, bh5, bh6, bh7,
|
|
2461
|
-
bl0, bl1, bl2, bl3, bl4, bl5, bl6, bl7,
|
|
2462
|
-
th, tl, i, j, h, l, a, b, c, d;
|
|
2463
|
-
|
|
2464
|
-
var ah0 = hh[0],
|
|
2465
|
-
ah1 = hh[1],
|
|
2466
|
-
ah2 = hh[2],
|
|
2467
|
-
ah3 = hh[3],
|
|
2468
|
-
ah4 = hh[4],
|
|
2469
|
-
ah5 = hh[5],
|
|
2470
|
-
ah6 = hh[6],
|
|
2471
|
-
ah7 = hh[7],
|
|
2472
|
-
|
|
2473
|
-
al0 = hl[0],
|
|
2474
|
-
al1 = hl[1],
|
|
2475
|
-
al2 = hl[2],
|
|
2476
|
-
al3 = hl[3],
|
|
2477
|
-
al4 = hl[4],
|
|
2478
|
-
al5 = hl[5],
|
|
2479
|
-
al6 = hl[6],
|
|
2480
|
-
al7 = hl[7];
|
|
2481
|
-
|
|
2482
|
-
var pos = 0;
|
|
2483
|
-
while (n >= 128) {
|
|
2484
|
-
for (i = 0; i < 16; i++) {
|
|
2485
|
-
j = 8 * i + pos;
|
|
2486
|
-
wh[i] = (m[j+0] << 24) | (m[j+1] << 16) | (m[j+2] << 8) | m[j+3];
|
|
2487
|
-
wl[i] = (m[j+4] << 24) | (m[j+5] << 16) | (m[j+6] << 8) | m[j+7];
|
|
2488
|
-
}
|
|
2489
|
-
for (i = 0; i < 80; i++) {
|
|
2490
|
-
bh0 = ah0;
|
|
2491
|
-
bh1 = ah1;
|
|
2492
|
-
bh2 = ah2;
|
|
2493
|
-
bh3 = ah3;
|
|
2494
|
-
bh4 = ah4;
|
|
2495
|
-
bh5 = ah5;
|
|
2496
|
-
bh6 = ah6;
|
|
2497
|
-
bh7 = ah7;
|
|
2498
|
-
|
|
2499
|
-
bl0 = al0;
|
|
2500
|
-
bl1 = al1;
|
|
2501
|
-
bl2 = al2;
|
|
2502
|
-
bl3 = al3;
|
|
2503
|
-
bl4 = al4;
|
|
2504
|
-
bl5 = al5;
|
|
2505
|
-
bl6 = al6;
|
|
2506
|
-
bl7 = al7;
|
|
2507
|
-
|
|
2508
|
-
// add
|
|
2509
|
-
h = ah7;
|
|
2510
|
-
l = al7;
|
|
2511
|
-
|
|
2512
|
-
a = l & 0xffff; b = l >>> 16;
|
|
2513
|
-
c = h & 0xffff; d = h >>> 16;
|
|
2514
|
-
|
|
2515
|
-
// Sigma1
|
|
2516
|
-
h = ((ah4 >>> 14) | (al4 << (32-14))) ^ ((ah4 >>> 18) | (al4 << (32-18))) ^ ((al4 >>> (41-32)) | (ah4 << (32-(41-32))));
|
|
2517
|
-
l = ((al4 >>> 14) | (ah4 << (32-14))) ^ ((al4 >>> 18) | (ah4 << (32-18))) ^ ((ah4 >>> (41-32)) | (al4 << (32-(41-32))));
|
|
2518
|
-
|
|
2519
|
-
a += l & 0xffff; b += l >>> 16;
|
|
2520
|
-
c += h & 0xffff; d += h >>> 16;
|
|
2521
|
-
|
|
2522
|
-
// Ch
|
|
2523
|
-
h = (ah4 & ah5) ^ (~ah4 & ah6);
|
|
2524
|
-
l = (al4 & al5) ^ (~al4 & al6);
|
|
2525
|
-
|
|
2526
|
-
a += l & 0xffff; b += l >>> 16;
|
|
2527
|
-
c += h & 0xffff; d += h >>> 16;
|
|
2528
|
-
|
|
2529
|
-
// K
|
|
2530
|
-
h = K[i*2];
|
|
2531
|
-
l = K[i*2+1];
|
|
2532
|
-
|
|
2533
|
-
a += l & 0xffff; b += l >>> 16;
|
|
2534
|
-
c += h & 0xffff; d += h >>> 16;
|
|
2535
|
-
|
|
2536
|
-
// w
|
|
2537
|
-
h = wh[i%16];
|
|
2538
|
-
l = wl[i%16];
|
|
2539
|
-
|
|
2540
|
-
a += l & 0xffff; b += l >>> 16;
|
|
2541
|
-
c += h & 0xffff; d += h >>> 16;
|
|
2542
|
-
|
|
2543
|
-
b += a >>> 16;
|
|
2544
|
-
c += b >>> 16;
|
|
2545
|
-
d += c >>> 16;
|
|
2546
|
-
|
|
2547
|
-
th = c & 0xffff | d << 16;
|
|
2548
|
-
tl = a & 0xffff | b << 16;
|
|
2549
|
-
|
|
2550
|
-
// add
|
|
2551
|
-
h = th;
|
|
2552
|
-
l = tl;
|
|
2553
|
-
|
|
2554
|
-
a = l & 0xffff; b = l >>> 16;
|
|
2555
|
-
c = h & 0xffff; d = h >>> 16;
|
|
2556
|
-
|
|
2557
|
-
// Sigma0
|
|
2558
|
-
h = ((ah0 >>> 28) | (al0 << (32-28))) ^ ((al0 >>> (34-32)) | (ah0 << (32-(34-32)))) ^ ((al0 >>> (39-32)) | (ah0 << (32-(39-32))));
|
|
2559
|
-
l = ((al0 >>> 28) | (ah0 << (32-28))) ^ ((ah0 >>> (34-32)) | (al0 << (32-(34-32)))) ^ ((ah0 >>> (39-32)) | (al0 << (32-(39-32))));
|
|
2560
|
-
|
|
2561
|
-
a += l & 0xffff; b += l >>> 16;
|
|
2562
|
-
c += h & 0xffff; d += h >>> 16;
|
|
2563
|
-
|
|
2564
|
-
// Maj
|
|
2565
|
-
h = (ah0 & ah1) ^ (ah0 & ah2) ^ (ah1 & ah2);
|
|
2566
|
-
l = (al0 & al1) ^ (al0 & al2) ^ (al1 & al2);
|
|
2567
|
-
|
|
2568
|
-
a += l & 0xffff; b += l >>> 16;
|
|
2569
|
-
c += h & 0xffff; d += h >>> 16;
|
|
2570
|
-
|
|
2571
|
-
b += a >>> 16;
|
|
2572
|
-
c += b >>> 16;
|
|
2573
|
-
d += c >>> 16;
|
|
2574
|
-
|
|
2575
|
-
bh7 = (c & 0xffff) | (d << 16);
|
|
2576
|
-
bl7 = (a & 0xffff) | (b << 16);
|
|
2577
|
-
|
|
2578
|
-
// add
|
|
2579
|
-
h = bh3;
|
|
2580
|
-
l = bl3;
|
|
2581
|
-
|
|
2582
|
-
a = l & 0xffff; b = l >>> 16;
|
|
2583
|
-
c = h & 0xffff; d = h >>> 16;
|
|
2584
|
-
|
|
2585
|
-
h = th;
|
|
2586
|
-
l = tl;
|
|
2587
|
-
|
|
2588
|
-
a += l & 0xffff; b += l >>> 16;
|
|
2589
|
-
c += h & 0xffff; d += h >>> 16;
|
|
2590
|
-
|
|
2591
|
-
b += a >>> 16;
|
|
2592
|
-
c += b >>> 16;
|
|
2593
|
-
d += c >>> 16;
|
|
2594
|
-
|
|
2595
|
-
bh3 = (c & 0xffff) | (d << 16);
|
|
2596
|
-
bl3 = (a & 0xffff) | (b << 16);
|
|
2597
|
-
|
|
2598
|
-
ah1 = bh0;
|
|
2599
|
-
ah2 = bh1;
|
|
2600
|
-
ah3 = bh2;
|
|
2601
|
-
ah4 = bh3;
|
|
2602
|
-
ah5 = bh4;
|
|
2603
|
-
ah6 = bh5;
|
|
2604
|
-
ah7 = bh6;
|
|
2605
|
-
ah0 = bh7;
|
|
2606
|
-
|
|
2607
|
-
al1 = bl0;
|
|
2608
|
-
al2 = bl1;
|
|
2609
|
-
al3 = bl2;
|
|
2610
|
-
al4 = bl3;
|
|
2611
|
-
al5 = bl4;
|
|
2612
|
-
al6 = bl5;
|
|
2613
|
-
al7 = bl6;
|
|
2614
|
-
al0 = bl7;
|
|
2615
|
-
|
|
2616
|
-
if (i%16 === 15) {
|
|
2617
|
-
for (j = 0; j < 16; j++) {
|
|
2618
|
-
// add
|
|
2619
|
-
h = wh[j];
|
|
2620
|
-
l = wl[j];
|
|
2621
|
-
|
|
2622
|
-
a = l & 0xffff; b = l >>> 16;
|
|
2623
|
-
c = h & 0xffff; d = h >>> 16;
|
|
2624
|
-
|
|
2625
|
-
h = wh[(j+9)%16];
|
|
2626
|
-
l = wl[(j+9)%16];
|
|
2627
|
-
|
|
2628
|
-
a += l & 0xffff; b += l >>> 16;
|
|
2629
|
-
c += h & 0xffff; d += h >>> 16;
|
|
2630
|
-
|
|
2631
|
-
// sigma0
|
|
2632
|
-
th = wh[(j+1)%16];
|
|
2633
|
-
tl = wl[(j+1)%16];
|
|
2634
|
-
h = ((th >>> 1) | (tl << (32-1))) ^ ((th >>> 8) | (tl << (32-8))) ^ (th >>> 7);
|
|
2635
|
-
l = ((tl >>> 1) | (th << (32-1))) ^ ((tl >>> 8) | (th << (32-8))) ^ ((tl >>> 7) | (th << (32-7)));
|
|
2636
|
-
|
|
2637
|
-
a += l & 0xffff; b += l >>> 16;
|
|
2638
|
-
c += h & 0xffff; d += h >>> 16;
|
|
2639
|
-
|
|
2640
|
-
// sigma1
|
|
2641
|
-
th = wh[(j+14)%16];
|
|
2642
|
-
tl = wl[(j+14)%16];
|
|
2643
|
-
h = ((th >>> 19) | (tl << (32-19))) ^ ((tl >>> (61-32)) | (th << (32-(61-32)))) ^ (th >>> 6);
|
|
2644
|
-
l = ((tl >>> 19) | (th << (32-19))) ^ ((th >>> (61-32)) | (tl << (32-(61-32)))) ^ ((tl >>> 6) | (th << (32-6)));
|
|
2645
|
-
|
|
2646
|
-
a += l & 0xffff; b += l >>> 16;
|
|
2647
|
-
c += h & 0xffff; d += h >>> 16;
|
|
2648
|
-
|
|
2649
|
-
b += a >>> 16;
|
|
2650
|
-
c += b >>> 16;
|
|
2651
|
-
d += c >>> 16;
|
|
2652
|
-
|
|
2653
|
-
wh[j] = (c & 0xffff) | (d << 16);
|
|
2654
|
-
wl[j] = (a & 0xffff) | (b << 16);
|
|
2655
|
-
}
|
|
2656
|
-
}
|
|
2657
|
-
}
|
|
2658
|
-
|
|
2659
|
-
// add
|
|
2660
|
-
h = ah0;
|
|
2661
|
-
l = al0;
|
|
2662
|
-
|
|
2663
|
-
a = l & 0xffff; b = l >>> 16;
|
|
2664
|
-
c = h & 0xffff; d = h >>> 16;
|
|
2665
|
-
|
|
2666
|
-
h = hh[0];
|
|
2667
|
-
l = hl[0];
|
|
2668
|
-
|
|
2669
|
-
a += l & 0xffff; b += l >>> 16;
|
|
2670
|
-
c += h & 0xffff; d += h >>> 16;
|
|
2671
|
-
|
|
2672
|
-
b += a >>> 16;
|
|
2673
|
-
c += b >>> 16;
|
|
2674
|
-
d += c >>> 16;
|
|
2675
|
-
|
|
2676
|
-
hh[0] = ah0 = (c & 0xffff) | (d << 16);
|
|
2677
|
-
hl[0] = al0 = (a & 0xffff) | (b << 16);
|
|
2678
|
-
|
|
2679
|
-
h = ah1;
|
|
2680
|
-
l = al1;
|
|
2681
|
-
|
|
2682
|
-
a = l & 0xffff; b = l >>> 16;
|
|
2683
|
-
c = h & 0xffff; d = h >>> 16;
|
|
2684
|
-
|
|
2685
|
-
h = hh[1];
|
|
2686
|
-
l = hl[1];
|
|
2687
|
-
|
|
2688
|
-
a += l & 0xffff; b += l >>> 16;
|
|
2689
|
-
c += h & 0xffff; d += h >>> 16;
|
|
2690
|
-
|
|
2691
|
-
b += a >>> 16;
|
|
2692
|
-
c += b >>> 16;
|
|
2693
|
-
d += c >>> 16;
|
|
2694
|
-
|
|
2695
|
-
hh[1] = ah1 = (c & 0xffff) | (d << 16);
|
|
2696
|
-
hl[1] = al1 = (a & 0xffff) | (b << 16);
|
|
2697
|
-
|
|
2698
|
-
h = ah2;
|
|
2699
|
-
l = al2;
|
|
2700
|
-
|
|
2701
|
-
a = l & 0xffff; b = l >>> 16;
|
|
2702
|
-
c = h & 0xffff; d = h >>> 16;
|
|
2703
|
-
|
|
2704
|
-
h = hh[2];
|
|
2705
|
-
l = hl[2];
|
|
2706
|
-
|
|
2707
|
-
a += l & 0xffff; b += l >>> 16;
|
|
2708
|
-
c += h & 0xffff; d += h >>> 16;
|
|
2709
|
-
|
|
2710
|
-
b += a >>> 16;
|
|
2711
|
-
c += b >>> 16;
|
|
2712
|
-
d += c >>> 16;
|
|
2713
|
-
|
|
2714
|
-
hh[2] = ah2 = (c & 0xffff) | (d << 16);
|
|
2715
|
-
hl[2] = al2 = (a & 0xffff) | (b << 16);
|
|
2716
|
-
|
|
2717
|
-
h = ah3;
|
|
2718
|
-
l = al3;
|
|
2719
|
-
|
|
2720
|
-
a = l & 0xffff; b = l >>> 16;
|
|
2721
|
-
c = h & 0xffff; d = h >>> 16;
|
|
2722
|
-
|
|
2723
|
-
h = hh[3];
|
|
2724
|
-
l = hl[3];
|
|
2725
|
-
|
|
2726
|
-
a += l & 0xffff; b += l >>> 16;
|
|
2727
|
-
c += h & 0xffff; d += h >>> 16;
|
|
2728
|
-
|
|
2729
|
-
b += a >>> 16;
|
|
2730
|
-
c += b >>> 16;
|
|
2731
|
-
d += c >>> 16;
|
|
2732
|
-
|
|
2733
|
-
hh[3] = ah3 = (c & 0xffff) | (d << 16);
|
|
2734
|
-
hl[3] = al3 = (a & 0xffff) | (b << 16);
|
|
2735
|
-
|
|
2736
|
-
h = ah4;
|
|
2737
|
-
l = al4;
|
|
2738
|
-
|
|
2739
|
-
a = l & 0xffff; b = l >>> 16;
|
|
2740
|
-
c = h & 0xffff; d = h >>> 16;
|
|
2741
|
-
|
|
2742
|
-
h = hh[4];
|
|
2743
|
-
l = hl[4];
|
|
2744
|
-
|
|
2745
|
-
a += l & 0xffff; b += l >>> 16;
|
|
2746
|
-
c += h & 0xffff; d += h >>> 16;
|
|
2747
|
-
|
|
2748
|
-
b += a >>> 16;
|
|
2749
|
-
c += b >>> 16;
|
|
2750
|
-
d += c >>> 16;
|
|
2751
|
-
|
|
2752
|
-
hh[4] = ah4 = (c & 0xffff) | (d << 16);
|
|
2753
|
-
hl[4] = al4 = (a & 0xffff) | (b << 16);
|
|
2754
|
-
|
|
2755
|
-
h = ah5;
|
|
2756
|
-
l = al5;
|
|
2757
|
-
|
|
2758
|
-
a = l & 0xffff; b = l >>> 16;
|
|
2759
|
-
c = h & 0xffff; d = h >>> 16;
|
|
2760
|
-
|
|
2761
|
-
h = hh[5];
|
|
2762
|
-
l = hl[5];
|
|
2763
|
-
|
|
2764
|
-
a += l & 0xffff; b += l >>> 16;
|
|
2765
|
-
c += h & 0xffff; d += h >>> 16;
|
|
2766
|
-
|
|
2767
|
-
b += a >>> 16;
|
|
2768
|
-
c += b >>> 16;
|
|
2769
|
-
d += c >>> 16;
|
|
2770
|
-
|
|
2771
|
-
hh[5] = ah5 = (c & 0xffff) | (d << 16);
|
|
2772
|
-
hl[5] = al5 = (a & 0xffff) | (b << 16);
|
|
2773
|
-
|
|
2774
|
-
h = ah6;
|
|
2775
|
-
l = al6;
|
|
2776
|
-
|
|
2777
|
-
a = l & 0xffff; b = l >>> 16;
|
|
2778
|
-
c = h & 0xffff; d = h >>> 16;
|
|
2779
|
-
|
|
2780
|
-
h = hh[6];
|
|
2781
|
-
l = hl[6];
|
|
2782
|
-
|
|
2783
|
-
a += l & 0xffff; b += l >>> 16;
|
|
2784
|
-
c += h & 0xffff; d += h >>> 16;
|
|
2785
|
-
|
|
2786
|
-
b += a >>> 16;
|
|
2787
|
-
c += b >>> 16;
|
|
2788
|
-
d += c >>> 16;
|
|
2789
|
-
|
|
2790
|
-
hh[6] = ah6 = (c & 0xffff) | (d << 16);
|
|
2791
|
-
hl[6] = al6 = (a & 0xffff) | (b << 16);
|
|
2792
|
-
|
|
2793
|
-
h = ah7;
|
|
2794
|
-
l = al7;
|
|
2795
|
-
|
|
2796
|
-
a = l & 0xffff; b = l >>> 16;
|
|
2797
|
-
c = h & 0xffff; d = h >>> 16;
|
|
2798
|
-
|
|
2799
|
-
h = hh[7];
|
|
2800
|
-
l = hl[7];
|
|
2801
|
-
|
|
2802
|
-
a += l & 0xffff; b += l >>> 16;
|
|
2803
|
-
c += h & 0xffff; d += h >>> 16;
|
|
2804
|
-
|
|
2805
|
-
b += a >>> 16;
|
|
2806
|
-
c += b >>> 16;
|
|
2807
|
-
d += c >>> 16;
|
|
2808
|
-
|
|
2809
|
-
hh[7] = ah7 = (c & 0xffff) | (d << 16);
|
|
2810
|
-
hl[7] = al7 = (a & 0xffff) | (b << 16);
|
|
2811
|
-
|
|
2812
|
-
pos += 128;
|
|
2813
|
-
n -= 128;
|
|
2814
|
-
}
|
|
2815
|
-
|
|
2816
|
-
return n;
|
|
2817
|
-
}
|
|
2818
|
-
|
|
2819
|
-
function crypto_hash(out, m, n) {
|
|
2820
|
-
var hh = new Int32Array(8),
|
|
2821
|
-
hl = new Int32Array(8),
|
|
2822
|
-
x = new Uint8Array(256),
|
|
2823
|
-
i, b = n;
|
|
2824
|
-
|
|
2825
|
-
hh[0] = 0x6a09e667;
|
|
2826
|
-
hh[1] = 0xbb67ae85;
|
|
2827
|
-
hh[2] = 0x3c6ef372;
|
|
2828
|
-
hh[3] = 0xa54ff53a;
|
|
2829
|
-
hh[4] = 0x510e527f;
|
|
2830
|
-
hh[5] = 0x9b05688c;
|
|
2831
|
-
hh[6] = 0x1f83d9ab;
|
|
2832
|
-
hh[7] = 0x5be0cd19;
|
|
2833
|
-
|
|
2834
|
-
hl[0] = 0xf3bcc908;
|
|
2835
|
-
hl[1] = 0x84caa73b;
|
|
2836
|
-
hl[2] = 0xfe94f82b;
|
|
2837
|
-
hl[3] = 0x5f1d36f1;
|
|
2838
|
-
hl[4] = 0xade682d1;
|
|
2839
|
-
hl[5] = 0x2b3e6c1f;
|
|
2840
|
-
hl[6] = 0xfb41bd6b;
|
|
2841
|
-
hl[7] = 0x137e2179;
|
|
2842
|
-
|
|
2843
|
-
crypto_hashblocks_hl(hh, hl, m, n);
|
|
2844
|
-
n %= 128;
|
|
2845
|
-
|
|
2846
|
-
for (i = 0; i < n; i++) x[i] = m[b-n+i];
|
|
2847
|
-
x[n] = 128;
|
|
2848
|
-
|
|
2849
|
-
n = 256-128*(n<112?1:0);
|
|
2850
|
-
x[n-9] = 0;
|
|
2851
|
-
ts64(x, n-8, (b / 0x20000000) | 0, b << 3);
|
|
2852
|
-
crypto_hashblocks_hl(hh, hl, x, n);
|
|
2853
|
-
|
|
2854
|
-
for (i = 0; i < 8; i++) ts64(out, 8*i, hh[i], hl[i]);
|
|
2855
|
-
|
|
2856
|
-
return 0;
|
|
2857
|
-
}
|
|
2858
|
-
|
|
2859
|
-
function add(p, q) {
|
|
2860
|
-
var a = gf(), b = gf(), c = gf(),
|
|
2861
|
-
d = gf(), e = gf(), f = gf(),
|
|
2862
|
-
g = gf(), h = gf(), t = gf();
|
|
2863
|
-
|
|
2864
|
-
Z(a, p[1], p[0]);
|
|
2865
|
-
Z(t, q[1], q[0]);
|
|
2866
|
-
M(a, a, t);
|
|
2867
|
-
A(b, p[0], p[1]);
|
|
2868
|
-
A(t, q[0], q[1]);
|
|
2869
|
-
M(b, b, t);
|
|
2870
|
-
M(c, p[3], q[3]);
|
|
2871
|
-
M(c, c, D2);
|
|
2872
|
-
M(d, p[2], q[2]);
|
|
2873
|
-
A(d, d, d);
|
|
2874
|
-
Z(e, b, a);
|
|
2875
|
-
Z(f, d, c);
|
|
2876
|
-
A(g, d, c);
|
|
2877
|
-
A(h, b, a);
|
|
2878
|
-
|
|
2879
|
-
M(p[0], e, f);
|
|
2880
|
-
M(p[1], h, g);
|
|
2881
|
-
M(p[2], g, f);
|
|
2882
|
-
M(p[3], e, h);
|
|
2883
|
-
}
|
|
2884
|
-
|
|
2885
|
-
function cswap(p, q, b) {
|
|
2886
|
-
var i;
|
|
2887
|
-
for (i = 0; i < 4; i++) {
|
|
2888
|
-
sel25519(p[i], q[i], b);
|
|
2889
|
-
}
|
|
2890
|
-
}
|
|
2891
|
-
|
|
2892
|
-
function pack(r, p) {
|
|
2893
|
-
var tx = gf(), ty = gf(), zi = gf();
|
|
2894
|
-
inv25519(zi, p[2]);
|
|
2895
|
-
M(tx, p[0], zi);
|
|
2896
|
-
M(ty, p[1], zi);
|
|
2897
|
-
pack25519(r, ty);
|
|
2898
|
-
r[31] ^= par25519(tx) << 7;
|
|
2899
|
-
}
|
|
2900
|
-
|
|
2901
|
-
function scalarmult(p, q, s) {
|
|
2902
|
-
var b, i;
|
|
2903
|
-
set25519(p[0], gf0);
|
|
2904
|
-
set25519(p[1], gf1);
|
|
2905
|
-
set25519(p[2], gf1);
|
|
2906
|
-
set25519(p[3], gf0);
|
|
2907
|
-
for (i = 255; i >= 0; --i) {
|
|
2908
|
-
b = (s[(i/8)|0] >> (i&7)) & 1;
|
|
2909
|
-
cswap(p, q, b);
|
|
2910
|
-
add(q, p);
|
|
2911
|
-
add(p, p);
|
|
2912
|
-
cswap(p, q, b);
|
|
2913
|
-
}
|
|
2914
|
-
}
|
|
2915
|
-
|
|
2916
|
-
function scalarbase(p, s) {
|
|
2917
|
-
var q = [gf(), gf(), gf(), gf()];
|
|
2918
|
-
set25519(q[0], X);
|
|
2919
|
-
set25519(q[1], Y);
|
|
2920
|
-
set25519(q[2], gf1);
|
|
2921
|
-
M(q[3], X, Y);
|
|
2922
|
-
scalarmult(p, q, s);
|
|
2923
|
-
}
|
|
2924
|
-
|
|
2925
|
-
function crypto_sign_keypair(pk, sk, seeded) {
|
|
2926
|
-
var d = new Uint8Array(64);
|
|
2927
|
-
var p = [gf(), gf(), gf(), gf()];
|
|
2928
|
-
var i;
|
|
2929
|
-
|
|
2930
|
-
if (!seeded) randombytes(sk, 32);
|
|
2931
|
-
crypto_hash(d, sk, 32);
|
|
2932
|
-
d[0] &= 248;
|
|
2933
|
-
d[31] &= 127;
|
|
2934
|
-
d[31] |= 64;
|
|
2935
|
-
|
|
2936
|
-
scalarbase(p, d);
|
|
2937
|
-
pack(pk, p);
|
|
2938
|
-
|
|
2939
|
-
for (i = 0; i < 32; i++) sk[i+32] = pk[i];
|
|
2940
|
-
return 0;
|
|
2941
|
-
}
|
|
2942
|
-
|
|
2943
|
-
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]);
|
|
2944
|
-
|
|
2945
|
-
function modL(r, x) {
|
|
2946
|
-
var carry, i, j, k;
|
|
2947
|
-
for (i = 63; i >= 32; --i) {
|
|
2948
|
-
carry = 0;
|
|
2949
|
-
for (j = i - 32, k = i - 12; j < k; ++j) {
|
|
2950
|
-
x[j] += carry - 16 * x[i] * L[j - (i - 32)];
|
|
2951
|
-
carry = Math.floor((x[j] + 128) / 256);
|
|
2952
|
-
x[j] -= carry * 256;
|
|
2953
|
-
}
|
|
2954
|
-
x[j] += carry;
|
|
2955
|
-
x[i] = 0;
|
|
2956
|
-
}
|
|
2957
|
-
carry = 0;
|
|
2958
|
-
for (j = 0; j < 32; j++) {
|
|
2959
|
-
x[j] += carry - (x[31] >> 4) * L[j];
|
|
2960
|
-
carry = x[j] >> 8;
|
|
2961
|
-
x[j] &= 255;
|
|
2962
|
-
}
|
|
2963
|
-
for (j = 0; j < 32; j++) x[j] -= carry * L[j];
|
|
2964
|
-
for (i = 0; i < 32; i++) {
|
|
2965
|
-
x[i+1] += x[i] >> 8;
|
|
2966
|
-
r[i] = x[i] & 255;
|
|
2967
|
-
}
|
|
2968
|
-
}
|
|
2969
|
-
|
|
2970
|
-
function reduce(r) {
|
|
2971
|
-
var x = new Float64Array(64), i;
|
|
2972
|
-
for (i = 0; i < 64; i++) x[i] = r[i];
|
|
2973
|
-
for (i = 0; i < 64; i++) r[i] = 0;
|
|
2974
|
-
modL(r, x);
|
|
2975
|
-
}
|
|
2976
|
-
|
|
2977
|
-
// Note: difference from C - smlen returned, not passed as argument.
|
|
2978
|
-
function crypto_sign(sm, m, n, sk) {
|
|
2979
|
-
var d = new Uint8Array(64), h = new Uint8Array(64), r = new Uint8Array(64);
|
|
2980
|
-
var i, j, x = new Float64Array(64);
|
|
2981
|
-
var p = [gf(), gf(), gf(), gf()];
|
|
2982
|
-
|
|
2983
|
-
crypto_hash(d, sk, 32);
|
|
2984
|
-
d[0] &= 248;
|
|
2985
|
-
d[31] &= 127;
|
|
2986
|
-
d[31] |= 64;
|
|
2987
|
-
|
|
2988
|
-
var smlen = n + 64;
|
|
2989
|
-
for (i = 0; i < n; i++) sm[64 + i] = m[i];
|
|
2990
|
-
for (i = 0; i < 32; i++) sm[32 + i] = d[32 + i];
|
|
2991
|
-
|
|
2992
|
-
crypto_hash(r, sm.subarray(32), n+32);
|
|
2993
|
-
reduce(r);
|
|
2994
|
-
scalarbase(p, r);
|
|
2995
|
-
pack(sm, p);
|
|
2996
|
-
|
|
2997
|
-
for (i = 32; i < 64; i++) sm[i] = sk[i];
|
|
2998
|
-
crypto_hash(h, sm, n + 64);
|
|
2999
|
-
reduce(h);
|
|
3000
|
-
|
|
3001
|
-
for (i = 0; i < 64; i++) x[i] = 0;
|
|
3002
|
-
for (i = 0; i < 32; i++) x[i] = r[i];
|
|
3003
|
-
for (i = 0; i < 32; i++) {
|
|
3004
|
-
for (j = 0; j < 32; j++) {
|
|
3005
|
-
x[i+j] += h[i] * d[j];
|
|
3006
|
-
}
|
|
3007
|
-
}
|
|
3008
|
-
|
|
3009
|
-
modL(sm.subarray(32), x);
|
|
3010
|
-
return smlen;
|
|
3011
|
-
}
|
|
3012
|
-
|
|
3013
|
-
function unpackneg(r, p) {
|
|
3014
|
-
var t = gf(), chk = gf(), num = gf(),
|
|
3015
|
-
den = gf(), den2 = gf(), den4 = gf(),
|
|
3016
|
-
den6 = gf();
|
|
3017
|
-
|
|
3018
|
-
set25519(r[2], gf1);
|
|
3019
|
-
unpack25519(r[1], p);
|
|
3020
|
-
S(num, r[1]);
|
|
3021
|
-
M(den, num, D);
|
|
3022
|
-
Z(num, num, r[2]);
|
|
3023
|
-
A(den, r[2], den);
|
|
3024
|
-
|
|
3025
|
-
S(den2, den);
|
|
3026
|
-
S(den4, den2);
|
|
3027
|
-
M(den6, den4, den2);
|
|
3028
|
-
M(t, den6, num);
|
|
3029
|
-
M(t, t, den);
|
|
3030
|
-
|
|
3031
|
-
pow2523(t, t);
|
|
3032
|
-
M(t, t, num);
|
|
3033
|
-
M(t, t, den);
|
|
3034
|
-
M(t, t, den);
|
|
3035
|
-
M(r[0], t, den);
|
|
3036
|
-
|
|
3037
|
-
S(chk, r[0]);
|
|
3038
|
-
M(chk, chk, den);
|
|
3039
|
-
if (neq25519(chk, num)) M(r[0], r[0], I);
|
|
3040
|
-
|
|
3041
|
-
S(chk, r[0]);
|
|
3042
|
-
M(chk, chk, den);
|
|
3043
|
-
if (neq25519(chk, num)) return -1;
|
|
3044
|
-
|
|
3045
|
-
if (par25519(r[0]) === (p[31]>>7)) Z(r[0], gf0, r[0]);
|
|
3046
|
-
|
|
3047
|
-
M(r[3], r[0], r[1]);
|
|
3048
|
-
return 0;
|
|
3049
|
-
}
|
|
3050
|
-
|
|
3051
|
-
function crypto_sign_open(m, sm, n, pk) {
|
|
3052
|
-
var i;
|
|
3053
|
-
var t = new Uint8Array(32), h = new Uint8Array(64);
|
|
3054
|
-
var p = [gf(), gf(), gf(), gf()],
|
|
3055
|
-
q = [gf(), gf(), gf(), gf()];
|
|
3056
|
-
|
|
3057
|
-
if (n < 64) return -1;
|
|
3058
|
-
|
|
3059
|
-
if (unpackneg(q, pk)) return -1;
|
|
3060
|
-
|
|
3061
|
-
for (i = 0; i < n; i++) m[i] = sm[i];
|
|
3062
|
-
for (i = 0; i < 32; i++) m[i+32] = pk[i];
|
|
3063
|
-
crypto_hash(h, m, n);
|
|
3064
|
-
reduce(h);
|
|
3065
|
-
scalarmult(p, q, h);
|
|
3066
|
-
|
|
3067
|
-
scalarbase(q, sm.subarray(32));
|
|
3068
|
-
add(p, q);
|
|
3069
|
-
pack(t, p);
|
|
3070
|
-
|
|
3071
|
-
n -= 64;
|
|
3072
|
-
if (crypto_verify_32(sm, 0, t, 0)) {
|
|
3073
|
-
for (i = 0; i < n; i++) m[i] = 0;
|
|
3074
|
-
return -1;
|
|
3075
|
-
}
|
|
3076
|
-
|
|
3077
|
-
for (i = 0; i < n; i++) m[i] = sm[i + 64];
|
|
3078
|
-
return n;
|
|
3079
|
-
}
|
|
3080
|
-
|
|
3081
|
-
var crypto_secretbox_KEYBYTES = 32,
|
|
3082
|
-
crypto_secretbox_NONCEBYTES = 24,
|
|
3083
|
-
crypto_secretbox_ZEROBYTES = 32,
|
|
3084
|
-
crypto_secretbox_BOXZEROBYTES = 16,
|
|
3085
|
-
crypto_scalarmult_BYTES = 32,
|
|
3086
|
-
crypto_scalarmult_SCALARBYTES = 32,
|
|
3087
|
-
crypto_box_PUBLICKEYBYTES = 32,
|
|
3088
|
-
crypto_box_SECRETKEYBYTES = 32,
|
|
3089
|
-
crypto_box_BEFORENMBYTES = 32,
|
|
3090
|
-
crypto_box_NONCEBYTES = crypto_secretbox_NONCEBYTES,
|
|
3091
|
-
crypto_box_ZEROBYTES = crypto_secretbox_ZEROBYTES,
|
|
3092
|
-
crypto_box_BOXZEROBYTES = crypto_secretbox_BOXZEROBYTES,
|
|
3093
|
-
crypto_sign_BYTES = 64,
|
|
3094
|
-
crypto_sign_PUBLICKEYBYTES = 32,
|
|
3095
|
-
crypto_sign_SECRETKEYBYTES = 64,
|
|
3096
|
-
crypto_sign_SEEDBYTES = 32,
|
|
3097
|
-
crypto_hash_BYTES = 64;
|
|
3098
|
-
|
|
3099
|
-
nacl.lowlevel = {
|
|
3100
|
-
crypto_core_hsalsa20: crypto_core_hsalsa20,
|
|
3101
|
-
crypto_stream_xor: crypto_stream_xor,
|
|
3102
|
-
crypto_stream: crypto_stream,
|
|
3103
|
-
crypto_stream_salsa20_xor: crypto_stream_salsa20_xor,
|
|
3104
|
-
crypto_stream_salsa20: crypto_stream_salsa20,
|
|
3105
|
-
crypto_onetimeauth: crypto_onetimeauth,
|
|
3106
|
-
crypto_onetimeauth_verify: crypto_onetimeauth_verify,
|
|
3107
|
-
crypto_verify_16: crypto_verify_16,
|
|
3108
|
-
crypto_verify_32: crypto_verify_32,
|
|
3109
|
-
crypto_secretbox: crypto_secretbox,
|
|
3110
|
-
crypto_secretbox_open: crypto_secretbox_open,
|
|
3111
|
-
crypto_scalarmult: crypto_scalarmult,
|
|
3112
|
-
crypto_scalarmult_base: crypto_scalarmult_base,
|
|
3113
|
-
crypto_box_beforenm: crypto_box_beforenm,
|
|
3114
|
-
crypto_box_afternm: crypto_box_afternm,
|
|
3115
|
-
crypto_box: crypto_box,
|
|
3116
|
-
crypto_box_open: crypto_box_open,
|
|
3117
|
-
crypto_box_keypair: crypto_box_keypair,
|
|
3118
|
-
crypto_hash: crypto_hash,
|
|
3119
|
-
crypto_sign: crypto_sign,
|
|
3120
|
-
crypto_sign_keypair: crypto_sign_keypair,
|
|
3121
|
-
crypto_sign_open: crypto_sign_open,
|
|
3122
|
-
|
|
3123
|
-
crypto_secretbox_KEYBYTES: crypto_secretbox_KEYBYTES,
|
|
3124
|
-
crypto_secretbox_NONCEBYTES: crypto_secretbox_NONCEBYTES,
|
|
3125
|
-
crypto_secretbox_ZEROBYTES: crypto_secretbox_ZEROBYTES,
|
|
3126
|
-
crypto_secretbox_BOXZEROBYTES: crypto_secretbox_BOXZEROBYTES,
|
|
3127
|
-
crypto_scalarmult_BYTES: crypto_scalarmult_BYTES,
|
|
3128
|
-
crypto_scalarmult_SCALARBYTES: crypto_scalarmult_SCALARBYTES,
|
|
3129
|
-
crypto_box_PUBLICKEYBYTES: crypto_box_PUBLICKEYBYTES,
|
|
3130
|
-
crypto_box_SECRETKEYBYTES: crypto_box_SECRETKEYBYTES,
|
|
3131
|
-
crypto_box_BEFORENMBYTES: crypto_box_BEFORENMBYTES,
|
|
3132
|
-
crypto_box_NONCEBYTES: crypto_box_NONCEBYTES,
|
|
3133
|
-
crypto_box_ZEROBYTES: crypto_box_ZEROBYTES,
|
|
3134
|
-
crypto_box_BOXZEROBYTES: crypto_box_BOXZEROBYTES,
|
|
3135
|
-
crypto_sign_BYTES: crypto_sign_BYTES,
|
|
3136
|
-
crypto_sign_PUBLICKEYBYTES: crypto_sign_PUBLICKEYBYTES,
|
|
3137
|
-
crypto_sign_SECRETKEYBYTES: crypto_sign_SECRETKEYBYTES,
|
|
3138
|
-
crypto_sign_SEEDBYTES: crypto_sign_SEEDBYTES,
|
|
3139
|
-
crypto_hash_BYTES: crypto_hash_BYTES,
|
|
3140
|
-
|
|
3141
|
-
gf: gf,
|
|
3142
|
-
D: D,
|
|
3143
|
-
L: L,
|
|
3144
|
-
pack25519: pack25519,
|
|
3145
|
-
unpack25519: unpack25519,
|
|
3146
|
-
M: M,
|
|
3147
|
-
A: A,
|
|
3148
|
-
S: S,
|
|
3149
|
-
Z: Z,
|
|
3150
|
-
pow2523: pow2523,
|
|
3151
|
-
add: add,
|
|
3152
|
-
set25519: set25519,
|
|
3153
|
-
modL: modL,
|
|
3154
|
-
scalarmult: scalarmult,
|
|
3155
|
-
scalarbase: scalarbase,
|
|
3156
|
-
};
|
|
3157
|
-
|
|
3158
|
-
/* High-level API */
|
|
3159
|
-
|
|
3160
|
-
function checkLengths(k, n) {
|
|
3161
|
-
if (k.length !== crypto_secretbox_KEYBYTES) throw new Error('bad key size');
|
|
3162
|
-
if (n.length !== crypto_secretbox_NONCEBYTES) throw new Error('bad nonce size');
|
|
3163
|
-
}
|
|
3164
|
-
|
|
3165
|
-
function checkBoxLengths(pk, sk) {
|
|
3166
|
-
if (pk.length !== crypto_box_PUBLICKEYBYTES) throw new Error('bad public key size');
|
|
3167
|
-
if (sk.length !== crypto_box_SECRETKEYBYTES) throw new Error('bad secret key size');
|
|
3168
|
-
}
|
|
3169
|
-
|
|
3170
|
-
function checkArrayTypes() {
|
|
3171
|
-
for (var i = 0; i < arguments.length; i++) {
|
|
3172
|
-
if (!(arguments[i] instanceof Uint8Array))
|
|
3173
|
-
throw new TypeError('unexpected type, use Uint8Array');
|
|
3174
|
-
}
|
|
3175
|
-
}
|
|
3176
|
-
|
|
3177
|
-
function cleanup(arr) {
|
|
3178
|
-
for (var i = 0; i < arr.length; i++) arr[i] = 0;
|
|
3179
|
-
}
|
|
3180
|
-
|
|
3181
|
-
nacl.randomBytes = function(n) {
|
|
3182
|
-
var b = new Uint8Array(n);
|
|
3183
|
-
randombytes(b, n);
|
|
3184
|
-
return b;
|
|
3185
|
-
};
|
|
3186
|
-
|
|
3187
|
-
nacl.secretbox = function(msg, nonce, key) {
|
|
3188
|
-
checkArrayTypes(msg, nonce, key);
|
|
3189
|
-
checkLengths(key, nonce);
|
|
3190
|
-
var m = new Uint8Array(crypto_secretbox_ZEROBYTES + msg.length);
|
|
3191
|
-
var c = new Uint8Array(m.length);
|
|
3192
|
-
for (var i = 0; i < msg.length; i++) m[i+crypto_secretbox_ZEROBYTES] = msg[i];
|
|
3193
|
-
crypto_secretbox(c, m, m.length, nonce, key);
|
|
3194
|
-
return c.subarray(crypto_secretbox_BOXZEROBYTES);
|
|
3195
|
-
};
|
|
3196
|
-
|
|
3197
|
-
nacl.secretbox.open = function(box, nonce, key) {
|
|
3198
|
-
checkArrayTypes(box, nonce, key);
|
|
3199
|
-
checkLengths(key, nonce);
|
|
3200
|
-
var c = new Uint8Array(crypto_secretbox_BOXZEROBYTES + box.length);
|
|
3201
|
-
var m = new Uint8Array(c.length);
|
|
3202
|
-
for (var i = 0; i < box.length; i++) c[i+crypto_secretbox_BOXZEROBYTES] = box[i];
|
|
3203
|
-
if (c.length < 32) return null;
|
|
3204
|
-
if (crypto_secretbox_open(m, c, c.length, nonce, key) !== 0) return null;
|
|
3205
|
-
return m.subarray(crypto_secretbox_ZEROBYTES);
|
|
3206
|
-
};
|
|
3207
|
-
|
|
3208
|
-
nacl.secretbox.keyLength = crypto_secretbox_KEYBYTES;
|
|
3209
|
-
nacl.secretbox.nonceLength = crypto_secretbox_NONCEBYTES;
|
|
3210
|
-
nacl.secretbox.overheadLength = crypto_secretbox_BOXZEROBYTES;
|
|
3211
|
-
|
|
3212
|
-
nacl.scalarMult = function(n, p) {
|
|
3213
|
-
checkArrayTypes(n, p);
|
|
3214
|
-
if (n.length !== crypto_scalarmult_SCALARBYTES) throw new Error('bad n size');
|
|
3215
|
-
if (p.length !== crypto_scalarmult_BYTES) throw new Error('bad p size');
|
|
3216
|
-
var q = new Uint8Array(crypto_scalarmult_BYTES);
|
|
3217
|
-
crypto_scalarmult(q, n, p);
|
|
3218
|
-
return q;
|
|
3219
|
-
};
|
|
3220
|
-
|
|
3221
|
-
nacl.scalarMult.base = function(n) {
|
|
3222
|
-
checkArrayTypes(n);
|
|
3223
|
-
if (n.length !== crypto_scalarmult_SCALARBYTES) throw new Error('bad n size');
|
|
3224
|
-
var q = new Uint8Array(crypto_scalarmult_BYTES);
|
|
3225
|
-
crypto_scalarmult_base(q, n);
|
|
3226
|
-
return q;
|
|
3227
|
-
};
|
|
3228
|
-
|
|
3229
|
-
nacl.scalarMult.scalarLength = crypto_scalarmult_SCALARBYTES;
|
|
3230
|
-
nacl.scalarMult.groupElementLength = crypto_scalarmult_BYTES;
|
|
3231
|
-
|
|
3232
|
-
nacl.box = function(msg, nonce, publicKey, secretKey) {
|
|
3233
|
-
var k = nacl.box.before(publicKey, secretKey);
|
|
3234
|
-
return nacl.secretbox(msg, nonce, k);
|
|
3235
|
-
};
|
|
3236
|
-
|
|
3237
|
-
nacl.box.before = function(publicKey, secretKey) {
|
|
3238
|
-
checkArrayTypes(publicKey, secretKey);
|
|
3239
|
-
checkBoxLengths(publicKey, secretKey);
|
|
3240
|
-
var k = new Uint8Array(crypto_box_BEFORENMBYTES);
|
|
3241
|
-
crypto_box_beforenm(k, publicKey, secretKey);
|
|
3242
|
-
return k;
|
|
3243
|
-
};
|
|
3244
|
-
|
|
3245
|
-
nacl.box.after = nacl.secretbox;
|
|
3246
|
-
|
|
3247
|
-
nacl.box.open = function(msg, nonce, publicKey, secretKey) {
|
|
3248
|
-
var k = nacl.box.before(publicKey, secretKey);
|
|
3249
|
-
return nacl.secretbox.open(msg, nonce, k);
|
|
3250
|
-
};
|
|
3251
|
-
|
|
3252
|
-
nacl.box.open.after = nacl.secretbox.open;
|
|
3253
|
-
|
|
3254
|
-
nacl.box.keyPair = function() {
|
|
3255
|
-
var pk = new Uint8Array(crypto_box_PUBLICKEYBYTES);
|
|
3256
|
-
var sk = new Uint8Array(crypto_box_SECRETKEYBYTES);
|
|
3257
|
-
crypto_box_keypair(pk, sk);
|
|
3258
|
-
return {publicKey: pk, secretKey: sk};
|
|
3259
|
-
};
|
|
3260
|
-
|
|
3261
|
-
nacl.box.keyPair.fromSecretKey = function(secretKey) {
|
|
3262
|
-
checkArrayTypes(secretKey);
|
|
3263
|
-
if (secretKey.length !== crypto_box_SECRETKEYBYTES)
|
|
3264
|
-
throw new Error('bad secret key size');
|
|
3265
|
-
var pk = new Uint8Array(crypto_box_PUBLICKEYBYTES);
|
|
3266
|
-
crypto_scalarmult_base(pk, secretKey);
|
|
3267
|
-
return {publicKey: pk, secretKey: new Uint8Array(secretKey)};
|
|
3268
|
-
};
|
|
3269
|
-
|
|
3270
|
-
nacl.box.publicKeyLength = crypto_box_PUBLICKEYBYTES;
|
|
3271
|
-
nacl.box.secretKeyLength = crypto_box_SECRETKEYBYTES;
|
|
3272
|
-
nacl.box.sharedKeyLength = crypto_box_BEFORENMBYTES;
|
|
3273
|
-
nacl.box.nonceLength = crypto_box_NONCEBYTES;
|
|
3274
|
-
nacl.box.overheadLength = nacl.secretbox.overheadLength;
|
|
3275
|
-
|
|
3276
|
-
nacl.sign = function(msg, secretKey) {
|
|
3277
|
-
checkArrayTypes(msg, secretKey);
|
|
3278
|
-
if (secretKey.length !== crypto_sign_SECRETKEYBYTES)
|
|
3279
|
-
throw new Error('bad secret key size');
|
|
3280
|
-
var signedMsg = new Uint8Array(crypto_sign_BYTES+msg.length);
|
|
3281
|
-
crypto_sign(signedMsg, msg, msg.length, secretKey);
|
|
3282
|
-
return signedMsg;
|
|
3283
|
-
};
|
|
3284
|
-
|
|
3285
|
-
nacl.sign.open = function(signedMsg, publicKey) {
|
|
3286
|
-
checkArrayTypes(signedMsg, publicKey);
|
|
3287
|
-
if (publicKey.length !== crypto_sign_PUBLICKEYBYTES)
|
|
3288
|
-
throw new Error('bad public key size');
|
|
3289
|
-
var tmp = new Uint8Array(signedMsg.length);
|
|
3290
|
-
var mlen = crypto_sign_open(tmp, signedMsg, signedMsg.length, publicKey);
|
|
3291
|
-
if (mlen < 0) return null;
|
|
3292
|
-
var m = new Uint8Array(mlen);
|
|
3293
|
-
for (var i = 0; i < m.length; i++) m[i] = tmp[i];
|
|
3294
|
-
return m;
|
|
3295
|
-
};
|
|
3296
|
-
|
|
3297
|
-
nacl.sign.detached = function(msg, secretKey) {
|
|
3298
|
-
var signedMsg = nacl.sign(msg, secretKey);
|
|
3299
|
-
var sig = new Uint8Array(crypto_sign_BYTES);
|
|
3300
|
-
for (var i = 0; i < sig.length; i++) sig[i] = signedMsg[i];
|
|
3301
|
-
return sig;
|
|
3302
|
-
};
|
|
3303
|
-
|
|
3304
|
-
nacl.sign.detached.verify = function(msg, sig, publicKey) {
|
|
3305
|
-
checkArrayTypes(msg, sig, publicKey);
|
|
3306
|
-
if (sig.length !== crypto_sign_BYTES)
|
|
3307
|
-
throw new Error('bad signature size');
|
|
3308
|
-
if (publicKey.length !== crypto_sign_PUBLICKEYBYTES)
|
|
3309
|
-
throw new Error('bad public key size');
|
|
3310
|
-
var sm = new Uint8Array(crypto_sign_BYTES + msg.length);
|
|
3311
|
-
var m = new Uint8Array(crypto_sign_BYTES + msg.length);
|
|
3312
|
-
var i;
|
|
3313
|
-
for (i = 0; i < crypto_sign_BYTES; i++) sm[i] = sig[i];
|
|
3314
|
-
for (i = 0; i < msg.length; i++) sm[i+crypto_sign_BYTES] = msg[i];
|
|
3315
|
-
return (crypto_sign_open(m, sm, sm.length, publicKey) >= 0);
|
|
3316
|
-
};
|
|
3317
|
-
|
|
3318
|
-
nacl.sign.keyPair = function() {
|
|
3319
|
-
var pk = new Uint8Array(crypto_sign_PUBLICKEYBYTES);
|
|
3320
|
-
var sk = new Uint8Array(crypto_sign_SECRETKEYBYTES);
|
|
3321
|
-
crypto_sign_keypair(pk, sk);
|
|
3322
|
-
return {publicKey: pk, secretKey: sk};
|
|
3323
|
-
};
|
|
3324
|
-
|
|
3325
|
-
nacl.sign.keyPair.fromSecretKey = function(secretKey) {
|
|
3326
|
-
checkArrayTypes(secretKey);
|
|
3327
|
-
if (secretKey.length !== crypto_sign_SECRETKEYBYTES)
|
|
3328
|
-
throw new Error('bad secret key size');
|
|
3329
|
-
var pk = new Uint8Array(crypto_sign_PUBLICKEYBYTES);
|
|
3330
|
-
for (var i = 0; i < pk.length; i++) pk[i] = secretKey[32+i];
|
|
3331
|
-
return {publicKey: pk, secretKey: new Uint8Array(secretKey)};
|
|
3332
|
-
};
|
|
3333
|
-
|
|
3334
|
-
nacl.sign.keyPair.fromSeed = function(seed) {
|
|
3335
|
-
checkArrayTypes(seed);
|
|
3336
|
-
if (seed.length !== crypto_sign_SEEDBYTES)
|
|
3337
|
-
throw new Error('bad seed size');
|
|
3338
|
-
var pk = new Uint8Array(crypto_sign_PUBLICKEYBYTES);
|
|
3339
|
-
var sk = new Uint8Array(crypto_sign_SECRETKEYBYTES);
|
|
3340
|
-
for (var i = 0; i < 32; i++) sk[i] = seed[i];
|
|
3341
|
-
crypto_sign_keypair(pk, sk, true);
|
|
3342
|
-
return {publicKey: pk, secretKey: sk};
|
|
3343
|
-
};
|
|
3344
|
-
|
|
3345
|
-
nacl.sign.publicKeyLength = crypto_sign_PUBLICKEYBYTES;
|
|
3346
|
-
nacl.sign.secretKeyLength = crypto_sign_SECRETKEYBYTES;
|
|
3347
|
-
nacl.sign.seedLength = crypto_sign_SEEDBYTES;
|
|
3348
|
-
nacl.sign.signatureLength = crypto_sign_BYTES;
|
|
3349
|
-
|
|
3350
|
-
nacl.hash = function(msg) {
|
|
3351
|
-
checkArrayTypes(msg);
|
|
3352
|
-
var h = new Uint8Array(crypto_hash_BYTES);
|
|
3353
|
-
crypto_hash(h, msg, msg.length);
|
|
3354
|
-
return h;
|
|
3355
|
-
};
|
|
3356
|
-
|
|
3357
|
-
nacl.hash.hashLength = crypto_hash_BYTES;
|
|
3358
|
-
|
|
3359
|
-
nacl.verify = function(x, y) {
|
|
3360
|
-
checkArrayTypes(x, y);
|
|
3361
|
-
// Zero length arguments are considered not equal.
|
|
3362
|
-
if (x.length === 0 || y.length === 0) return false;
|
|
3363
|
-
if (x.length !== y.length) return false;
|
|
3364
|
-
return (vn(x, 0, y, 0, x.length) === 0) ? true : false;
|
|
3365
|
-
};
|
|
3366
|
-
|
|
3367
|
-
nacl.setPRNG = function(fn) {
|
|
3368
|
-
randombytes = fn;
|
|
3369
|
-
};
|
|
3370
|
-
|
|
3371
|
-
(function() {
|
|
3372
|
-
// Initialize PRNG if environment provides CSPRNG.
|
|
3373
|
-
// If not, methods calling randombytes will throw.
|
|
3374
|
-
var crypto = typeof self !== 'undefined' ? (self.crypto || self.msCrypto) : null;
|
|
3375
|
-
if (crypto && crypto.getRandomValues) {
|
|
3376
|
-
// Browsers.
|
|
3377
|
-
var QUOTA = 65536;
|
|
3378
|
-
nacl.setPRNG(function(x, n) {
|
|
3379
|
-
var i, v = new Uint8Array(n);
|
|
3380
|
-
for (i = 0; i < n; i += QUOTA) {
|
|
3381
|
-
crypto.getRandomValues(v.subarray(i, i + Math.min(n - i, QUOTA)));
|
|
3382
|
-
}
|
|
3383
|
-
for (i = 0; i < n; i++) x[i] = v[i];
|
|
3384
|
-
cleanup(v);
|
|
3385
|
-
});
|
|
3386
|
-
} else if (typeof commonjsRequire !== 'undefined') {
|
|
3387
|
-
// Node.js.
|
|
3388
|
-
crypto = require$$0;
|
|
3389
|
-
if (crypto && crypto.randomBytes) {
|
|
3390
|
-
nacl.setPRNG(function(x, n) {
|
|
3391
|
-
var i, v = crypto.randomBytes(n);
|
|
3392
|
-
for (i = 0; i < n; i++) x[i] = v[i];
|
|
3393
|
-
cleanup(v);
|
|
3394
|
-
});
|
|
3395
|
-
}
|
|
3396
|
-
}
|
|
3397
|
-
})();
|
|
3398
|
-
|
|
3399
|
-
})(module.exports ? module.exports : (self.nacl = self.nacl || {}));
|
|
3400
|
-
} (naclFast));
|
|
3401
|
-
return naclFast.exports;
|
|
3402
|
-
}
|
|
3403
|
-
|
|
3404
|
-
requireNaclFast();
|
|
3405
|
-
|
|
3406
|
-
var src;
|
|
3407
|
-
var hasRequiredSrc;
|
|
3408
|
-
|
|
3409
|
-
function requireSrc () {
|
|
3410
|
-
if (hasRequiredSrc) return src;
|
|
3411
|
-
hasRequiredSrc = 1;
|
|
3412
|
-
// base-x encoding / decoding
|
|
3413
|
-
// Copyright (c) 2018 base-x contributors
|
|
3414
|
-
// Copyright (c) 2014-2018 The Bitcoin Core developers (base58.cpp)
|
|
3415
|
-
// Distributed under the MIT software license, see the accompanying
|
|
3416
|
-
// file LICENSE or http://www.opensource.org/licenses/mit-license.php.
|
|
3417
|
-
function base (ALPHABET) {
|
|
3418
|
-
if (ALPHABET.length >= 255) { throw new TypeError('Alphabet too long') }
|
|
3419
|
-
var BASE_MAP = new Uint8Array(256);
|
|
3420
|
-
for (var j = 0; j < BASE_MAP.length; j++) {
|
|
3421
|
-
BASE_MAP[j] = 255;
|
|
3422
|
-
}
|
|
3423
|
-
for (var i = 0; i < ALPHABET.length; i++) {
|
|
3424
|
-
var x = ALPHABET.charAt(i);
|
|
3425
|
-
var xc = x.charCodeAt(0);
|
|
3426
|
-
if (BASE_MAP[xc] !== 255) { throw new TypeError(x + ' is ambiguous') }
|
|
3427
|
-
BASE_MAP[xc] = i;
|
|
3428
|
-
}
|
|
3429
|
-
var BASE = ALPHABET.length;
|
|
3430
|
-
var LEADER = ALPHABET.charAt(0);
|
|
3431
|
-
var FACTOR = Math.log(BASE) / Math.log(256); // log(BASE) / log(256), rounded up
|
|
3432
|
-
var iFACTOR = Math.log(256) / Math.log(BASE); // log(256) / log(BASE), rounded up
|
|
3433
|
-
function encode (source) {
|
|
3434
|
-
if (source instanceof Uint8Array) ; else if (ArrayBuffer.isView(source)) {
|
|
3435
|
-
source = new Uint8Array(source.buffer, source.byteOffset, source.byteLength);
|
|
3436
|
-
} else if (Array.isArray(source)) {
|
|
3437
|
-
source = Uint8Array.from(source);
|
|
3438
|
-
}
|
|
3439
|
-
if (!(source instanceof Uint8Array)) { throw new TypeError('Expected Uint8Array') }
|
|
3440
|
-
if (source.length === 0) { return '' }
|
|
3441
|
-
// Skip & count leading zeroes.
|
|
3442
|
-
var zeroes = 0;
|
|
3443
|
-
var length = 0;
|
|
3444
|
-
var pbegin = 0;
|
|
3445
|
-
var pend = source.length;
|
|
3446
|
-
while (pbegin !== pend && source[pbegin] === 0) {
|
|
3447
|
-
pbegin++;
|
|
3448
|
-
zeroes++;
|
|
3449
|
-
}
|
|
3450
|
-
// Allocate enough space in big-endian base58 representation.
|
|
3451
|
-
var size = ((pend - pbegin) * iFACTOR + 1) >>> 0;
|
|
3452
|
-
var b58 = new Uint8Array(size);
|
|
3453
|
-
// Process the bytes.
|
|
3454
|
-
while (pbegin !== pend) {
|
|
3455
|
-
var carry = source[pbegin];
|
|
3456
|
-
// Apply "b58 = b58 * 256 + ch".
|
|
3457
|
-
var i = 0;
|
|
3458
|
-
for (var it1 = size - 1; (carry !== 0 || i < length) && (it1 !== -1); it1--, i++) {
|
|
3459
|
-
carry += (256 * b58[it1]) >>> 0;
|
|
3460
|
-
b58[it1] = (carry % BASE) >>> 0;
|
|
3461
|
-
carry = (carry / BASE) >>> 0;
|
|
3462
|
-
}
|
|
3463
|
-
if (carry !== 0) { throw new Error('Non-zero carry') }
|
|
3464
|
-
length = i;
|
|
3465
|
-
pbegin++;
|
|
3466
|
-
}
|
|
3467
|
-
// Skip leading zeroes in base58 result.
|
|
3468
|
-
var it2 = size - length;
|
|
3469
|
-
while (it2 !== size && b58[it2] === 0) {
|
|
3470
|
-
it2++;
|
|
3471
|
-
}
|
|
3472
|
-
// Translate the result into a string.
|
|
3473
|
-
var str = LEADER.repeat(zeroes);
|
|
3474
|
-
for (; it2 < size; ++it2) { str += ALPHABET.charAt(b58[it2]); }
|
|
3475
|
-
return str
|
|
3476
|
-
}
|
|
3477
|
-
function decodeUnsafe (source) {
|
|
3478
|
-
if (typeof source !== 'string') { throw new TypeError('Expected String') }
|
|
3479
|
-
if (source.length === 0) { return new Uint8Array() }
|
|
3480
|
-
var psz = 0;
|
|
3481
|
-
// Skip and count leading '1's.
|
|
3482
|
-
var zeroes = 0;
|
|
3483
|
-
var length = 0;
|
|
3484
|
-
while (source[psz] === LEADER) {
|
|
3485
|
-
zeroes++;
|
|
3486
|
-
psz++;
|
|
3487
|
-
}
|
|
3488
|
-
// Allocate enough space in big-endian base256 representation.
|
|
3489
|
-
var size = (((source.length - psz) * FACTOR) + 1) >>> 0; // log(58) / log(256), rounded up.
|
|
3490
|
-
var b256 = new Uint8Array(size);
|
|
3491
|
-
// Process the characters.
|
|
3492
|
-
while (source[psz]) {
|
|
3493
|
-
// Find code of next character
|
|
3494
|
-
var charCode = source.charCodeAt(psz);
|
|
3495
|
-
// Base map can not be indexed using char code
|
|
3496
|
-
if (charCode > 255) { return }
|
|
3497
|
-
// Decode character
|
|
3498
|
-
var carry = BASE_MAP[charCode];
|
|
3499
|
-
// Invalid character
|
|
3500
|
-
if (carry === 255) { return }
|
|
3501
|
-
var i = 0;
|
|
3502
|
-
for (var it3 = size - 1; (carry !== 0 || i < length) && (it3 !== -1); it3--, i++) {
|
|
3503
|
-
carry += (BASE * b256[it3]) >>> 0;
|
|
3504
|
-
b256[it3] = (carry % 256) >>> 0;
|
|
3505
|
-
carry = (carry / 256) >>> 0;
|
|
3506
|
-
}
|
|
3507
|
-
if (carry !== 0) { throw new Error('Non-zero carry') }
|
|
3508
|
-
length = i;
|
|
3509
|
-
psz++;
|
|
3510
|
-
}
|
|
3511
|
-
// Skip leading zeroes in b256.
|
|
3512
|
-
var it4 = size - length;
|
|
3513
|
-
while (it4 !== size && b256[it4] === 0) {
|
|
3514
|
-
it4++;
|
|
3515
|
-
}
|
|
3516
|
-
var vch = new Uint8Array(zeroes + (size - it4));
|
|
3517
|
-
var j = zeroes;
|
|
3518
|
-
while (it4 !== size) {
|
|
3519
|
-
vch[j++] = b256[it4++];
|
|
3520
|
-
}
|
|
3521
|
-
return vch
|
|
3522
|
-
}
|
|
3523
|
-
function decode (string) {
|
|
3524
|
-
var buffer = decodeUnsafe(string);
|
|
3525
|
-
if (buffer) { return buffer }
|
|
3526
|
-
throw new Error('Non-base' + BASE + ' character')
|
|
3527
|
-
}
|
|
3528
|
-
return {
|
|
3529
|
-
encode: encode,
|
|
3530
|
-
decodeUnsafe: decodeUnsafe,
|
|
3531
|
-
decode: decode
|
|
3532
|
-
}
|
|
3533
|
-
}
|
|
3534
|
-
src = base;
|
|
3535
|
-
return src;
|
|
3536
|
-
}
|
|
3537
|
-
|
|
3538
|
-
var bs58$3;
|
|
3539
|
-
var hasRequiredBs58;
|
|
3540
|
-
|
|
3541
|
-
function requireBs58 () {
|
|
3542
|
-
if (hasRequiredBs58) return bs58$3;
|
|
3543
|
-
hasRequiredBs58 = 1;
|
|
3544
|
-
const basex = requireSrc();
|
|
3545
|
-
const ALPHABET = '123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz';
|
|
3546
|
-
|
|
3547
|
-
bs58$3 = basex(ALPHABET);
|
|
3548
|
-
return bs58$3;
|
|
3549
|
-
}
|
|
3550
|
-
|
|
3551
|
-
requireBs58();
|
|
3552
|
-
|
|
3553
1002
|
// src/PhantomClient.ts
|
|
3554
1003
|
var CAIP2_NETWORK_MAPPINGS = {
|
|
3555
1004
|
// Solana networks
|
|
@@ -11182,133 +8631,6 @@ class Transaction {
|
|
|
11182
8631
|
}
|
|
11183
8632
|
}
|
|
11184
8633
|
|
|
11185
|
-
// base-x encoding / decoding
|
|
11186
|
-
// Copyright (c) 2018 base-x contributors
|
|
11187
|
-
// Copyright (c) 2014-2018 The Bitcoin Core developers (base58.cpp)
|
|
11188
|
-
// Distributed under the MIT software license, see the accompanying
|
|
11189
|
-
// file LICENSE or http://www.opensource.org/licenses/mit-license.php.
|
|
11190
|
-
function base$3 (ALPHABET) {
|
|
11191
|
-
if (ALPHABET.length >= 255) { throw new TypeError('Alphabet too long') }
|
|
11192
|
-
const BASE_MAP = new Uint8Array(256);
|
|
11193
|
-
for (let j = 0; j < BASE_MAP.length; j++) {
|
|
11194
|
-
BASE_MAP[j] = 255;
|
|
11195
|
-
}
|
|
11196
|
-
for (let i = 0; i < ALPHABET.length; i++) {
|
|
11197
|
-
const x = ALPHABET.charAt(i);
|
|
11198
|
-
const xc = x.charCodeAt(0);
|
|
11199
|
-
if (BASE_MAP[xc] !== 255) { throw new TypeError(x + ' is ambiguous') }
|
|
11200
|
-
BASE_MAP[xc] = i;
|
|
11201
|
-
}
|
|
11202
|
-
const BASE = ALPHABET.length;
|
|
11203
|
-
const LEADER = ALPHABET.charAt(0);
|
|
11204
|
-
const FACTOR = Math.log(BASE) / Math.log(256); // log(BASE) / log(256), rounded up
|
|
11205
|
-
const iFACTOR = Math.log(256) / Math.log(BASE); // log(256) / log(BASE), rounded up
|
|
11206
|
-
function encode (source) {
|
|
11207
|
-
// eslint-disable-next-line no-empty
|
|
11208
|
-
if (source instanceof Uint8Array) ; else if (ArrayBuffer.isView(source)) {
|
|
11209
|
-
source = new Uint8Array(source.buffer, source.byteOffset, source.byteLength);
|
|
11210
|
-
} else if (Array.isArray(source)) {
|
|
11211
|
-
source = Uint8Array.from(source);
|
|
11212
|
-
}
|
|
11213
|
-
if (!(source instanceof Uint8Array)) { throw new TypeError('Expected Uint8Array') }
|
|
11214
|
-
if (source.length === 0) { return '' }
|
|
11215
|
-
// Skip & count leading zeroes.
|
|
11216
|
-
let zeroes = 0;
|
|
11217
|
-
let length = 0;
|
|
11218
|
-
let pbegin = 0;
|
|
11219
|
-
const pend = source.length;
|
|
11220
|
-
while (pbegin !== pend && source[pbegin] === 0) {
|
|
11221
|
-
pbegin++;
|
|
11222
|
-
zeroes++;
|
|
11223
|
-
}
|
|
11224
|
-
// Allocate enough space in big-endian base58 representation.
|
|
11225
|
-
const size = ((pend - pbegin) * iFACTOR + 1) >>> 0;
|
|
11226
|
-
const b58 = new Uint8Array(size);
|
|
11227
|
-
// Process the bytes.
|
|
11228
|
-
while (pbegin !== pend) {
|
|
11229
|
-
let carry = source[pbegin];
|
|
11230
|
-
// Apply "b58 = b58 * 256 + ch".
|
|
11231
|
-
let i = 0;
|
|
11232
|
-
for (let it1 = size - 1; (carry !== 0 || i < length) && (it1 !== -1); it1--, i++) {
|
|
11233
|
-
carry += (256 * b58[it1]) >>> 0;
|
|
11234
|
-
b58[it1] = (carry % BASE) >>> 0;
|
|
11235
|
-
carry = (carry / BASE) >>> 0;
|
|
11236
|
-
}
|
|
11237
|
-
if (carry !== 0) { throw new Error('Non-zero carry') }
|
|
11238
|
-
length = i;
|
|
11239
|
-
pbegin++;
|
|
11240
|
-
}
|
|
11241
|
-
// Skip leading zeroes in base58 result.
|
|
11242
|
-
let it2 = size - length;
|
|
11243
|
-
while (it2 !== size && b58[it2] === 0) {
|
|
11244
|
-
it2++;
|
|
11245
|
-
}
|
|
11246
|
-
// Translate the result into a string.
|
|
11247
|
-
let str = LEADER.repeat(zeroes);
|
|
11248
|
-
for (; it2 < size; ++it2) { str += ALPHABET.charAt(b58[it2]); }
|
|
11249
|
-
return str
|
|
11250
|
-
}
|
|
11251
|
-
function decodeUnsafe (source) {
|
|
11252
|
-
if (typeof source !== 'string') { throw new TypeError('Expected String') }
|
|
11253
|
-
if (source.length === 0) { return new Uint8Array() }
|
|
11254
|
-
let psz = 0;
|
|
11255
|
-
// Skip and count leading '1's.
|
|
11256
|
-
let zeroes = 0;
|
|
11257
|
-
let length = 0;
|
|
11258
|
-
while (source[psz] === LEADER) {
|
|
11259
|
-
zeroes++;
|
|
11260
|
-
psz++;
|
|
11261
|
-
}
|
|
11262
|
-
// Allocate enough space in big-endian base256 representation.
|
|
11263
|
-
const size = (((source.length - psz) * FACTOR) + 1) >>> 0; // log(58) / log(256), rounded up.
|
|
11264
|
-
const b256 = new Uint8Array(size);
|
|
11265
|
-
// Process the characters.
|
|
11266
|
-
while (psz < source.length) {
|
|
11267
|
-
// Find code of next character
|
|
11268
|
-
const charCode = source.charCodeAt(psz);
|
|
11269
|
-
// Base map can not be indexed using char code
|
|
11270
|
-
if (charCode > 255) { return }
|
|
11271
|
-
// Decode character
|
|
11272
|
-
let carry = BASE_MAP[charCode];
|
|
11273
|
-
// Invalid character
|
|
11274
|
-
if (carry === 255) { return }
|
|
11275
|
-
let i = 0;
|
|
11276
|
-
for (let it3 = size - 1; (carry !== 0 || i < length) && (it3 !== -1); it3--, i++) {
|
|
11277
|
-
carry += (BASE * b256[it3]) >>> 0;
|
|
11278
|
-
b256[it3] = (carry % 256) >>> 0;
|
|
11279
|
-
carry = (carry / 256) >>> 0;
|
|
11280
|
-
}
|
|
11281
|
-
if (carry !== 0) { throw new Error('Non-zero carry') }
|
|
11282
|
-
length = i;
|
|
11283
|
-
psz++;
|
|
11284
|
-
}
|
|
11285
|
-
// Skip leading zeroes in b256.
|
|
11286
|
-
let it4 = size - length;
|
|
11287
|
-
while (it4 !== size && b256[it4] === 0) {
|
|
11288
|
-
it4++;
|
|
11289
|
-
}
|
|
11290
|
-
const vch = new Uint8Array(zeroes + (size - it4));
|
|
11291
|
-
let j = zeroes;
|
|
11292
|
-
while (it4 !== size) {
|
|
11293
|
-
vch[j++] = b256[it4++];
|
|
11294
|
-
}
|
|
11295
|
-
return vch
|
|
11296
|
-
}
|
|
11297
|
-
function decode (string) {
|
|
11298
|
-
const buffer = decodeUnsafe(string);
|
|
11299
|
-
if (buffer) { return buffer }
|
|
11300
|
-
throw new Error('Non-base' + BASE + ' character')
|
|
11301
|
-
}
|
|
11302
|
-
return {
|
|
11303
|
-
encode,
|
|
11304
|
-
decodeUnsafe,
|
|
11305
|
-
decode
|
|
11306
|
-
}
|
|
11307
|
-
}
|
|
11308
|
-
|
|
11309
|
-
var ALPHABET$3 = '123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz';
|
|
11310
|
-
var bs58$2 = base$3(ALPHABET$3);
|
|
11311
|
-
|
|
11312
8634
|
// src/index.ts
|
|
11313
8635
|
function parseSignMessageResponse(base64Response, networkId) {
|
|
11314
8636
|
const networkPrefix = networkId.split(":")[0].toLowerCase();
|
|
@@ -11355,7 +8677,7 @@ function parseTransactionResponse(base64RawTransaction, networkId, hash) {
|
|
|
11355
8677
|
function parseSolanaSignatureResponse(base64Response) {
|
|
11356
8678
|
try {
|
|
11357
8679
|
const signatureBytes = base64urlDecode(base64Response);
|
|
11358
|
-
const signature =
|
|
8680
|
+
const signature = base58.encode(signatureBytes);
|
|
11359
8681
|
return {
|
|
11360
8682
|
signature,
|
|
11361
8683
|
rawSignature: base64Response
|
|
@@ -11595,260 +8917,6 @@ function parseBitcoinTransactionToBase64Url(transaction) {
|
|
|
11595
8917
|
throw new Error("Unsupported Bitcoin transaction format");
|
|
11596
8918
|
}
|
|
11597
8919
|
|
|
11598
|
-
// base-x encoding / decoding
|
|
11599
|
-
// Copyright (c) 2018 base-x contributors
|
|
11600
|
-
// Copyright (c) 2014-2018 The Bitcoin Core developers (base58.cpp)
|
|
11601
|
-
// Distributed under the MIT software license, see the accompanying
|
|
11602
|
-
// file LICENSE or http://www.opensource.org/licenses/mit-license.php.
|
|
11603
|
-
function base$2 (ALPHABET) {
|
|
11604
|
-
if (ALPHABET.length >= 255) { throw new TypeError('Alphabet too long') }
|
|
11605
|
-
const BASE_MAP = new Uint8Array(256);
|
|
11606
|
-
for (let j = 0; j < BASE_MAP.length; j++) {
|
|
11607
|
-
BASE_MAP[j] = 255;
|
|
11608
|
-
}
|
|
11609
|
-
for (let i = 0; i < ALPHABET.length; i++) {
|
|
11610
|
-
const x = ALPHABET.charAt(i);
|
|
11611
|
-
const xc = x.charCodeAt(0);
|
|
11612
|
-
if (BASE_MAP[xc] !== 255) { throw new TypeError(x + ' is ambiguous') }
|
|
11613
|
-
BASE_MAP[xc] = i;
|
|
11614
|
-
}
|
|
11615
|
-
const BASE = ALPHABET.length;
|
|
11616
|
-
const LEADER = ALPHABET.charAt(0);
|
|
11617
|
-
const FACTOR = Math.log(BASE) / Math.log(256); // log(BASE) / log(256), rounded up
|
|
11618
|
-
const iFACTOR = Math.log(256) / Math.log(BASE); // log(256) / log(BASE), rounded up
|
|
11619
|
-
function encode (source) {
|
|
11620
|
-
// eslint-disable-next-line no-empty
|
|
11621
|
-
if (source instanceof Uint8Array) ; else if (ArrayBuffer.isView(source)) {
|
|
11622
|
-
source = new Uint8Array(source.buffer, source.byteOffset, source.byteLength);
|
|
11623
|
-
} else if (Array.isArray(source)) {
|
|
11624
|
-
source = Uint8Array.from(source);
|
|
11625
|
-
}
|
|
11626
|
-
if (!(source instanceof Uint8Array)) { throw new TypeError('Expected Uint8Array') }
|
|
11627
|
-
if (source.length === 0) { return '' }
|
|
11628
|
-
// Skip & count leading zeroes.
|
|
11629
|
-
let zeroes = 0;
|
|
11630
|
-
let length = 0;
|
|
11631
|
-
let pbegin = 0;
|
|
11632
|
-
const pend = source.length;
|
|
11633
|
-
while (pbegin !== pend && source[pbegin] === 0) {
|
|
11634
|
-
pbegin++;
|
|
11635
|
-
zeroes++;
|
|
11636
|
-
}
|
|
11637
|
-
// Allocate enough space in big-endian base58 representation.
|
|
11638
|
-
const size = ((pend - pbegin) * iFACTOR + 1) >>> 0;
|
|
11639
|
-
const b58 = new Uint8Array(size);
|
|
11640
|
-
// Process the bytes.
|
|
11641
|
-
while (pbegin !== pend) {
|
|
11642
|
-
let carry = source[pbegin];
|
|
11643
|
-
// Apply "b58 = b58 * 256 + ch".
|
|
11644
|
-
let i = 0;
|
|
11645
|
-
for (let it1 = size - 1; (carry !== 0 || i < length) && (it1 !== -1); it1--, i++) {
|
|
11646
|
-
carry += (256 * b58[it1]) >>> 0;
|
|
11647
|
-
b58[it1] = (carry % BASE) >>> 0;
|
|
11648
|
-
carry = (carry / BASE) >>> 0;
|
|
11649
|
-
}
|
|
11650
|
-
if (carry !== 0) { throw new Error('Non-zero carry') }
|
|
11651
|
-
length = i;
|
|
11652
|
-
pbegin++;
|
|
11653
|
-
}
|
|
11654
|
-
// Skip leading zeroes in base58 result.
|
|
11655
|
-
let it2 = size - length;
|
|
11656
|
-
while (it2 !== size && b58[it2] === 0) {
|
|
11657
|
-
it2++;
|
|
11658
|
-
}
|
|
11659
|
-
// Translate the result into a string.
|
|
11660
|
-
let str = LEADER.repeat(zeroes);
|
|
11661
|
-
for (; it2 < size; ++it2) { str += ALPHABET.charAt(b58[it2]); }
|
|
11662
|
-
return str
|
|
11663
|
-
}
|
|
11664
|
-
function decodeUnsafe (source) {
|
|
11665
|
-
if (typeof source !== 'string') { throw new TypeError('Expected String') }
|
|
11666
|
-
if (source.length === 0) { return new Uint8Array() }
|
|
11667
|
-
let psz = 0;
|
|
11668
|
-
// Skip and count leading '1's.
|
|
11669
|
-
let zeroes = 0;
|
|
11670
|
-
let length = 0;
|
|
11671
|
-
while (source[psz] === LEADER) {
|
|
11672
|
-
zeroes++;
|
|
11673
|
-
psz++;
|
|
11674
|
-
}
|
|
11675
|
-
// Allocate enough space in big-endian base256 representation.
|
|
11676
|
-
const size = (((source.length - psz) * FACTOR) + 1) >>> 0; // log(58) / log(256), rounded up.
|
|
11677
|
-
const b256 = new Uint8Array(size);
|
|
11678
|
-
// Process the characters.
|
|
11679
|
-
while (psz < source.length) {
|
|
11680
|
-
// Find code of next character
|
|
11681
|
-
const charCode = source.charCodeAt(psz);
|
|
11682
|
-
// Base map can not be indexed using char code
|
|
11683
|
-
if (charCode > 255) { return }
|
|
11684
|
-
// Decode character
|
|
11685
|
-
let carry = BASE_MAP[charCode];
|
|
11686
|
-
// Invalid character
|
|
11687
|
-
if (carry === 255) { return }
|
|
11688
|
-
let i = 0;
|
|
11689
|
-
for (let it3 = size - 1; (carry !== 0 || i < length) && (it3 !== -1); it3--, i++) {
|
|
11690
|
-
carry += (BASE * b256[it3]) >>> 0;
|
|
11691
|
-
b256[it3] = (carry % 256) >>> 0;
|
|
11692
|
-
carry = (carry / 256) >>> 0;
|
|
11693
|
-
}
|
|
11694
|
-
if (carry !== 0) { throw new Error('Non-zero carry') }
|
|
11695
|
-
length = i;
|
|
11696
|
-
psz++;
|
|
11697
|
-
}
|
|
11698
|
-
// Skip leading zeroes in b256.
|
|
11699
|
-
let it4 = size - length;
|
|
11700
|
-
while (it4 !== size && b256[it4] === 0) {
|
|
11701
|
-
it4++;
|
|
11702
|
-
}
|
|
11703
|
-
const vch = new Uint8Array(zeroes + (size - it4));
|
|
11704
|
-
let j = zeroes;
|
|
11705
|
-
while (it4 !== size) {
|
|
11706
|
-
vch[j++] = b256[it4++];
|
|
11707
|
-
}
|
|
11708
|
-
return vch
|
|
11709
|
-
}
|
|
11710
|
-
function decode (string) {
|
|
11711
|
-
const buffer = decodeUnsafe(string);
|
|
11712
|
-
if (buffer) { return buffer }
|
|
11713
|
-
throw new Error('Non-base' + BASE + ' character')
|
|
11714
|
-
}
|
|
11715
|
-
return {
|
|
11716
|
-
encode,
|
|
11717
|
-
decodeUnsafe,
|
|
11718
|
-
decode
|
|
11719
|
-
}
|
|
11720
|
-
}
|
|
11721
|
-
|
|
11722
|
-
var ALPHABET$2 = '123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz';
|
|
11723
|
-
var bs58$1 = base$2(ALPHABET$2);
|
|
11724
|
-
|
|
11725
|
-
// base-x encoding / decoding
|
|
11726
|
-
// Copyright (c) 2018 base-x contributors
|
|
11727
|
-
// Copyright (c) 2014-2018 The Bitcoin Core developers (base58.cpp)
|
|
11728
|
-
// Distributed under the MIT software license, see the accompanying
|
|
11729
|
-
// file LICENSE or http://www.opensource.org/licenses/mit-license.php.
|
|
11730
|
-
function base$1 (ALPHABET) {
|
|
11731
|
-
if (ALPHABET.length >= 255) { throw new TypeError('Alphabet too long') }
|
|
11732
|
-
const BASE_MAP = new Uint8Array(256);
|
|
11733
|
-
for (let j = 0; j < BASE_MAP.length; j++) {
|
|
11734
|
-
BASE_MAP[j] = 255;
|
|
11735
|
-
}
|
|
11736
|
-
for (let i = 0; i < ALPHABET.length; i++) {
|
|
11737
|
-
const x = ALPHABET.charAt(i);
|
|
11738
|
-
const xc = x.charCodeAt(0);
|
|
11739
|
-
if (BASE_MAP[xc] !== 255) { throw new TypeError(x + ' is ambiguous') }
|
|
11740
|
-
BASE_MAP[xc] = i;
|
|
11741
|
-
}
|
|
11742
|
-
const BASE = ALPHABET.length;
|
|
11743
|
-
const LEADER = ALPHABET.charAt(0);
|
|
11744
|
-
const FACTOR = Math.log(BASE) / Math.log(256); // log(BASE) / log(256), rounded up
|
|
11745
|
-
const iFACTOR = Math.log(256) / Math.log(BASE); // log(256) / log(BASE), rounded up
|
|
11746
|
-
function encode (source) {
|
|
11747
|
-
// eslint-disable-next-line no-empty
|
|
11748
|
-
if (source instanceof Uint8Array) ; else if (ArrayBuffer.isView(source)) {
|
|
11749
|
-
source = new Uint8Array(source.buffer, source.byteOffset, source.byteLength);
|
|
11750
|
-
} else if (Array.isArray(source)) {
|
|
11751
|
-
source = Uint8Array.from(source);
|
|
11752
|
-
}
|
|
11753
|
-
if (!(source instanceof Uint8Array)) { throw new TypeError('Expected Uint8Array') }
|
|
11754
|
-
if (source.length === 0) { return '' }
|
|
11755
|
-
// Skip & count leading zeroes.
|
|
11756
|
-
let zeroes = 0;
|
|
11757
|
-
let length = 0;
|
|
11758
|
-
let pbegin = 0;
|
|
11759
|
-
const pend = source.length;
|
|
11760
|
-
while (pbegin !== pend && source[pbegin] === 0) {
|
|
11761
|
-
pbegin++;
|
|
11762
|
-
zeroes++;
|
|
11763
|
-
}
|
|
11764
|
-
// Allocate enough space in big-endian base58 representation.
|
|
11765
|
-
const size = ((pend - pbegin) * iFACTOR + 1) >>> 0;
|
|
11766
|
-
const b58 = new Uint8Array(size);
|
|
11767
|
-
// Process the bytes.
|
|
11768
|
-
while (pbegin !== pend) {
|
|
11769
|
-
let carry = source[pbegin];
|
|
11770
|
-
// Apply "b58 = b58 * 256 + ch".
|
|
11771
|
-
let i = 0;
|
|
11772
|
-
for (let it1 = size - 1; (carry !== 0 || i < length) && (it1 !== -1); it1--, i++) {
|
|
11773
|
-
carry += (256 * b58[it1]) >>> 0;
|
|
11774
|
-
b58[it1] = (carry % BASE) >>> 0;
|
|
11775
|
-
carry = (carry / BASE) >>> 0;
|
|
11776
|
-
}
|
|
11777
|
-
if (carry !== 0) { throw new Error('Non-zero carry') }
|
|
11778
|
-
length = i;
|
|
11779
|
-
pbegin++;
|
|
11780
|
-
}
|
|
11781
|
-
// Skip leading zeroes in base58 result.
|
|
11782
|
-
let it2 = size - length;
|
|
11783
|
-
while (it2 !== size && b58[it2] === 0) {
|
|
11784
|
-
it2++;
|
|
11785
|
-
}
|
|
11786
|
-
// Translate the result into a string.
|
|
11787
|
-
let str = LEADER.repeat(zeroes);
|
|
11788
|
-
for (; it2 < size; ++it2) { str += ALPHABET.charAt(b58[it2]); }
|
|
11789
|
-
return str
|
|
11790
|
-
}
|
|
11791
|
-
function decodeUnsafe (source) {
|
|
11792
|
-
if (typeof source !== 'string') { throw new TypeError('Expected String') }
|
|
11793
|
-
if (source.length === 0) { return new Uint8Array() }
|
|
11794
|
-
let psz = 0;
|
|
11795
|
-
// Skip and count leading '1's.
|
|
11796
|
-
let zeroes = 0;
|
|
11797
|
-
let length = 0;
|
|
11798
|
-
while (source[psz] === LEADER) {
|
|
11799
|
-
zeroes++;
|
|
11800
|
-
psz++;
|
|
11801
|
-
}
|
|
11802
|
-
// Allocate enough space in big-endian base256 representation.
|
|
11803
|
-
const size = (((source.length - psz) * FACTOR) + 1) >>> 0; // log(58) / log(256), rounded up.
|
|
11804
|
-
const b256 = new Uint8Array(size);
|
|
11805
|
-
// Process the characters.
|
|
11806
|
-
while (psz < source.length) {
|
|
11807
|
-
// Find code of next character
|
|
11808
|
-
const charCode = source.charCodeAt(psz);
|
|
11809
|
-
// Base map can not be indexed using char code
|
|
11810
|
-
if (charCode > 255) { return }
|
|
11811
|
-
// Decode character
|
|
11812
|
-
let carry = BASE_MAP[charCode];
|
|
11813
|
-
// Invalid character
|
|
11814
|
-
if (carry === 255) { return }
|
|
11815
|
-
let i = 0;
|
|
11816
|
-
for (let it3 = size - 1; (carry !== 0 || i < length) && (it3 !== -1); it3--, i++) {
|
|
11817
|
-
carry += (BASE * b256[it3]) >>> 0;
|
|
11818
|
-
b256[it3] = (carry % 256) >>> 0;
|
|
11819
|
-
carry = (carry / 256) >>> 0;
|
|
11820
|
-
}
|
|
11821
|
-
if (carry !== 0) { throw new Error('Non-zero carry') }
|
|
11822
|
-
length = i;
|
|
11823
|
-
psz++;
|
|
11824
|
-
}
|
|
11825
|
-
// Skip leading zeroes in b256.
|
|
11826
|
-
let it4 = size - length;
|
|
11827
|
-
while (it4 !== size && b256[it4] === 0) {
|
|
11828
|
-
it4++;
|
|
11829
|
-
}
|
|
11830
|
-
const vch = new Uint8Array(zeroes + (size - it4));
|
|
11831
|
-
let j = zeroes;
|
|
11832
|
-
while (it4 !== size) {
|
|
11833
|
-
vch[j++] = b256[it4++];
|
|
11834
|
-
}
|
|
11835
|
-
return vch
|
|
11836
|
-
}
|
|
11837
|
-
function decode (string) {
|
|
11838
|
-
const buffer = decodeUnsafe(string);
|
|
11839
|
-
if (buffer) { return buffer }
|
|
11840
|
-
throw new Error('Non-base' + BASE + ' character')
|
|
11841
|
-
}
|
|
11842
|
-
return {
|
|
11843
|
-
encode,
|
|
11844
|
-
decodeUnsafe,
|
|
11845
|
-
decode
|
|
11846
|
-
}
|
|
11847
|
-
}
|
|
11848
|
-
|
|
11849
|
-
var ALPHABET$1 = '123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz';
|
|
11850
|
-
var bs582 = base$1(ALPHABET$1);
|
|
11851
|
-
|
|
11852
8920
|
var eventemitter3 = {exports: {}};
|
|
11853
8921
|
|
|
11854
8922
|
var hasRequiredEventemitter3;
|
|
@@ -12234,7 +9302,7 @@ var EmbeddedSolanaChain = class {
|
|
|
12234
9302
|
message: messageStr,
|
|
12235
9303
|
networkId: this.currentNetworkId
|
|
12236
9304
|
});
|
|
12237
|
-
const signature = typeof result.signature === "string" ? new Uint8Array(
|
|
9305
|
+
const signature = typeof result.signature === "string" ? new Uint8Array(base58.decode(result.signature)) : result.signature;
|
|
12238
9306
|
return {
|
|
12239
9307
|
signature,
|
|
12240
9308
|
publicKey: this._publicKey || ""
|
|
@@ -12917,7 +9985,7 @@ var EmbeddedProvider$1 = class EmbeddedProvider {
|
|
|
12917
9985
|
publicKey: stamperInfo.publicKey,
|
|
12918
9986
|
platform: platformName
|
|
12919
9987
|
});
|
|
12920
|
-
const base64urlPublicKey = base64urlEncode(
|
|
9988
|
+
const base64urlPublicKey = base64urlEncode(base58.decode(stamperInfo.publicKey));
|
|
12921
9989
|
const username = `user-${randomUUID()}`;
|
|
12922
9990
|
const { organizationId } = await tempClient.createOrganization(organizationName, [
|
|
12923
9991
|
{
|
|
@@ -13506,133 +10574,6 @@ var EmbeddedProvider$1 = class EmbeddedProvider {
|
|
|
13506
10574
|
}
|
|
13507
10575
|
};
|
|
13508
10576
|
|
|
13509
|
-
// base-x encoding / decoding
|
|
13510
|
-
// Copyright (c) 2018 base-x contributors
|
|
13511
|
-
// Copyright (c) 2014-2018 The Bitcoin Core developers (base58.cpp)
|
|
13512
|
-
// Distributed under the MIT software license, see the accompanying
|
|
13513
|
-
// file LICENSE or http://www.opensource.org/licenses/mit-license.php.
|
|
13514
|
-
function base (ALPHABET) {
|
|
13515
|
-
if (ALPHABET.length >= 255) { throw new TypeError('Alphabet too long') }
|
|
13516
|
-
const BASE_MAP = new Uint8Array(256);
|
|
13517
|
-
for (let j = 0; j < BASE_MAP.length; j++) {
|
|
13518
|
-
BASE_MAP[j] = 255;
|
|
13519
|
-
}
|
|
13520
|
-
for (let i = 0; i < ALPHABET.length; i++) {
|
|
13521
|
-
const x = ALPHABET.charAt(i);
|
|
13522
|
-
const xc = x.charCodeAt(0);
|
|
13523
|
-
if (BASE_MAP[xc] !== 255) { throw new TypeError(x + ' is ambiguous') }
|
|
13524
|
-
BASE_MAP[xc] = i;
|
|
13525
|
-
}
|
|
13526
|
-
const BASE = ALPHABET.length;
|
|
13527
|
-
const LEADER = ALPHABET.charAt(0);
|
|
13528
|
-
const FACTOR = Math.log(BASE) / Math.log(256); // log(BASE) / log(256), rounded up
|
|
13529
|
-
const iFACTOR = Math.log(256) / Math.log(BASE); // log(256) / log(BASE), rounded up
|
|
13530
|
-
function encode (source) {
|
|
13531
|
-
// eslint-disable-next-line no-empty
|
|
13532
|
-
if (source instanceof Uint8Array) ; else if (ArrayBuffer.isView(source)) {
|
|
13533
|
-
source = new Uint8Array(source.buffer, source.byteOffset, source.byteLength);
|
|
13534
|
-
} else if (Array.isArray(source)) {
|
|
13535
|
-
source = Uint8Array.from(source);
|
|
13536
|
-
}
|
|
13537
|
-
if (!(source instanceof Uint8Array)) { throw new TypeError('Expected Uint8Array') }
|
|
13538
|
-
if (source.length === 0) { return '' }
|
|
13539
|
-
// Skip & count leading zeroes.
|
|
13540
|
-
let zeroes = 0;
|
|
13541
|
-
let length = 0;
|
|
13542
|
-
let pbegin = 0;
|
|
13543
|
-
const pend = source.length;
|
|
13544
|
-
while (pbegin !== pend && source[pbegin] === 0) {
|
|
13545
|
-
pbegin++;
|
|
13546
|
-
zeroes++;
|
|
13547
|
-
}
|
|
13548
|
-
// Allocate enough space in big-endian base58 representation.
|
|
13549
|
-
const size = ((pend - pbegin) * iFACTOR + 1) >>> 0;
|
|
13550
|
-
const b58 = new Uint8Array(size);
|
|
13551
|
-
// Process the bytes.
|
|
13552
|
-
while (pbegin !== pend) {
|
|
13553
|
-
let carry = source[pbegin];
|
|
13554
|
-
// Apply "b58 = b58 * 256 + ch".
|
|
13555
|
-
let i = 0;
|
|
13556
|
-
for (let it1 = size - 1; (carry !== 0 || i < length) && (it1 !== -1); it1--, i++) {
|
|
13557
|
-
carry += (256 * b58[it1]) >>> 0;
|
|
13558
|
-
b58[it1] = (carry % BASE) >>> 0;
|
|
13559
|
-
carry = (carry / BASE) >>> 0;
|
|
13560
|
-
}
|
|
13561
|
-
if (carry !== 0) { throw new Error('Non-zero carry') }
|
|
13562
|
-
length = i;
|
|
13563
|
-
pbegin++;
|
|
13564
|
-
}
|
|
13565
|
-
// Skip leading zeroes in base58 result.
|
|
13566
|
-
let it2 = size - length;
|
|
13567
|
-
while (it2 !== size && b58[it2] === 0) {
|
|
13568
|
-
it2++;
|
|
13569
|
-
}
|
|
13570
|
-
// Translate the result into a string.
|
|
13571
|
-
let str = LEADER.repeat(zeroes);
|
|
13572
|
-
for (; it2 < size; ++it2) { str += ALPHABET.charAt(b58[it2]); }
|
|
13573
|
-
return str
|
|
13574
|
-
}
|
|
13575
|
-
function decodeUnsafe (source) {
|
|
13576
|
-
if (typeof source !== 'string') { throw new TypeError('Expected String') }
|
|
13577
|
-
if (source.length === 0) { return new Uint8Array() }
|
|
13578
|
-
let psz = 0;
|
|
13579
|
-
// Skip and count leading '1's.
|
|
13580
|
-
let zeroes = 0;
|
|
13581
|
-
let length = 0;
|
|
13582
|
-
while (source[psz] === LEADER) {
|
|
13583
|
-
zeroes++;
|
|
13584
|
-
psz++;
|
|
13585
|
-
}
|
|
13586
|
-
// Allocate enough space in big-endian base256 representation.
|
|
13587
|
-
const size = (((source.length - psz) * FACTOR) + 1) >>> 0; // log(58) / log(256), rounded up.
|
|
13588
|
-
const b256 = new Uint8Array(size);
|
|
13589
|
-
// Process the characters.
|
|
13590
|
-
while (psz < source.length) {
|
|
13591
|
-
// Find code of next character
|
|
13592
|
-
const charCode = source.charCodeAt(psz);
|
|
13593
|
-
// Base map can not be indexed using char code
|
|
13594
|
-
if (charCode > 255) { return }
|
|
13595
|
-
// Decode character
|
|
13596
|
-
let carry = BASE_MAP[charCode];
|
|
13597
|
-
// Invalid character
|
|
13598
|
-
if (carry === 255) { return }
|
|
13599
|
-
let i = 0;
|
|
13600
|
-
for (let it3 = size - 1; (carry !== 0 || i < length) && (it3 !== -1); it3--, i++) {
|
|
13601
|
-
carry += (BASE * b256[it3]) >>> 0;
|
|
13602
|
-
b256[it3] = (carry % 256) >>> 0;
|
|
13603
|
-
carry = (carry / 256) >>> 0;
|
|
13604
|
-
}
|
|
13605
|
-
if (carry !== 0) { throw new Error('Non-zero carry') }
|
|
13606
|
-
length = i;
|
|
13607
|
-
psz++;
|
|
13608
|
-
}
|
|
13609
|
-
// Skip leading zeroes in b256.
|
|
13610
|
-
let it4 = size - length;
|
|
13611
|
-
while (it4 !== size && b256[it4] === 0) {
|
|
13612
|
-
it4++;
|
|
13613
|
-
}
|
|
13614
|
-
const vch = new Uint8Array(zeroes + (size - it4));
|
|
13615
|
-
let j = zeroes;
|
|
13616
|
-
while (it4 !== size) {
|
|
13617
|
-
vch[j++] = b256[it4++];
|
|
13618
|
-
}
|
|
13619
|
-
return vch
|
|
13620
|
-
}
|
|
13621
|
-
function decode (string) {
|
|
13622
|
-
const buffer = decodeUnsafe(string);
|
|
13623
|
-
if (buffer) { return buffer }
|
|
13624
|
-
throw new Error('Non-base' + BASE + ' character')
|
|
13625
|
-
}
|
|
13626
|
-
return {
|
|
13627
|
-
encode,
|
|
13628
|
-
decodeUnsafe,
|
|
13629
|
-
decode
|
|
13630
|
-
}
|
|
13631
|
-
}
|
|
13632
|
-
|
|
13633
|
-
var ALPHABET = '123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz';
|
|
13634
|
-
var bs58 = base(ALPHABET);
|
|
13635
|
-
|
|
13636
10577
|
// src/index.ts
|
|
13637
10578
|
var IndexedDbStamper = class {
|
|
13638
10579
|
// Optional for PKI, required for OIDC
|
|
@@ -13706,14 +10647,14 @@ var IndexedDbStamper = class {
|
|
|
13706
10647
|
const salt = params.type === "OIDC" ? params.salt : this.salt;
|
|
13707
10648
|
const stampData = stampType === "PKI" ? {
|
|
13708
10649
|
// Decode base58 public key to bytes, then encode as base64url (consistent with ApiKeyStamper)
|
|
13709
|
-
publicKey: base64urlEncode(
|
|
10650
|
+
publicKey: base64urlEncode(base58.decode(this.activeKeyPairRecord.keyInfo.publicKey)),
|
|
13710
10651
|
signature: signatureBase64url,
|
|
13711
10652
|
kind: "PKI",
|
|
13712
10653
|
algorithm: this.algorithm
|
|
13713
10654
|
} : {
|
|
13714
10655
|
kind: "OIDC",
|
|
13715
10656
|
idToken,
|
|
13716
|
-
publicKey: base64urlEncode(
|
|
10657
|
+
publicKey: base64urlEncode(base58.decode(this.activeKeyPairRecord.keyInfo.publicKey)),
|
|
13717
10658
|
salt,
|
|
13718
10659
|
algorithm: this.algorithm,
|
|
13719
10660
|
signature: signatureBase64url
|
|
@@ -13816,7 +10757,7 @@ var IndexedDbStamper = class {
|
|
|
13816
10757
|
["sign", "verify"]
|
|
13817
10758
|
);
|
|
13818
10759
|
const rawPublicKeyBuffer = await crypto.subtle.exportKey("raw", keyPair.publicKey);
|
|
13819
|
-
const publicKeyBase58 =
|
|
10760
|
+
const publicKeyBase58 = base58.encode(new Uint8Array(rawPublicKeyBuffer));
|
|
13820
10761
|
const keyIdBuffer = await crypto.subtle.digest("SHA-256", rawPublicKeyBuffer);
|
|
13821
10762
|
const keyId = base64urlEncode(new Uint8Array(keyIdBuffer)).substring(0, 16);
|
|
13822
10763
|
const now = Date.now();
|
|
@@ -14735,7 +11676,7 @@ var WalletStandardSolanaAdapter = class {
|
|
|
14735
11676
|
throw new Error("No signature found in signAndSendTransaction result");
|
|
14736
11677
|
}
|
|
14737
11678
|
const signatureBytes = this.parseUint8Array(signatureOutput.signature);
|
|
14738
|
-
const signature =
|
|
11679
|
+
const signature = base58.encode(signatureBytes);
|
|
14739
11680
|
return { signature };
|
|
14740
11681
|
} catch (error) {
|
|
14741
11682
|
debug.error(DebugCategory.INJECTED_PROVIDER, "Wallet Standard Solana signAndSendTransaction failed", {
|
|
@@ -19146,4 +16087,4 @@ function ConnectBox({ maxWidth = "350px", transparent = false, appIcon, appName
|
|
|
19146
16087
|
}
|
|
19147
16088
|
|
|
19148
16089
|
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 };
|
|
19149
|
-
//# sourceMappingURL=index-
|
|
16090
|
+
//# sourceMappingURL=index-CpaP1yGp.esm.js.map
|