@pooflabs/web 0.0.57 → 0.0.59
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-iG3iHW2H.esm.js → index-B1INQP2H.esm.js} +756 -3082
- package/dist/index-B1INQP2H.esm.js.map +1 -0
- package/dist/{index-OppCl1Ve.js → index-BGYQ_HzF.js} +756 -3082
- package/dist/index-BGYQ_HzF.js.map +1 -0
- package/dist/{index-ipxXG26r.esm.js → index-C9sapvtl.esm.js} +220 -67
- package/dist/index-C9sapvtl.esm.js.map +1 -0
- package/dist/{index-DFi8Tb9p.js → index-DZfjvlS2.js} +220 -69
- package/dist/index-DZfjvlS2.js.map +1 -0
- package/dist/index.esm.js +1 -1
- package/dist/index.js +1 -1
- package/package.json +3 -3
- package/dist/index-DFi8Tb9p.js.map +0 -1
- package/dist/index-OppCl1Ve.js.map +0 -1
- package/dist/index-iG3iHW2H.esm.js.map +0 -1
- package/dist/index-ipxXG26r.esm.js.map +0 -1
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import * as React from 'react';
|
|
2
2
|
import { useContext, createContext, useState, useMemo, useRef, useEffect, useCallback } from 'react';
|
|
3
3
|
import globalAxios, { isAxiosError } from 'axios';
|
|
4
|
-
import {
|
|
4
|
+
import { b as bufferExports, a as bs58$1, E as EventEmitter3 } from './index-C9sapvtl.esm.js';
|
|
5
5
|
import { Transaction as Transaction$1, VersionedTransaction } from '@solana/web3.js';
|
|
6
6
|
import { jsx, jsxs, Fragment } from 'react/jsx-runtime';
|
|
7
7
|
import '@coral-xyz/anchor';
|
|
@@ -998,2410 +998,6 @@ function isSolanaChain(networkId) {
|
|
|
998
998
|
return network === "solana";
|
|
999
999
|
}
|
|
1000
1000
|
|
|
1001
|
-
var naclFast = {exports: {}};
|
|
1002
|
-
|
|
1003
|
-
var hasRequiredNaclFast;
|
|
1004
|
-
|
|
1005
|
-
function requireNaclFast () {
|
|
1006
|
-
if (hasRequiredNaclFast) return naclFast.exports;
|
|
1007
|
-
hasRequiredNaclFast = 1;
|
|
1008
|
-
(function (module) {
|
|
1009
|
-
(function(nacl) {
|
|
1010
|
-
|
|
1011
|
-
// Ported in 2014 by Dmitry Chestnykh and Devi Mandiri.
|
|
1012
|
-
// Public domain.
|
|
1013
|
-
//
|
|
1014
|
-
// Implementation derived from TweetNaCl version 20140427.
|
|
1015
|
-
// See for details: http://tweetnacl.cr.yp.to/
|
|
1016
|
-
|
|
1017
|
-
var gf = function(init) {
|
|
1018
|
-
var i, r = new Float64Array(16);
|
|
1019
|
-
if (init) for (i = 0; i < init.length; i++) r[i] = init[i];
|
|
1020
|
-
return r;
|
|
1021
|
-
};
|
|
1022
|
-
|
|
1023
|
-
// Pluggable, initialized in high-level API below.
|
|
1024
|
-
var randombytes = function(/* x, n */) { throw new Error('no PRNG'); };
|
|
1025
|
-
|
|
1026
|
-
var _0 = new Uint8Array(16);
|
|
1027
|
-
var _9 = new Uint8Array(32); _9[0] = 9;
|
|
1028
|
-
|
|
1029
|
-
var gf0 = gf(),
|
|
1030
|
-
gf1 = gf([1]),
|
|
1031
|
-
_121665 = gf([0xdb41, 1]),
|
|
1032
|
-
D = gf([0x78a3, 0x1359, 0x4dca, 0x75eb, 0xd8ab, 0x4141, 0x0a4d, 0x0070, 0xe898, 0x7779, 0x4079, 0x8cc7, 0xfe73, 0x2b6f, 0x6cee, 0x5203]),
|
|
1033
|
-
D2 = gf([0xf159, 0x26b2, 0x9b94, 0xebd6, 0xb156, 0x8283, 0x149a, 0x00e0, 0xd130, 0xeef3, 0x80f2, 0x198e, 0xfce7, 0x56df, 0xd9dc, 0x2406]),
|
|
1034
|
-
X = gf([0xd51a, 0x8f25, 0x2d60, 0xc956, 0xa7b2, 0x9525, 0xc760, 0x692c, 0xdc5c, 0xfdd6, 0xe231, 0xc0a4, 0x53fe, 0xcd6e, 0x36d3, 0x2169]),
|
|
1035
|
-
Y = gf([0x6658, 0x6666, 0x6666, 0x6666, 0x6666, 0x6666, 0x6666, 0x6666, 0x6666, 0x6666, 0x6666, 0x6666, 0x6666, 0x6666, 0x6666, 0x6666]),
|
|
1036
|
-
I = gf([0xa0b0, 0x4a0e, 0x1b27, 0xc4ee, 0xe478, 0xad2f, 0x1806, 0x2f43, 0xd7a7, 0x3dfb, 0x0099, 0x2b4d, 0xdf0b, 0x4fc1, 0x2480, 0x2b83]);
|
|
1037
|
-
|
|
1038
|
-
function ts64(x, i, h, l) {
|
|
1039
|
-
x[i] = (h >> 24) & 0xff;
|
|
1040
|
-
x[i+1] = (h >> 16) & 0xff;
|
|
1041
|
-
x[i+2] = (h >> 8) & 0xff;
|
|
1042
|
-
x[i+3] = h & 0xff;
|
|
1043
|
-
x[i+4] = (l >> 24) & 0xff;
|
|
1044
|
-
x[i+5] = (l >> 16) & 0xff;
|
|
1045
|
-
x[i+6] = (l >> 8) & 0xff;
|
|
1046
|
-
x[i+7] = l & 0xff;
|
|
1047
|
-
}
|
|
1048
|
-
|
|
1049
|
-
function vn(x, xi, y, yi, n) {
|
|
1050
|
-
var i,d = 0;
|
|
1051
|
-
for (i = 0; i < n; i++) d |= x[xi+i]^y[yi+i];
|
|
1052
|
-
return (1 & ((d - 1) >>> 8)) - 1;
|
|
1053
|
-
}
|
|
1054
|
-
|
|
1055
|
-
function crypto_verify_16(x, xi, y, yi) {
|
|
1056
|
-
return vn(x,xi,y,yi,16);
|
|
1057
|
-
}
|
|
1058
|
-
|
|
1059
|
-
function crypto_verify_32(x, xi, y, yi) {
|
|
1060
|
-
return vn(x,xi,y,yi,32);
|
|
1061
|
-
}
|
|
1062
|
-
|
|
1063
|
-
function core_salsa20(o, p, k, c) {
|
|
1064
|
-
var j0 = c[ 0] & 0xff | (c[ 1] & 0xff)<<8 | (c[ 2] & 0xff)<<16 | (c[ 3] & 0xff)<<24,
|
|
1065
|
-
j1 = k[ 0] & 0xff | (k[ 1] & 0xff)<<8 | (k[ 2] & 0xff)<<16 | (k[ 3] & 0xff)<<24,
|
|
1066
|
-
j2 = k[ 4] & 0xff | (k[ 5] & 0xff)<<8 | (k[ 6] & 0xff)<<16 | (k[ 7] & 0xff)<<24,
|
|
1067
|
-
j3 = k[ 8] & 0xff | (k[ 9] & 0xff)<<8 | (k[10] & 0xff)<<16 | (k[11] & 0xff)<<24,
|
|
1068
|
-
j4 = k[12] & 0xff | (k[13] & 0xff)<<8 | (k[14] & 0xff)<<16 | (k[15] & 0xff)<<24,
|
|
1069
|
-
j5 = c[ 4] & 0xff | (c[ 5] & 0xff)<<8 | (c[ 6] & 0xff)<<16 | (c[ 7] & 0xff)<<24,
|
|
1070
|
-
j6 = p[ 0] & 0xff | (p[ 1] & 0xff)<<8 | (p[ 2] & 0xff)<<16 | (p[ 3] & 0xff)<<24,
|
|
1071
|
-
j7 = p[ 4] & 0xff | (p[ 5] & 0xff)<<8 | (p[ 6] & 0xff)<<16 | (p[ 7] & 0xff)<<24,
|
|
1072
|
-
j8 = p[ 8] & 0xff | (p[ 9] & 0xff)<<8 | (p[10] & 0xff)<<16 | (p[11] & 0xff)<<24,
|
|
1073
|
-
j9 = p[12] & 0xff | (p[13] & 0xff)<<8 | (p[14] & 0xff)<<16 | (p[15] & 0xff)<<24,
|
|
1074
|
-
j10 = c[ 8] & 0xff | (c[ 9] & 0xff)<<8 | (c[10] & 0xff)<<16 | (c[11] & 0xff)<<24,
|
|
1075
|
-
j11 = k[16] & 0xff | (k[17] & 0xff)<<8 | (k[18] & 0xff)<<16 | (k[19] & 0xff)<<24,
|
|
1076
|
-
j12 = k[20] & 0xff | (k[21] & 0xff)<<8 | (k[22] & 0xff)<<16 | (k[23] & 0xff)<<24,
|
|
1077
|
-
j13 = k[24] & 0xff | (k[25] & 0xff)<<8 | (k[26] & 0xff)<<16 | (k[27] & 0xff)<<24,
|
|
1078
|
-
j14 = k[28] & 0xff | (k[29] & 0xff)<<8 | (k[30] & 0xff)<<16 | (k[31] & 0xff)<<24,
|
|
1079
|
-
j15 = c[12] & 0xff | (c[13] & 0xff)<<8 | (c[14] & 0xff)<<16 | (c[15] & 0xff)<<24;
|
|
1080
|
-
|
|
1081
|
-
var x0 = j0, x1 = j1, x2 = j2, x3 = j3, x4 = j4, x5 = j5, x6 = j6, x7 = j7,
|
|
1082
|
-
x8 = j8, x9 = j9, x10 = j10, x11 = j11, x12 = j12, x13 = j13, x14 = j14,
|
|
1083
|
-
x15 = j15, u;
|
|
1084
|
-
|
|
1085
|
-
for (var i = 0; i < 20; i += 2) {
|
|
1086
|
-
u = x0 + x12 | 0;
|
|
1087
|
-
x4 ^= u<<7 | u>>>(32-7);
|
|
1088
|
-
u = x4 + x0 | 0;
|
|
1089
|
-
x8 ^= u<<9 | u>>>(32-9);
|
|
1090
|
-
u = x8 + x4 | 0;
|
|
1091
|
-
x12 ^= u<<13 | u>>>(32-13);
|
|
1092
|
-
u = x12 + x8 | 0;
|
|
1093
|
-
x0 ^= u<<18 | u>>>(32-18);
|
|
1094
|
-
|
|
1095
|
-
u = x5 + x1 | 0;
|
|
1096
|
-
x9 ^= u<<7 | u>>>(32-7);
|
|
1097
|
-
u = x9 + x5 | 0;
|
|
1098
|
-
x13 ^= u<<9 | u>>>(32-9);
|
|
1099
|
-
u = x13 + x9 | 0;
|
|
1100
|
-
x1 ^= u<<13 | u>>>(32-13);
|
|
1101
|
-
u = x1 + x13 | 0;
|
|
1102
|
-
x5 ^= u<<18 | u>>>(32-18);
|
|
1103
|
-
|
|
1104
|
-
u = x10 + x6 | 0;
|
|
1105
|
-
x14 ^= u<<7 | u>>>(32-7);
|
|
1106
|
-
u = x14 + x10 | 0;
|
|
1107
|
-
x2 ^= u<<9 | u>>>(32-9);
|
|
1108
|
-
u = x2 + x14 | 0;
|
|
1109
|
-
x6 ^= u<<13 | u>>>(32-13);
|
|
1110
|
-
u = x6 + x2 | 0;
|
|
1111
|
-
x10 ^= u<<18 | u>>>(32-18);
|
|
1112
|
-
|
|
1113
|
-
u = x15 + x11 | 0;
|
|
1114
|
-
x3 ^= u<<7 | u>>>(32-7);
|
|
1115
|
-
u = x3 + x15 | 0;
|
|
1116
|
-
x7 ^= u<<9 | u>>>(32-9);
|
|
1117
|
-
u = x7 + x3 | 0;
|
|
1118
|
-
x11 ^= u<<13 | u>>>(32-13);
|
|
1119
|
-
u = x11 + x7 | 0;
|
|
1120
|
-
x15 ^= u<<18 | u>>>(32-18);
|
|
1121
|
-
|
|
1122
|
-
u = x0 + x3 | 0;
|
|
1123
|
-
x1 ^= u<<7 | u>>>(32-7);
|
|
1124
|
-
u = x1 + x0 | 0;
|
|
1125
|
-
x2 ^= u<<9 | u>>>(32-9);
|
|
1126
|
-
u = x2 + x1 | 0;
|
|
1127
|
-
x3 ^= u<<13 | u>>>(32-13);
|
|
1128
|
-
u = x3 + x2 | 0;
|
|
1129
|
-
x0 ^= u<<18 | u>>>(32-18);
|
|
1130
|
-
|
|
1131
|
-
u = x5 + x4 | 0;
|
|
1132
|
-
x6 ^= u<<7 | u>>>(32-7);
|
|
1133
|
-
u = x6 + x5 | 0;
|
|
1134
|
-
x7 ^= u<<9 | u>>>(32-9);
|
|
1135
|
-
u = x7 + x6 | 0;
|
|
1136
|
-
x4 ^= u<<13 | u>>>(32-13);
|
|
1137
|
-
u = x4 + x7 | 0;
|
|
1138
|
-
x5 ^= u<<18 | u>>>(32-18);
|
|
1139
|
-
|
|
1140
|
-
u = x10 + x9 | 0;
|
|
1141
|
-
x11 ^= u<<7 | u>>>(32-7);
|
|
1142
|
-
u = x11 + x10 | 0;
|
|
1143
|
-
x8 ^= u<<9 | u>>>(32-9);
|
|
1144
|
-
u = x8 + x11 | 0;
|
|
1145
|
-
x9 ^= u<<13 | u>>>(32-13);
|
|
1146
|
-
u = x9 + x8 | 0;
|
|
1147
|
-
x10 ^= u<<18 | u>>>(32-18);
|
|
1148
|
-
|
|
1149
|
-
u = x15 + x14 | 0;
|
|
1150
|
-
x12 ^= u<<7 | u>>>(32-7);
|
|
1151
|
-
u = x12 + x15 | 0;
|
|
1152
|
-
x13 ^= u<<9 | u>>>(32-9);
|
|
1153
|
-
u = x13 + x12 | 0;
|
|
1154
|
-
x14 ^= u<<13 | u>>>(32-13);
|
|
1155
|
-
u = x14 + x13 | 0;
|
|
1156
|
-
x15 ^= u<<18 | u>>>(32-18);
|
|
1157
|
-
}
|
|
1158
|
-
x0 = x0 + j0 | 0;
|
|
1159
|
-
x1 = x1 + j1 | 0;
|
|
1160
|
-
x2 = x2 + j2 | 0;
|
|
1161
|
-
x3 = x3 + j3 | 0;
|
|
1162
|
-
x4 = x4 + j4 | 0;
|
|
1163
|
-
x5 = x5 + j5 | 0;
|
|
1164
|
-
x6 = x6 + j6 | 0;
|
|
1165
|
-
x7 = x7 + j7 | 0;
|
|
1166
|
-
x8 = x8 + j8 | 0;
|
|
1167
|
-
x9 = x9 + j9 | 0;
|
|
1168
|
-
x10 = x10 + j10 | 0;
|
|
1169
|
-
x11 = x11 + j11 | 0;
|
|
1170
|
-
x12 = x12 + j12 | 0;
|
|
1171
|
-
x13 = x13 + j13 | 0;
|
|
1172
|
-
x14 = x14 + j14 | 0;
|
|
1173
|
-
x15 = x15 + j15 | 0;
|
|
1174
|
-
|
|
1175
|
-
o[ 0] = x0 >>> 0 & 0xff;
|
|
1176
|
-
o[ 1] = x0 >>> 8 & 0xff;
|
|
1177
|
-
o[ 2] = x0 >>> 16 & 0xff;
|
|
1178
|
-
o[ 3] = x0 >>> 24 & 0xff;
|
|
1179
|
-
|
|
1180
|
-
o[ 4] = x1 >>> 0 & 0xff;
|
|
1181
|
-
o[ 5] = x1 >>> 8 & 0xff;
|
|
1182
|
-
o[ 6] = x1 >>> 16 & 0xff;
|
|
1183
|
-
o[ 7] = x1 >>> 24 & 0xff;
|
|
1184
|
-
|
|
1185
|
-
o[ 8] = x2 >>> 0 & 0xff;
|
|
1186
|
-
o[ 9] = x2 >>> 8 & 0xff;
|
|
1187
|
-
o[10] = x2 >>> 16 & 0xff;
|
|
1188
|
-
o[11] = x2 >>> 24 & 0xff;
|
|
1189
|
-
|
|
1190
|
-
o[12] = x3 >>> 0 & 0xff;
|
|
1191
|
-
o[13] = x3 >>> 8 & 0xff;
|
|
1192
|
-
o[14] = x3 >>> 16 & 0xff;
|
|
1193
|
-
o[15] = x3 >>> 24 & 0xff;
|
|
1194
|
-
|
|
1195
|
-
o[16] = x4 >>> 0 & 0xff;
|
|
1196
|
-
o[17] = x4 >>> 8 & 0xff;
|
|
1197
|
-
o[18] = x4 >>> 16 & 0xff;
|
|
1198
|
-
o[19] = x4 >>> 24 & 0xff;
|
|
1199
|
-
|
|
1200
|
-
o[20] = x5 >>> 0 & 0xff;
|
|
1201
|
-
o[21] = x5 >>> 8 & 0xff;
|
|
1202
|
-
o[22] = x5 >>> 16 & 0xff;
|
|
1203
|
-
o[23] = x5 >>> 24 & 0xff;
|
|
1204
|
-
|
|
1205
|
-
o[24] = x6 >>> 0 & 0xff;
|
|
1206
|
-
o[25] = x6 >>> 8 & 0xff;
|
|
1207
|
-
o[26] = x6 >>> 16 & 0xff;
|
|
1208
|
-
o[27] = x6 >>> 24 & 0xff;
|
|
1209
|
-
|
|
1210
|
-
o[28] = x7 >>> 0 & 0xff;
|
|
1211
|
-
o[29] = x7 >>> 8 & 0xff;
|
|
1212
|
-
o[30] = x7 >>> 16 & 0xff;
|
|
1213
|
-
o[31] = x7 >>> 24 & 0xff;
|
|
1214
|
-
|
|
1215
|
-
o[32] = x8 >>> 0 & 0xff;
|
|
1216
|
-
o[33] = x8 >>> 8 & 0xff;
|
|
1217
|
-
o[34] = x8 >>> 16 & 0xff;
|
|
1218
|
-
o[35] = x8 >>> 24 & 0xff;
|
|
1219
|
-
|
|
1220
|
-
o[36] = x9 >>> 0 & 0xff;
|
|
1221
|
-
o[37] = x9 >>> 8 & 0xff;
|
|
1222
|
-
o[38] = x9 >>> 16 & 0xff;
|
|
1223
|
-
o[39] = x9 >>> 24 & 0xff;
|
|
1224
|
-
|
|
1225
|
-
o[40] = x10 >>> 0 & 0xff;
|
|
1226
|
-
o[41] = x10 >>> 8 & 0xff;
|
|
1227
|
-
o[42] = x10 >>> 16 & 0xff;
|
|
1228
|
-
o[43] = x10 >>> 24 & 0xff;
|
|
1229
|
-
|
|
1230
|
-
o[44] = x11 >>> 0 & 0xff;
|
|
1231
|
-
o[45] = x11 >>> 8 & 0xff;
|
|
1232
|
-
o[46] = x11 >>> 16 & 0xff;
|
|
1233
|
-
o[47] = x11 >>> 24 & 0xff;
|
|
1234
|
-
|
|
1235
|
-
o[48] = x12 >>> 0 & 0xff;
|
|
1236
|
-
o[49] = x12 >>> 8 & 0xff;
|
|
1237
|
-
o[50] = x12 >>> 16 & 0xff;
|
|
1238
|
-
o[51] = x12 >>> 24 & 0xff;
|
|
1239
|
-
|
|
1240
|
-
o[52] = x13 >>> 0 & 0xff;
|
|
1241
|
-
o[53] = x13 >>> 8 & 0xff;
|
|
1242
|
-
o[54] = x13 >>> 16 & 0xff;
|
|
1243
|
-
o[55] = x13 >>> 24 & 0xff;
|
|
1244
|
-
|
|
1245
|
-
o[56] = x14 >>> 0 & 0xff;
|
|
1246
|
-
o[57] = x14 >>> 8 & 0xff;
|
|
1247
|
-
o[58] = x14 >>> 16 & 0xff;
|
|
1248
|
-
o[59] = x14 >>> 24 & 0xff;
|
|
1249
|
-
|
|
1250
|
-
o[60] = x15 >>> 0 & 0xff;
|
|
1251
|
-
o[61] = x15 >>> 8 & 0xff;
|
|
1252
|
-
o[62] = x15 >>> 16 & 0xff;
|
|
1253
|
-
o[63] = x15 >>> 24 & 0xff;
|
|
1254
|
-
}
|
|
1255
|
-
|
|
1256
|
-
function core_hsalsa20(o,p,k,c) {
|
|
1257
|
-
var j0 = c[ 0] & 0xff | (c[ 1] & 0xff)<<8 | (c[ 2] & 0xff)<<16 | (c[ 3] & 0xff)<<24,
|
|
1258
|
-
j1 = k[ 0] & 0xff | (k[ 1] & 0xff)<<8 | (k[ 2] & 0xff)<<16 | (k[ 3] & 0xff)<<24,
|
|
1259
|
-
j2 = k[ 4] & 0xff | (k[ 5] & 0xff)<<8 | (k[ 6] & 0xff)<<16 | (k[ 7] & 0xff)<<24,
|
|
1260
|
-
j3 = k[ 8] & 0xff | (k[ 9] & 0xff)<<8 | (k[10] & 0xff)<<16 | (k[11] & 0xff)<<24,
|
|
1261
|
-
j4 = k[12] & 0xff | (k[13] & 0xff)<<8 | (k[14] & 0xff)<<16 | (k[15] & 0xff)<<24,
|
|
1262
|
-
j5 = c[ 4] & 0xff | (c[ 5] & 0xff)<<8 | (c[ 6] & 0xff)<<16 | (c[ 7] & 0xff)<<24,
|
|
1263
|
-
j6 = p[ 0] & 0xff | (p[ 1] & 0xff)<<8 | (p[ 2] & 0xff)<<16 | (p[ 3] & 0xff)<<24,
|
|
1264
|
-
j7 = p[ 4] & 0xff | (p[ 5] & 0xff)<<8 | (p[ 6] & 0xff)<<16 | (p[ 7] & 0xff)<<24,
|
|
1265
|
-
j8 = p[ 8] & 0xff | (p[ 9] & 0xff)<<8 | (p[10] & 0xff)<<16 | (p[11] & 0xff)<<24,
|
|
1266
|
-
j9 = p[12] & 0xff | (p[13] & 0xff)<<8 | (p[14] & 0xff)<<16 | (p[15] & 0xff)<<24,
|
|
1267
|
-
j10 = c[ 8] & 0xff | (c[ 9] & 0xff)<<8 | (c[10] & 0xff)<<16 | (c[11] & 0xff)<<24,
|
|
1268
|
-
j11 = k[16] & 0xff | (k[17] & 0xff)<<8 | (k[18] & 0xff)<<16 | (k[19] & 0xff)<<24,
|
|
1269
|
-
j12 = k[20] & 0xff | (k[21] & 0xff)<<8 | (k[22] & 0xff)<<16 | (k[23] & 0xff)<<24,
|
|
1270
|
-
j13 = k[24] & 0xff | (k[25] & 0xff)<<8 | (k[26] & 0xff)<<16 | (k[27] & 0xff)<<24,
|
|
1271
|
-
j14 = k[28] & 0xff | (k[29] & 0xff)<<8 | (k[30] & 0xff)<<16 | (k[31] & 0xff)<<24,
|
|
1272
|
-
j15 = c[12] & 0xff | (c[13] & 0xff)<<8 | (c[14] & 0xff)<<16 | (c[15] & 0xff)<<24;
|
|
1273
|
-
|
|
1274
|
-
var x0 = j0, x1 = j1, x2 = j2, x3 = j3, x4 = j4, x5 = j5, x6 = j6, x7 = j7,
|
|
1275
|
-
x8 = j8, x9 = j9, x10 = j10, x11 = j11, x12 = j12, x13 = j13, x14 = j14,
|
|
1276
|
-
x15 = j15, u;
|
|
1277
|
-
|
|
1278
|
-
for (var i = 0; i < 20; i += 2) {
|
|
1279
|
-
u = x0 + x12 | 0;
|
|
1280
|
-
x4 ^= u<<7 | u>>>(32-7);
|
|
1281
|
-
u = x4 + x0 | 0;
|
|
1282
|
-
x8 ^= u<<9 | u>>>(32-9);
|
|
1283
|
-
u = x8 + x4 | 0;
|
|
1284
|
-
x12 ^= u<<13 | u>>>(32-13);
|
|
1285
|
-
u = x12 + x8 | 0;
|
|
1286
|
-
x0 ^= u<<18 | u>>>(32-18);
|
|
1287
|
-
|
|
1288
|
-
u = x5 + x1 | 0;
|
|
1289
|
-
x9 ^= u<<7 | u>>>(32-7);
|
|
1290
|
-
u = x9 + x5 | 0;
|
|
1291
|
-
x13 ^= u<<9 | u>>>(32-9);
|
|
1292
|
-
u = x13 + x9 | 0;
|
|
1293
|
-
x1 ^= u<<13 | u>>>(32-13);
|
|
1294
|
-
u = x1 + x13 | 0;
|
|
1295
|
-
x5 ^= u<<18 | u>>>(32-18);
|
|
1296
|
-
|
|
1297
|
-
u = x10 + x6 | 0;
|
|
1298
|
-
x14 ^= u<<7 | u>>>(32-7);
|
|
1299
|
-
u = x14 + x10 | 0;
|
|
1300
|
-
x2 ^= u<<9 | u>>>(32-9);
|
|
1301
|
-
u = x2 + x14 | 0;
|
|
1302
|
-
x6 ^= u<<13 | u>>>(32-13);
|
|
1303
|
-
u = x6 + x2 | 0;
|
|
1304
|
-
x10 ^= u<<18 | u>>>(32-18);
|
|
1305
|
-
|
|
1306
|
-
u = x15 + x11 | 0;
|
|
1307
|
-
x3 ^= u<<7 | u>>>(32-7);
|
|
1308
|
-
u = x3 + x15 | 0;
|
|
1309
|
-
x7 ^= u<<9 | u>>>(32-9);
|
|
1310
|
-
u = x7 + x3 | 0;
|
|
1311
|
-
x11 ^= u<<13 | u>>>(32-13);
|
|
1312
|
-
u = x11 + x7 | 0;
|
|
1313
|
-
x15 ^= u<<18 | u>>>(32-18);
|
|
1314
|
-
|
|
1315
|
-
u = x0 + x3 | 0;
|
|
1316
|
-
x1 ^= u<<7 | u>>>(32-7);
|
|
1317
|
-
u = x1 + x0 | 0;
|
|
1318
|
-
x2 ^= u<<9 | u>>>(32-9);
|
|
1319
|
-
u = x2 + x1 | 0;
|
|
1320
|
-
x3 ^= u<<13 | u>>>(32-13);
|
|
1321
|
-
u = x3 + x2 | 0;
|
|
1322
|
-
x0 ^= u<<18 | u>>>(32-18);
|
|
1323
|
-
|
|
1324
|
-
u = x5 + x4 | 0;
|
|
1325
|
-
x6 ^= u<<7 | u>>>(32-7);
|
|
1326
|
-
u = x6 + x5 | 0;
|
|
1327
|
-
x7 ^= u<<9 | u>>>(32-9);
|
|
1328
|
-
u = x7 + x6 | 0;
|
|
1329
|
-
x4 ^= u<<13 | u>>>(32-13);
|
|
1330
|
-
u = x4 + x7 | 0;
|
|
1331
|
-
x5 ^= u<<18 | u>>>(32-18);
|
|
1332
|
-
|
|
1333
|
-
u = x10 + x9 | 0;
|
|
1334
|
-
x11 ^= u<<7 | u>>>(32-7);
|
|
1335
|
-
u = x11 + x10 | 0;
|
|
1336
|
-
x8 ^= u<<9 | u>>>(32-9);
|
|
1337
|
-
u = x8 + x11 | 0;
|
|
1338
|
-
x9 ^= u<<13 | u>>>(32-13);
|
|
1339
|
-
u = x9 + x8 | 0;
|
|
1340
|
-
x10 ^= u<<18 | u>>>(32-18);
|
|
1341
|
-
|
|
1342
|
-
u = x15 + x14 | 0;
|
|
1343
|
-
x12 ^= u<<7 | u>>>(32-7);
|
|
1344
|
-
u = x12 + x15 | 0;
|
|
1345
|
-
x13 ^= u<<9 | u>>>(32-9);
|
|
1346
|
-
u = x13 + x12 | 0;
|
|
1347
|
-
x14 ^= u<<13 | u>>>(32-13);
|
|
1348
|
-
u = x14 + x13 | 0;
|
|
1349
|
-
x15 ^= u<<18 | u>>>(32-18);
|
|
1350
|
-
}
|
|
1351
|
-
|
|
1352
|
-
o[ 0] = x0 >>> 0 & 0xff;
|
|
1353
|
-
o[ 1] = x0 >>> 8 & 0xff;
|
|
1354
|
-
o[ 2] = x0 >>> 16 & 0xff;
|
|
1355
|
-
o[ 3] = x0 >>> 24 & 0xff;
|
|
1356
|
-
|
|
1357
|
-
o[ 4] = x5 >>> 0 & 0xff;
|
|
1358
|
-
o[ 5] = x5 >>> 8 & 0xff;
|
|
1359
|
-
o[ 6] = x5 >>> 16 & 0xff;
|
|
1360
|
-
o[ 7] = x5 >>> 24 & 0xff;
|
|
1361
|
-
|
|
1362
|
-
o[ 8] = x10 >>> 0 & 0xff;
|
|
1363
|
-
o[ 9] = x10 >>> 8 & 0xff;
|
|
1364
|
-
o[10] = x10 >>> 16 & 0xff;
|
|
1365
|
-
o[11] = x10 >>> 24 & 0xff;
|
|
1366
|
-
|
|
1367
|
-
o[12] = x15 >>> 0 & 0xff;
|
|
1368
|
-
o[13] = x15 >>> 8 & 0xff;
|
|
1369
|
-
o[14] = x15 >>> 16 & 0xff;
|
|
1370
|
-
o[15] = x15 >>> 24 & 0xff;
|
|
1371
|
-
|
|
1372
|
-
o[16] = x6 >>> 0 & 0xff;
|
|
1373
|
-
o[17] = x6 >>> 8 & 0xff;
|
|
1374
|
-
o[18] = x6 >>> 16 & 0xff;
|
|
1375
|
-
o[19] = x6 >>> 24 & 0xff;
|
|
1376
|
-
|
|
1377
|
-
o[20] = x7 >>> 0 & 0xff;
|
|
1378
|
-
o[21] = x7 >>> 8 & 0xff;
|
|
1379
|
-
o[22] = x7 >>> 16 & 0xff;
|
|
1380
|
-
o[23] = x7 >>> 24 & 0xff;
|
|
1381
|
-
|
|
1382
|
-
o[24] = x8 >>> 0 & 0xff;
|
|
1383
|
-
o[25] = x8 >>> 8 & 0xff;
|
|
1384
|
-
o[26] = x8 >>> 16 & 0xff;
|
|
1385
|
-
o[27] = x8 >>> 24 & 0xff;
|
|
1386
|
-
|
|
1387
|
-
o[28] = x9 >>> 0 & 0xff;
|
|
1388
|
-
o[29] = x9 >>> 8 & 0xff;
|
|
1389
|
-
o[30] = x9 >>> 16 & 0xff;
|
|
1390
|
-
o[31] = x9 >>> 24 & 0xff;
|
|
1391
|
-
}
|
|
1392
|
-
|
|
1393
|
-
function crypto_core_salsa20(out,inp,k,c) {
|
|
1394
|
-
core_salsa20(out,inp,k,c);
|
|
1395
|
-
}
|
|
1396
|
-
|
|
1397
|
-
function crypto_core_hsalsa20(out,inp,k,c) {
|
|
1398
|
-
core_hsalsa20(out,inp,k,c);
|
|
1399
|
-
}
|
|
1400
|
-
|
|
1401
|
-
var sigma = new Uint8Array([101, 120, 112, 97, 110, 100, 32, 51, 50, 45, 98, 121, 116, 101, 32, 107]);
|
|
1402
|
-
// "expand 32-byte k"
|
|
1403
|
-
|
|
1404
|
-
function crypto_stream_salsa20_xor(c,cpos,m,mpos,b,n,k) {
|
|
1405
|
-
var z = new Uint8Array(16), x = new Uint8Array(64);
|
|
1406
|
-
var u, i;
|
|
1407
|
-
for (i = 0; i < 16; i++) z[i] = 0;
|
|
1408
|
-
for (i = 0; i < 8; i++) z[i] = n[i];
|
|
1409
|
-
while (b >= 64) {
|
|
1410
|
-
crypto_core_salsa20(x,z,k,sigma);
|
|
1411
|
-
for (i = 0; i < 64; i++) c[cpos+i] = m[mpos+i] ^ x[i];
|
|
1412
|
-
u = 1;
|
|
1413
|
-
for (i = 8; i < 16; i++) {
|
|
1414
|
-
u = u + (z[i] & 0xff) | 0;
|
|
1415
|
-
z[i] = u & 0xff;
|
|
1416
|
-
u >>>= 8;
|
|
1417
|
-
}
|
|
1418
|
-
b -= 64;
|
|
1419
|
-
cpos += 64;
|
|
1420
|
-
mpos += 64;
|
|
1421
|
-
}
|
|
1422
|
-
if (b > 0) {
|
|
1423
|
-
crypto_core_salsa20(x,z,k,sigma);
|
|
1424
|
-
for (i = 0; i < b; i++) c[cpos+i] = m[mpos+i] ^ x[i];
|
|
1425
|
-
}
|
|
1426
|
-
return 0;
|
|
1427
|
-
}
|
|
1428
|
-
|
|
1429
|
-
function crypto_stream_salsa20(c,cpos,b,n,k) {
|
|
1430
|
-
var z = new Uint8Array(16), x = new Uint8Array(64);
|
|
1431
|
-
var u, i;
|
|
1432
|
-
for (i = 0; i < 16; i++) z[i] = 0;
|
|
1433
|
-
for (i = 0; i < 8; i++) z[i] = n[i];
|
|
1434
|
-
while (b >= 64) {
|
|
1435
|
-
crypto_core_salsa20(x,z,k,sigma);
|
|
1436
|
-
for (i = 0; i < 64; i++) c[cpos+i] = x[i];
|
|
1437
|
-
u = 1;
|
|
1438
|
-
for (i = 8; i < 16; i++) {
|
|
1439
|
-
u = u + (z[i] & 0xff) | 0;
|
|
1440
|
-
z[i] = u & 0xff;
|
|
1441
|
-
u >>>= 8;
|
|
1442
|
-
}
|
|
1443
|
-
b -= 64;
|
|
1444
|
-
cpos += 64;
|
|
1445
|
-
}
|
|
1446
|
-
if (b > 0) {
|
|
1447
|
-
crypto_core_salsa20(x,z,k,sigma);
|
|
1448
|
-
for (i = 0; i < b; i++) c[cpos+i] = x[i];
|
|
1449
|
-
}
|
|
1450
|
-
return 0;
|
|
1451
|
-
}
|
|
1452
|
-
|
|
1453
|
-
function crypto_stream(c,cpos,d,n,k) {
|
|
1454
|
-
var s = new Uint8Array(32);
|
|
1455
|
-
crypto_core_hsalsa20(s,n,k,sigma);
|
|
1456
|
-
var sn = new Uint8Array(8);
|
|
1457
|
-
for (var i = 0; i < 8; i++) sn[i] = n[i+16];
|
|
1458
|
-
return crypto_stream_salsa20(c,cpos,d,sn,s);
|
|
1459
|
-
}
|
|
1460
|
-
|
|
1461
|
-
function crypto_stream_xor(c,cpos,m,mpos,d,n,k) {
|
|
1462
|
-
var s = new Uint8Array(32);
|
|
1463
|
-
crypto_core_hsalsa20(s,n,k,sigma);
|
|
1464
|
-
var sn = new Uint8Array(8);
|
|
1465
|
-
for (var i = 0; i < 8; i++) sn[i] = n[i+16];
|
|
1466
|
-
return crypto_stream_salsa20_xor(c,cpos,m,mpos,d,sn,s);
|
|
1467
|
-
}
|
|
1468
|
-
|
|
1469
|
-
/*
|
|
1470
|
-
* Port of Andrew Moon's Poly1305-donna-16. Public domain.
|
|
1471
|
-
* https://github.com/floodyberry/poly1305-donna
|
|
1472
|
-
*/
|
|
1473
|
-
|
|
1474
|
-
var poly1305 = function(key) {
|
|
1475
|
-
this.buffer = new Uint8Array(16);
|
|
1476
|
-
this.r = new Uint16Array(10);
|
|
1477
|
-
this.h = new Uint16Array(10);
|
|
1478
|
-
this.pad = new Uint16Array(8);
|
|
1479
|
-
this.leftover = 0;
|
|
1480
|
-
this.fin = 0;
|
|
1481
|
-
|
|
1482
|
-
var t0, t1, t2, t3, t4, t5, t6, t7;
|
|
1483
|
-
|
|
1484
|
-
t0 = key[ 0] & 0xff | (key[ 1] & 0xff) << 8; this.r[0] = ( t0 ) & 0x1fff;
|
|
1485
|
-
t1 = key[ 2] & 0xff | (key[ 3] & 0xff) << 8; this.r[1] = ((t0 >>> 13) | (t1 << 3)) & 0x1fff;
|
|
1486
|
-
t2 = key[ 4] & 0xff | (key[ 5] & 0xff) << 8; this.r[2] = ((t1 >>> 10) | (t2 << 6)) & 0x1f03;
|
|
1487
|
-
t3 = key[ 6] & 0xff | (key[ 7] & 0xff) << 8; this.r[3] = ((t2 >>> 7) | (t3 << 9)) & 0x1fff;
|
|
1488
|
-
t4 = key[ 8] & 0xff | (key[ 9] & 0xff) << 8; this.r[4] = ((t3 >>> 4) | (t4 << 12)) & 0x00ff;
|
|
1489
|
-
this.r[5] = ((t4 >>> 1)) & 0x1ffe;
|
|
1490
|
-
t5 = key[10] & 0xff | (key[11] & 0xff) << 8; this.r[6] = ((t4 >>> 14) | (t5 << 2)) & 0x1fff;
|
|
1491
|
-
t6 = key[12] & 0xff | (key[13] & 0xff) << 8; this.r[7] = ((t5 >>> 11) | (t6 << 5)) & 0x1f81;
|
|
1492
|
-
t7 = key[14] & 0xff | (key[15] & 0xff) << 8; this.r[8] = ((t6 >>> 8) | (t7 << 8)) & 0x1fff;
|
|
1493
|
-
this.r[9] = ((t7 >>> 5)) & 0x007f;
|
|
1494
|
-
|
|
1495
|
-
this.pad[0] = key[16] & 0xff | (key[17] & 0xff) << 8;
|
|
1496
|
-
this.pad[1] = key[18] & 0xff | (key[19] & 0xff) << 8;
|
|
1497
|
-
this.pad[2] = key[20] & 0xff | (key[21] & 0xff) << 8;
|
|
1498
|
-
this.pad[3] = key[22] & 0xff | (key[23] & 0xff) << 8;
|
|
1499
|
-
this.pad[4] = key[24] & 0xff | (key[25] & 0xff) << 8;
|
|
1500
|
-
this.pad[5] = key[26] & 0xff | (key[27] & 0xff) << 8;
|
|
1501
|
-
this.pad[6] = key[28] & 0xff | (key[29] & 0xff) << 8;
|
|
1502
|
-
this.pad[7] = key[30] & 0xff | (key[31] & 0xff) << 8;
|
|
1503
|
-
};
|
|
1504
|
-
|
|
1505
|
-
poly1305.prototype.blocks = function(m, mpos, bytes) {
|
|
1506
|
-
var hibit = this.fin ? 0 : (1 << 11);
|
|
1507
|
-
var t0, t1, t2, t3, t4, t5, t6, t7, c;
|
|
1508
|
-
var d0, d1, d2, d3, d4, d5, d6, d7, d8, d9;
|
|
1509
|
-
|
|
1510
|
-
var h0 = this.h[0],
|
|
1511
|
-
h1 = this.h[1],
|
|
1512
|
-
h2 = this.h[2],
|
|
1513
|
-
h3 = this.h[3],
|
|
1514
|
-
h4 = this.h[4],
|
|
1515
|
-
h5 = this.h[5],
|
|
1516
|
-
h6 = this.h[6],
|
|
1517
|
-
h7 = this.h[7],
|
|
1518
|
-
h8 = this.h[8],
|
|
1519
|
-
h9 = this.h[9];
|
|
1520
|
-
|
|
1521
|
-
var r0 = this.r[0],
|
|
1522
|
-
r1 = this.r[1],
|
|
1523
|
-
r2 = this.r[2],
|
|
1524
|
-
r3 = this.r[3],
|
|
1525
|
-
r4 = this.r[4],
|
|
1526
|
-
r5 = this.r[5],
|
|
1527
|
-
r6 = this.r[6],
|
|
1528
|
-
r7 = this.r[7],
|
|
1529
|
-
r8 = this.r[8],
|
|
1530
|
-
r9 = this.r[9];
|
|
1531
|
-
|
|
1532
|
-
while (bytes >= 16) {
|
|
1533
|
-
t0 = m[mpos+ 0] & 0xff | (m[mpos+ 1] & 0xff) << 8; h0 += ( t0 ) & 0x1fff;
|
|
1534
|
-
t1 = m[mpos+ 2] & 0xff | (m[mpos+ 3] & 0xff) << 8; h1 += ((t0 >>> 13) | (t1 << 3)) & 0x1fff;
|
|
1535
|
-
t2 = m[mpos+ 4] & 0xff | (m[mpos+ 5] & 0xff) << 8; h2 += ((t1 >>> 10) | (t2 << 6)) & 0x1fff;
|
|
1536
|
-
t3 = m[mpos+ 6] & 0xff | (m[mpos+ 7] & 0xff) << 8; h3 += ((t2 >>> 7) | (t3 << 9)) & 0x1fff;
|
|
1537
|
-
t4 = m[mpos+ 8] & 0xff | (m[mpos+ 9] & 0xff) << 8; h4 += ((t3 >>> 4) | (t4 << 12)) & 0x1fff;
|
|
1538
|
-
h5 += ((t4 >>> 1)) & 0x1fff;
|
|
1539
|
-
t5 = m[mpos+10] & 0xff | (m[mpos+11] & 0xff) << 8; h6 += ((t4 >>> 14) | (t5 << 2)) & 0x1fff;
|
|
1540
|
-
t6 = m[mpos+12] & 0xff | (m[mpos+13] & 0xff) << 8; h7 += ((t5 >>> 11) | (t6 << 5)) & 0x1fff;
|
|
1541
|
-
t7 = m[mpos+14] & 0xff | (m[mpos+15] & 0xff) << 8; h8 += ((t6 >>> 8) | (t7 << 8)) & 0x1fff;
|
|
1542
|
-
h9 += ((t7 >>> 5)) | hibit;
|
|
1543
|
-
|
|
1544
|
-
c = 0;
|
|
1545
|
-
|
|
1546
|
-
d0 = c;
|
|
1547
|
-
d0 += h0 * r0;
|
|
1548
|
-
d0 += h1 * (5 * r9);
|
|
1549
|
-
d0 += h2 * (5 * r8);
|
|
1550
|
-
d0 += h3 * (5 * r7);
|
|
1551
|
-
d0 += h4 * (5 * r6);
|
|
1552
|
-
c = (d0 >>> 13); d0 &= 0x1fff;
|
|
1553
|
-
d0 += h5 * (5 * r5);
|
|
1554
|
-
d0 += h6 * (5 * r4);
|
|
1555
|
-
d0 += h7 * (5 * r3);
|
|
1556
|
-
d0 += h8 * (5 * r2);
|
|
1557
|
-
d0 += h9 * (5 * r1);
|
|
1558
|
-
c += (d0 >>> 13); d0 &= 0x1fff;
|
|
1559
|
-
|
|
1560
|
-
d1 = c;
|
|
1561
|
-
d1 += h0 * r1;
|
|
1562
|
-
d1 += h1 * r0;
|
|
1563
|
-
d1 += h2 * (5 * r9);
|
|
1564
|
-
d1 += h3 * (5 * r8);
|
|
1565
|
-
d1 += h4 * (5 * r7);
|
|
1566
|
-
c = (d1 >>> 13); d1 &= 0x1fff;
|
|
1567
|
-
d1 += h5 * (5 * r6);
|
|
1568
|
-
d1 += h6 * (5 * r5);
|
|
1569
|
-
d1 += h7 * (5 * r4);
|
|
1570
|
-
d1 += h8 * (5 * r3);
|
|
1571
|
-
d1 += h9 * (5 * r2);
|
|
1572
|
-
c += (d1 >>> 13); d1 &= 0x1fff;
|
|
1573
|
-
|
|
1574
|
-
d2 = c;
|
|
1575
|
-
d2 += h0 * r2;
|
|
1576
|
-
d2 += h1 * r1;
|
|
1577
|
-
d2 += h2 * r0;
|
|
1578
|
-
d2 += h3 * (5 * r9);
|
|
1579
|
-
d2 += h4 * (5 * r8);
|
|
1580
|
-
c = (d2 >>> 13); d2 &= 0x1fff;
|
|
1581
|
-
d2 += h5 * (5 * r7);
|
|
1582
|
-
d2 += h6 * (5 * r6);
|
|
1583
|
-
d2 += h7 * (5 * r5);
|
|
1584
|
-
d2 += h8 * (5 * r4);
|
|
1585
|
-
d2 += h9 * (5 * r3);
|
|
1586
|
-
c += (d2 >>> 13); d2 &= 0x1fff;
|
|
1587
|
-
|
|
1588
|
-
d3 = c;
|
|
1589
|
-
d3 += h0 * r3;
|
|
1590
|
-
d3 += h1 * r2;
|
|
1591
|
-
d3 += h2 * r1;
|
|
1592
|
-
d3 += h3 * r0;
|
|
1593
|
-
d3 += h4 * (5 * r9);
|
|
1594
|
-
c = (d3 >>> 13); d3 &= 0x1fff;
|
|
1595
|
-
d3 += h5 * (5 * r8);
|
|
1596
|
-
d3 += h6 * (5 * r7);
|
|
1597
|
-
d3 += h7 * (5 * r6);
|
|
1598
|
-
d3 += h8 * (5 * r5);
|
|
1599
|
-
d3 += h9 * (5 * r4);
|
|
1600
|
-
c += (d3 >>> 13); d3 &= 0x1fff;
|
|
1601
|
-
|
|
1602
|
-
d4 = c;
|
|
1603
|
-
d4 += h0 * r4;
|
|
1604
|
-
d4 += h1 * r3;
|
|
1605
|
-
d4 += h2 * r2;
|
|
1606
|
-
d4 += h3 * r1;
|
|
1607
|
-
d4 += h4 * r0;
|
|
1608
|
-
c = (d4 >>> 13); d4 &= 0x1fff;
|
|
1609
|
-
d4 += h5 * (5 * r9);
|
|
1610
|
-
d4 += h6 * (5 * r8);
|
|
1611
|
-
d4 += h7 * (5 * r7);
|
|
1612
|
-
d4 += h8 * (5 * r6);
|
|
1613
|
-
d4 += h9 * (5 * r5);
|
|
1614
|
-
c += (d4 >>> 13); d4 &= 0x1fff;
|
|
1615
|
-
|
|
1616
|
-
d5 = c;
|
|
1617
|
-
d5 += h0 * r5;
|
|
1618
|
-
d5 += h1 * r4;
|
|
1619
|
-
d5 += h2 * r3;
|
|
1620
|
-
d5 += h3 * r2;
|
|
1621
|
-
d5 += h4 * r1;
|
|
1622
|
-
c = (d5 >>> 13); d5 &= 0x1fff;
|
|
1623
|
-
d5 += h5 * r0;
|
|
1624
|
-
d5 += h6 * (5 * r9);
|
|
1625
|
-
d5 += h7 * (5 * r8);
|
|
1626
|
-
d5 += h8 * (5 * r7);
|
|
1627
|
-
d5 += h9 * (5 * r6);
|
|
1628
|
-
c += (d5 >>> 13); d5 &= 0x1fff;
|
|
1629
|
-
|
|
1630
|
-
d6 = c;
|
|
1631
|
-
d6 += h0 * r6;
|
|
1632
|
-
d6 += h1 * r5;
|
|
1633
|
-
d6 += h2 * r4;
|
|
1634
|
-
d6 += h3 * r3;
|
|
1635
|
-
d6 += h4 * r2;
|
|
1636
|
-
c = (d6 >>> 13); d6 &= 0x1fff;
|
|
1637
|
-
d6 += h5 * r1;
|
|
1638
|
-
d6 += h6 * r0;
|
|
1639
|
-
d6 += h7 * (5 * r9);
|
|
1640
|
-
d6 += h8 * (5 * r8);
|
|
1641
|
-
d6 += h9 * (5 * r7);
|
|
1642
|
-
c += (d6 >>> 13); d6 &= 0x1fff;
|
|
1643
|
-
|
|
1644
|
-
d7 = c;
|
|
1645
|
-
d7 += h0 * r7;
|
|
1646
|
-
d7 += h1 * r6;
|
|
1647
|
-
d7 += h2 * r5;
|
|
1648
|
-
d7 += h3 * r4;
|
|
1649
|
-
d7 += h4 * r3;
|
|
1650
|
-
c = (d7 >>> 13); d7 &= 0x1fff;
|
|
1651
|
-
d7 += h5 * r2;
|
|
1652
|
-
d7 += h6 * r1;
|
|
1653
|
-
d7 += h7 * r0;
|
|
1654
|
-
d7 += h8 * (5 * r9);
|
|
1655
|
-
d7 += h9 * (5 * r8);
|
|
1656
|
-
c += (d7 >>> 13); d7 &= 0x1fff;
|
|
1657
|
-
|
|
1658
|
-
d8 = c;
|
|
1659
|
-
d8 += h0 * r8;
|
|
1660
|
-
d8 += h1 * r7;
|
|
1661
|
-
d8 += h2 * r6;
|
|
1662
|
-
d8 += h3 * r5;
|
|
1663
|
-
d8 += h4 * r4;
|
|
1664
|
-
c = (d8 >>> 13); d8 &= 0x1fff;
|
|
1665
|
-
d8 += h5 * r3;
|
|
1666
|
-
d8 += h6 * r2;
|
|
1667
|
-
d8 += h7 * r1;
|
|
1668
|
-
d8 += h8 * r0;
|
|
1669
|
-
d8 += h9 * (5 * r9);
|
|
1670
|
-
c += (d8 >>> 13); d8 &= 0x1fff;
|
|
1671
|
-
|
|
1672
|
-
d9 = c;
|
|
1673
|
-
d9 += h0 * r9;
|
|
1674
|
-
d9 += h1 * r8;
|
|
1675
|
-
d9 += h2 * r7;
|
|
1676
|
-
d9 += h3 * r6;
|
|
1677
|
-
d9 += h4 * r5;
|
|
1678
|
-
c = (d9 >>> 13); d9 &= 0x1fff;
|
|
1679
|
-
d9 += h5 * r4;
|
|
1680
|
-
d9 += h6 * r3;
|
|
1681
|
-
d9 += h7 * r2;
|
|
1682
|
-
d9 += h8 * r1;
|
|
1683
|
-
d9 += h9 * r0;
|
|
1684
|
-
c += (d9 >>> 13); d9 &= 0x1fff;
|
|
1685
|
-
|
|
1686
|
-
c = (((c << 2) + c)) | 0;
|
|
1687
|
-
c = (c + d0) | 0;
|
|
1688
|
-
d0 = c & 0x1fff;
|
|
1689
|
-
c = (c >>> 13);
|
|
1690
|
-
d1 += c;
|
|
1691
|
-
|
|
1692
|
-
h0 = d0;
|
|
1693
|
-
h1 = d1;
|
|
1694
|
-
h2 = d2;
|
|
1695
|
-
h3 = d3;
|
|
1696
|
-
h4 = d4;
|
|
1697
|
-
h5 = d5;
|
|
1698
|
-
h6 = d6;
|
|
1699
|
-
h7 = d7;
|
|
1700
|
-
h8 = d8;
|
|
1701
|
-
h9 = d9;
|
|
1702
|
-
|
|
1703
|
-
mpos += 16;
|
|
1704
|
-
bytes -= 16;
|
|
1705
|
-
}
|
|
1706
|
-
this.h[0] = h0;
|
|
1707
|
-
this.h[1] = h1;
|
|
1708
|
-
this.h[2] = h2;
|
|
1709
|
-
this.h[3] = h3;
|
|
1710
|
-
this.h[4] = h4;
|
|
1711
|
-
this.h[5] = h5;
|
|
1712
|
-
this.h[6] = h6;
|
|
1713
|
-
this.h[7] = h7;
|
|
1714
|
-
this.h[8] = h8;
|
|
1715
|
-
this.h[9] = h9;
|
|
1716
|
-
};
|
|
1717
|
-
|
|
1718
|
-
poly1305.prototype.finish = function(mac, macpos) {
|
|
1719
|
-
var g = new Uint16Array(10);
|
|
1720
|
-
var c, mask, f, i;
|
|
1721
|
-
|
|
1722
|
-
if (this.leftover) {
|
|
1723
|
-
i = this.leftover;
|
|
1724
|
-
this.buffer[i++] = 1;
|
|
1725
|
-
for (; i < 16; i++) this.buffer[i] = 0;
|
|
1726
|
-
this.fin = 1;
|
|
1727
|
-
this.blocks(this.buffer, 0, 16);
|
|
1728
|
-
}
|
|
1729
|
-
|
|
1730
|
-
c = this.h[1] >>> 13;
|
|
1731
|
-
this.h[1] &= 0x1fff;
|
|
1732
|
-
for (i = 2; i < 10; i++) {
|
|
1733
|
-
this.h[i] += c;
|
|
1734
|
-
c = this.h[i] >>> 13;
|
|
1735
|
-
this.h[i] &= 0x1fff;
|
|
1736
|
-
}
|
|
1737
|
-
this.h[0] += (c * 5);
|
|
1738
|
-
c = this.h[0] >>> 13;
|
|
1739
|
-
this.h[0] &= 0x1fff;
|
|
1740
|
-
this.h[1] += c;
|
|
1741
|
-
c = this.h[1] >>> 13;
|
|
1742
|
-
this.h[1] &= 0x1fff;
|
|
1743
|
-
this.h[2] += c;
|
|
1744
|
-
|
|
1745
|
-
g[0] = this.h[0] + 5;
|
|
1746
|
-
c = g[0] >>> 13;
|
|
1747
|
-
g[0] &= 0x1fff;
|
|
1748
|
-
for (i = 1; i < 10; i++) {
|
|
1749
|
-
g[i] = this.h[i] + c;
|
|
1750
|
-
c = g[i] >>> 13;
|
|
1751
|
-
g[i] &= 0x1fff;
|
|
1752
|
-
}
|
|
1753
|
-
g[9] -= (1 << 13);
|
|
1754
|
-
|
|
1755
|
-
mask = (c ^ 1) - 1;
|
|
1756
|
-
for (i = 0; i < 10; i++) g[i] &= mask;
|
|
1757
|
-
mask = ~mask;
|
|
1758
|
-
for (i = 0; i < 10; i++) this.h[i] = (this.h[i] & mask) | g[i];
|
|
1759
|
-
|
|
1760
|
-
this.h[0] = ((this.h[0] ) | (this.h[1] << 13) ) & 0xffff;
|
|
1761
|
-
this.h[1] = ((this.h[1] >>> 3) | (this.h[2] << 10) ) & 0xffff;
|
|
1762
|
-
this.h[2] = ((this.h[2] >>> 6) | (this.h[3] << 7) ) & 0xffff;
|
|
1763
|
-
this.h[3] = ((this.h[3] >>> 9) | (this.h[4] << 4) ) & 0xffff;
|
|
1764
|
-
this.h[4] = ((this.h[4] >>> 12) | (this.h[5] << 1) | (this.h[6] << 14)) & 0xffff;
|
|
1765
|
-
this.h[5] = ((this.h[6] >>> 2) | (this.h[7] << 11) ) & 0xffff;
|
|
1766
|
-
this.h[6] = ((this.h[7] >>> 5) | (this.h[8] << 8) ) & 0xffff;
|
|
1767
|
-
this.h[7] = ((this.h[8] >>> 8) | (this.h[9] << 5) ) & 0xffff;
|
|
1768
|
-
|
|
1769
|
-
f = this.h[0] + this.pad[0];
|
|
1770
|
-
this.h[0] = f & 0xffff;
|
|
1771
|
-
for (i = 1; i < 8; i++) {
|
|
1772
|
-
f = (((this.h[i] + this.pad[i]) | 0) + (f >>> 16)) | 0;
|
|
1773
|
-
this.h[i] = f & 0xffff;
|
|
1774
|
-
}
|
|
1775
|
-
|
|
1776
|
-
mac[macpos+ 0] = (this.h[0] >>> 0) & 0xff;
|
|
1777
|
-
mac[macpos+ 1] = (this.h[0] >>> 8) & 0xff;
|
|
1778
|
-
mac[macpos+ 2] = (this.h[1] >>> 0) & 0xff;
|
|
1779
|
-
mac[macpos+ 3] = (this.h[1] >>> 8) & 0xff;
|
|
1780
|
-
mac[macpos+ 4] = (this.h[2] >>> 0) & 0xff;
|
|
1781
|
-
mac[macpos+ 5] = (this.h[2] >>> 8) & 0xff;
|
|
1782
|
-
mac[macpos+ 6] = (this.h[3] >>> 0) & 0xff;
|
|
1783
|
-
mac[macpos+ 7] = (this.h[3] >>> 8) & 0xff;
|
|
1784
|
-
mac[macpos+ 8] = (this.h[4] >>> 0) & 0xff;
|
|
1785
|
-
mac[macpos+ 9] = (this.h[4] >>> 8) & 0xff;
|
|
1786
|
-
mac[macpos+10] = (this.h[5] >>> 0) & 0xff;
|
|
1787
|
-
mac[macpos+11] = (this.h[5] >>> 8) & 0xff;
|
|
1788
|
-
mac[macpos+12] = (this.h[6] >>> 0) & 0xff;
|
|
1789
|
-
mac[macpos+13] = (this.h[6] >>> 8) & 0xff;
|
|
1790
|
-
mac[macpos+14] = (this.h[7] >>> 0) & 0xff;
|
|
1791
|
-
mac[macpos+15] = (this.h[7] >>> 8) & 0xff;
|
|
1792
|
-
};
|
|
1793
|
-
|
|
1794
|
-
poly1305.prototype.update = function(m, mpos, bytes) {
|
|
1795
|
-
var i, want;
|
|
1796
|
-
|
|
1797
|
-
if (this.leftover) {
|
|
1798
|
-
want = (16 - this.leftover);
|
|
1799
|
-
if (want > bytes)
|
|
1800
|
-
want = bytes;
|
|
1801
|
-
for (i = 0; i < want; i++)
|
|
1802
|
-
this.buffer[this.leftover + i] = m[mpos+i];
|
|
1803
|
-
bytes -= want;
|
|
1804
|
-
mpos += want;
|
|
1805
|
-
this.leftover += want;
|
|
1806
|
-
if (this.leftover < 16)
|
|
1807
|
-
return;
|
|
1808
|
-
this.blocks(this.buffer, 0, 16);
|
|
1809
|
-
this.leftover = 0;
|
|
1810
|
-
}
|
|
1811
|
-
|
|
1812
|
-
if (bytes >= 16) {
|
|
1813
|
-
want = bytes - (bytes % 16);
|
|
1814
|
-
this.blocks(m, mpos, want);
|
|
1815
|
-
mpos += want;
|
|
1816
|
-
bytes -= want;
|
|
1817
|
-
}
|
|
1818
|
-
|
|
1819
|
-
if (bytes) {
|
|
1820
|
-
for (i = 0; i < bytes; i++)
|
|
1821
|
-
this.buffer[this.leftover + i] = m[mpos+i];
|
|
1822
|
-
this.leftover += bytes;
|
|
1823
|
-
}
|
|
1824
|
-
};
|
|
1825
|
-
|
|
1826
|
-
function crypto_onetimeauth(out, outpos, m, mpos, n, k) {
|
|
1827
|
-
var s = new poly1305(k);
|
|
1828
|
-
s.update(m, mpos, n);
|
|
1829
|
-
s.finish(out, outpos);
|
|
1830
|
-
return 0;
|
|
1831
|
-
}
|
|
1832
|
-
|
|
1833
|
-
function crypto_onetimeauth_verify(h, hpos, m, mpos, n, k) {
|
|
1834
|
-
var x = new Uint8Array(16);
|
|
1835
|
-
crypto_onetimeauth(x,0,m,mpos,n,k);
|
|
1836
|
-
return crypto_verify_16(h,hpos,x,0);
|
|
1837
|
-
}
|
|
1838
|
-
|
|
1839
|
-
function crypto_secretbox(c,m,d,n,k) {
|
|
1840
|
-
var i;
|
|
1841
|
-
if (d < 32) return -1;
|
|
1842
|
-
crypto_stream_xor(c,0,m,0,d,n,k);
|
|
1843
|
-
crypto_onetimeauth(c, 16, c, 32, d - 32, c);
|
|
1844
|
-
for (i = 0; i < 16; i++) c[i] = 0;
|
|
1845
|
-
return 0;
|
|
1846
|
-
}
|
|
1847
|
-
|
|
1848
|
-
function crypto_secretbox_open(m,c,d,n,k) {
|
|
1849
|
-
var i;
|
|
1850
|
-
var x = new Uint8Array(32);
|
|
1851
|
-
if (d < 32) return -1;
|
|
1852
|
-
crypto_stream(x,0,32,n,k);
|
|
1853
|
-
if (crypto_onetimeauth_verify(c, 16,c, 32,d - 32,x) !== 0) return -1;
|
|
1854
|
-
crypto_stream_xor(m,0,c,0,d,n,k);
|
|
1855
|
-
for (i = 0; i < 32; i++) m[i] = 0;
|
|
1856
|
-
return 0;
|
|
1857
|
-
}
|
|
1858
|
-
|
|
1859
|
-
function set25519(r, a) {
|
|
1860
|
-
var i;
|
|
1861
|
-
for (i = 0; i < 16; i++) r[i] = a[i]|0;
|
|
1862
|
-
}
|
|
1863
|
-
|
|
1864
|
-
function car25519(o) {
|
|
1865
|
-
var i, v, c = 1;
|
|
1866
|
-
for (i = 0; i < 16; i++) {
|
|
1867
|
-
v = o[i] + c + 65535;
|
|
1868
|
-
c = Math.floor(v / 65536);
|
|
1869
|
-
o[i] = v - c * 65536;
|
|
1870
|
-
}
|
|
1871
|
-
o[0] += c-1 + 37 * (c-1);
|
|
1872
|
-
}
|
|
1873
|
-
|
|
1874
|
-
function sel25519(p, q, b) {
|
|
1875
|
-
var t, c = ~(b-1);
|
|
1876
|
-
for (var i = 0; i < 16; i++) {
|
|
1877
|
-
t = c & (p[i] ^ q[i]);
|
|
1878
|
-
p[i] ^= t;
|
|
1879
|
-
q[i] ^= t;
|
|
1880
|
-
}
|
|
1881
|
-
}
|
|
1882
|
-
|
|
1883
|
-
function pack25519(o, n) {
|
|
1884
|
-
var i, j, b;
|
|
1885
|
-
var m = gf(), t = gf();
|
|
1886
|
-
for (i = 0; i < 16; i++) t[i] = n[i];
|
|
1887
|
-
car25519(t);
|
|
1888
|
-
car25519(t);
|
|
1889
|
-
car25519(t);
|
|
1890
|
-
for (j = 0; j < 2; j++) {
|
|
1891
|
-
m[0] = t[0] - 0xffed;
|
|
1892
|
-
for (i = 1; i < 15; i++) {
|
|
1893
|
-
m[i] = t[i] - 0xffff - ((m[i-1]>>16) & 1);
|
|
1894
|
-
m[i-1] &= 0xffff;
|
|
1895
|
-
}
|
|
1896
|
-
m[15] = t[15] - 0x7fff - ((m[14]>>16) & 1);
|
|
1897
|
-
b = (m[15]>>16) & 1;
|
|
1898
|
-
m[14] &= 0xffff;
|
|
1899
|
-
sel25519(t, m, 1-b);
|
|
1900
|
-
}
|
|
1901
|
-
for (i = 0; i < 16; i++) {
|
|
1902
|
-
o[2*i] = t[i] & 0xff;
|
|
1903
|
-
o[2*i+1] = t[i]>>8;
|
|
1904
|
-
}
|
|
1905
|
-
}
|
|
1906
|
-
|
|
1907
|
-
function neq25519(a, b) {
|
|
1908
|
-
var c = new Uint8Array(32), d = new Uint8Array(32);
|
|
1909
|
-
pack25519(c, a);
|
|
1910
|
-
pack25519(d, b);
|
|
1911
|
-
return crypto_verify_32(c, 0, d, 0);
|
|
1912
|
-
}
|
|
1913
|
-
|
|
1914
|
-
function par25519(a) {
|
|
1915
|
-
var d = new Uint8Array(32);
|
|
1916
|
-
pack25519(d, a);
|
|
1917
|
-
return d[0] & 1;
|
|
1918
|
-
}
|
|
1919
|
-
|
|
1920
|
-
function unpack25519(o, n) {
|
|
1921
|
-
var i;
|
|
1922
|
-
for (i = 0; i < 16; i++) o[i] = n[2*i] + (n[2*i+1] << 8);
|
|
1923
|
-
o[15] &= 0x7fff;
|
|
1924
|
-
}
|
|
1925
|
-
|
|
1926
|
-
function A(o, a, b) {
|
|
1927
|
-
for (var i = 0; i < 16; i++) o[i] = a[i] + b[i];
|
|
1928
|
-
}
|
|
1929
|
-
|
|
1930
|
-
function Z(o, a, b) {
|
|
1931
|
-
for (var i = 0; i < 16; i++) o[i] = a[i] - b[i];
|
|
1932
|
-
}
|
|
1933
|
-
|
|
1934
|
-
function M(o, a, b) {
|
|
1935
|
-
var v, c,
|
|
1936
|
-
t0 = 0, t1 = 0, t2 = 0, t3 = 0, t4 = 0, t5 = 0, t6 = 0, t7 = 0,
|
|
1937
|
-
t8 = 0, t9 = 0, t10 = 0, t11 = 0, t12 = 0, t13 = 0, t14 = 0, t15 = 0,
|
|
1938
|
-
t16 = 0, t17 = 0, t18 = 0, t19 = 0, t20 = 0, t21 = 0, t22 = 0, t23 = 0,
|
|
1939
|
-
t24 = 0, t25 = 0, t26 = 0, t27 = 0, t28 = 0, t29 = 0, t30 = 0,
|
|
1940
|
-
b0 = b[0],
|
|
1941
|
-
b1 = b[1],
|
|
1942
|
-
b2 = b[2],
|
|
1943
|
-
b3 = b[3],
|
|
1944
|
-
b4 = b[4],
|
|
1945
|
-
b5 = b[5],
|
|
1946
|
-
b6 = b[6],
|
|
1947
|
-
b7 = b[7],
|
|
1948
|
-
b8 = b[8],
|
|
1949
|
-
b9 = b[9],
|
|
1950
|
-
b10 = b[10],
|
|
1951
|
-
b11 = b[11],
|
|
1952
|
-
b12 = b[12],
|
|
1953
|
-
b13 = b[13],
|
|
1954
|
-
b14 = b[14],
|
|
1955
|
-
b15 = b[15];
|
|
1956
|
-
|
|
1957
|
-
v = a[0];
|
|
1958
|
-
t0 += v * b0;
|
|
1959
|
-
t1 += v * b1;
|
|
1960
|
-
t2 += v * b2;
|
|
1961
|
-
t3 += v * b3;
|
|
1962
|
-
t4 += v * b4;
|
|
1963
|
-
t5 += v * b5;
|
|
1964
|
-
t6 += v * b6;
|
|
1965
|
-
t7 += v * b7;
|
|
1966
|
-
t8 += v * b8;
|
|
1967
|
-
t9 += v * b9;
|
|
1968
|
-
t10 += v * b10;
|
|
1969
|
-
t11 += v * b11;
|
|
1970
|
-
t12 += v * b12;
|
|
1971
|
-
t13 += v * b13;
|
|
1972
|
-
t14 += v * b14;
|
|
1973
|
-
t15 += v * b15;
|
|
1974
|
-
v = a[1];
|
|
1975
|
-
t1 += v * b0;
|
|
1976
|
-
t2 += v * b1;
|
|
1977
|
-
t3 += v * b2;
|
|
1978
|
-
t4 += v * b3;
|
|
1979
|
-
t5 += v * b4;
|
|
1980
|
-
t6 += v * b5;
|
|
1981
|
-
t7 += v * b6;
|
|
1982
|
-
t8 += v * b7;
|
|
1983
|
-
t9 += v * b8;
|
|
1984
|
-
t10 += v * b9;
|
|
1985
|
-
t11 += v * b10;
|
|
1986
|
-
t12 += v * b11;
|
|
1987
|
-
t13 += v * b12;
|
|
1988
|
-
t14 += v * b13;
|
|
1989
|
-
t15 += v * b14;
|
|
1990
|
-
t16 += v * b15;
|
|
1991
|
-
v = a[2];
|
|
1992
|
-
t2 += v * b0;
|
|
1993
|
-
t3 += v * b1;
|
|
1994
|
-
t4 += v * b2;
|
|
1995
|
-
t5 += v * b3;
|
|
1996
|
-
t6 += v * b4;
|
|
1997
|
-
t7 += v * b5;
|
|
1998
|
-
t8 += v * b6;
|
|
1999
|
-
t9 += v * b7;
|
|
2000
|
-
t10 += v * b8;
|
|
2001
|
-
t11 += v * b9;
|
|
2002
|
-
t12 += v * b10;
|
|
2003
|
-
t13 += v * b11;
|
|
2004
|
-
t14 += v * b12;
|
|
2005
|
-
t15 += v * b13;
|
|
2006
|
-
t16 += v * b14;
|
|
2007
|
-
t17 += v * b15;
|
|
2008
|
-
v = a[3];
|
|
2009
|
-
t3 += v * b0;
|
|
2010
|
-
t4 += v * b1;
|
|
2011
|
-
t5 += v * b2;
|
|
2012
|
-
t6 += v * b3;
|
|
2013
|
-
t7 += v * b4;
|
|
2014
|
-
t8 += v * b5;
|
|
2015
|
-
t9 += v * b6;
|
|
2016
|
-
t10 += v * b7;
|
|
2017
|
-
t11 += v * b8;
|
|
2018
|
-
t12 += v * b9;
|
|
2019
|
-
t13 += v * b10;
|
|
2020
|
-
t14 += v * b11;
|
|
2021
|
-
t15 += v * b12;
|
|
2022
|
-
t16 += v * b13;
|
|
2023
|
-
t17 += v * b14;
|
|
2024
|
-
t18 += v * b15;
|
|
2025
|
-
v = a[4];
|
|
2026
|
-
t4 += v * b0;
|
|
2027
|
-
t5 += v * b1;
|
|
2028
|
-
t6 += v * b2;
|
|
2029
|
-
t7 += v * b3;
|
|
2030
|
-
t8 += v * b4;
|
|
2031
|
-
t9 += v * b5;
|
|
2032
|
-
t10 += v * b6;
|
|
2033
|
-
t11 += v * b7;
|
|
2034
|
-
t12 += v * b8;
|
|
2035
|
-
t13 += v * b9;
|
|
2036
|
-
t14 += v * b10;
|
|
2037
|
-
t15 += v * b11;
|
|
2038
|
-
t16 += v * b12;
|
|
2039
|
-
t17 += v * b13;
|
|
2040
|
-
t18 += v * b14;
|
|
2041
|
-
t19 += v * b15;
|
|
2042
|
-
v = a[5];
|
|
2043
|
-
t5 += v * b0;
|
|
2044
|
-
t6 += v * b1;
|
|
2045
|
-
t7 += v * b2;
|
|
2046
|
-
t8 += v * b3;
|
|
2047
|
-
t9 += v * b4;
|
|
2048
|
-
t10 += v * b5;
|
|
2049
|
-
t11 += v * b6;
|
|
2050
|
-
t12 += v * b7;
|
|
2051
|
-
t13 += v * b8;
|
|
2052
|
-
t14 += v * b9;
|
|
2053
|
-
t15 += v * b10;
|
|
2054
|
-
t16 += v * b11;
|
|
2055
|
-
t17 += v * b12;
|
|
2056
|
-
t18 += v * b13;
|
|
2057
|
-
t19 += v * b14;
|
|
2058
|
-
t20 += v * b15;
|
|
2059
|
-
v = a[6];
|
|
2060
|
-
t6 += v * b0;
|
|
2061
|
-
t7 += v * b1;
|
|
2062
|
-
t8 += v * b2;
|
|
2063
|
-
t9 += v * b3;
|
|
2064
|
-
t10 += v * b4;
|
|
2065
|
-
t11 += v * b5;
|
|
2066
|
-
t12 += v * b6;
|
|
2067
|
-
t13 += v * b7;
|
|
2068
|
-
t14 += v * b8;
|
|
2069
|
-
t15 += v * b9;
|
|
2070
|
-
t16 += v * b10;
|
|
2071
|
-
t17 += v * b11;
|
|
2072
|
-
t18 += v * b12;
|
|
2073
|
-
t19 += v * b13;
|
|
2074
|
-
t20 += v * b14;
|
|
2075
|
-
t21 += v * b15;
|
|
2076
|
-
v = a[7];
|
|
2077
|
-
t7 += v * b0;
|
|
2078
|
-
t8 += v * b1;
|
|
2079
|
-
t9 += v * b2;
|
|
2080
|
-
t10 += v * b3;
|
|
2081
|
-
t11 += v * b4;
|
|
2082
|
-
t12 += v * b5;
|
|
2083
|
-
t13 += v * b6;
|
|
2084
|
-
t14 += v * b7;
|
|
2085
|
-
t15 += v * b8;
|
|
2086
|
-
t16 += v * b9;
|
|
2087
|
-
t17 += v * b10;
|
|
2088
|
-
t18 += v * b11;
|
|
2089
|
-
t19 += v * b12;
|
|
2090
|
-
t20 += v * b13;
|
|
2091
|
-
t21 += v * b14;
|
|
2092
|
-
t22 += v * b15;
|
|
2093
|
-
v = a[8];
|
|
2094
|
-
t8 += v * b0;
|
|
2095
|
-
t9 += v * b1;
|
|
2096
|
-
t10 += v * b2;
|
|
2097
|
-
t11 += v * b3;
|
|
2098
|
-
t12 += v * b4;
|
|
2099
|
-
t13 += v * b5;
|
|
2100
|
-
t14 += v * b6;
|
|
2101
|
-
t15 += v * b7;
|
|
2102
|
-
t16 += v * b8;
|
|
2103
|
-
t17 += v * b9;
|
|
2104
|
-
t18 += v * b10;
|
|
2105
|
-
t19 += v * b11;
|
|
2106
|
-
t20 += v * b12;
|
|
2107
|
-
t21 += v * b13;
|
|
2108
|
-
t22 += v * b14;
|
|
2109
|
-
t23 += v * b15;
|
|
2110
|
-
v = a[9];
|
|
2111
|
-
t9 += v * b0;
|
|
2112
|
-
t10 += v * b1;
|
|
2113
|
-
t11 += v * b2;
|
|
2114
|
-
t12 += v * b3;
|
|
2115
|
-
t13 += v * b4;
|
|
2116
|
-
t14 += v * b5;
|
|
2117
|
-
t15 += v * b6;
|
|
2118
|
-
t16 += v * b7;
|
|
2119
|
-
t17 += v * b8;
|
|
2120
|
-
t18 += v * b9;
|
|
2121
|
-
t19 += v * b10;
|
|
2122
|
-
t20 += v * b11;
|
|
2123
|
-
t21 += v * b12;
|
|
2124
|
-
t22 += v * b13;
|
|
2125
|
-
t23 += v * b14;
|
|
2126
|
-
t24 += v * b15;
|
|
2127
|
-
v = a[10];
|
|
2128
|
-
t10 += v * b0;
|
|
2129
|
-
t11 += v * b1;
|
|
2130
|
-
t12 += v * b2;
|
|
2131
|
-
t13 += v * b3;
|
|
2132
|
-
t14 += v * b4;
|
|
2133
|
-
t15 += v * b5;
|
|
2134
|
-
t16 += v * b6;
|
|
2135
|
-
t17 += v * b7;
|
|
2136
|
-
t18 += v * b8;
|
|
2137
|
-
t19 += v * b9;
|
|
2138
|
-
t20 += v * b10;
|
|
2139
|
-
t21 += v * b11;
|
|
2140
|
-
t22 += v * b12;
|
|
2141
|
-
t23 += v * b13;
|
|
2142
|
-
t24 += v * b14;
|
|
2143
|
-
t25 += v * b15;
|
|
2144
|
-
v = a[11];
|
|
2145
|
-
t11 += v * b0;
|
|
2146
|
-
t12 += v * b1;
|
|
2147
|
-
t13 += v * b2;
|
|
2148
|
-
t14 += v * b3;
|
|
2149
|
-
t15 += v * b4;
|
|
2150
|
-
t16 += v * b5;
|
|
2151
|
-
t17 += v * b6;
|
|
2152
|
-
t18 += v * b7;
|
|
2153
|
-
t19 += v * b8;
|
|
2154
|
-
t20 += v * b9;
|
|
2155
|
-
t21 += v * b10;
|
|
2156
|
-
t22 += v * b11;
|
|
2157
|
-
t23 += v * b12;
|
|
2158
|
-
t24 += v * b13;
|
|
2159
|
-
t25 += v * b14;
|
|
2160
|
-
t26 += v * b15;
|
|
2161
|
-
v = a[12];
|
|
2162
|
-
t12 += v * b0;
|
|
2163
|
-
t13 += v * b1;
|
|
2164
|
-
t14 += v * b2;
|
|
2165
|
-
t15 += v * b3;
|
|
2166
|
-
t16 += v * b4;
|
|
2167
|
-
t17 += v * b5;
|
|
2168
|
-
t18 += v * b6;
|
|
2169
|
-
t19 += v * b7;
|
|
2170
|
-
t20 += v * b8;
|
|
2171
|
-
t21 += v * b9;
|
|
2172
|
-
t22 += v * b10;
|
|
2173
|
-
t23 += v * b11;
|
|
2174
|
-
t24 += v * b12;
|
|
2175
|
-
t25 += v * b13;
|
|
2176
|
-
t26 += v * b14;
|
|
2177
|
-
t27 += v * b15;
|
|
2178
|
-
v = a[13];
|
|
2179
|
-
t13 += v * b0;
|
|
2180
|
-
t14 += v * b1;
|
|
2181
|
-
t15 += v * b2;
|
|
2182
|
-
t16 += v * b3;
|
|
2183
|
-
t17 += v * b4;
|
|
2184
|
-
t18 += v * b5;
|
|
2185
|
-
t19 += v * b6;
|
|
2186
|
-
t20 += v * b7;
|
|
2187
|
-
t21 += v * b8;
|
|
2188
|
-
t22 += v * b9;
|
|
2189
|
-
t23 += v * b10;
|
|
2190
|
-
t24 += v * b11;
|
|
2191
|
-
t25 += v * b12;
|
|
2192
|
-
t26 += v * b13;
|
|
2193
|
-
t27 += v * b14;
|
|
2194
|
-
t28 += v * b15;
|
|
2195
|
-
v = a[14];
|
|
2196
|
-
t14 += v * b0;
|
|
2197
|
-
t15 += v * b1;
|
|
2198
|
-
t16 += v * b2;
|
|
2199
|
-
t17 += v * b3;
|
|
2200
|
-
t18 += v * b4;
|
|
2201
|
-
t19 += v * b5;
|
|
2202
|
-
t20 += v * b6;
|
|
2203
|
-
t21 += v * b7;
|
|
2204
|
-
t22 += v * b8;
|
|
2205
|
-
t23 += v * b9;
|
|
2206
|
-
t24 += v * b10;
|
|
2207
|
-
t25 += v * b11;
|
|
2208
|
-
t26 += v * b12;
|
|
2209
|
-
t27 += v * b13;
|
|
2210
|
-
t28 += v * b14;
|
|
2211
|
-
t29 += v * b15;
|
|
2212
|
-
v = a[15];
|
|
2213
|
-
t15 += v * b0;
|
|
2214
|
-
t16 += v * b1;
|
|
2215
|
-
t17 += v * b2;
|
|
2216
|
-
t18 += v * b3;
|
|
2217
|
-
t19 += v * b4;
|
|
2218
|
-
t20 += v * b5;
|
|
2219
|
-
t21 += v * b6;
|
|
2220
|
-
t22 += v * b7;
|
|
2221
|
-
t23 += v * b8;
|
|
2222
|
-
t24 += v * b9;
|
|
2223
|
-
t25 += v * b10;
|
|
2224
|
-
t26 += v * b11;
|
|
2225
|
-
t27 += v * b12;
|
|
2226
|
-
t28 += v * b13;
|
|
2227
|
-
t29 += v * b14;
|
|
2228
|
-
t30 += v * b15;
|
|
2229
|
-
|
|
2230
|
-
t0 += 38 * t16;
|
|
2231
|
-
t1 += 38 * t17;
|
|
2232
|
-
t2 += 38 * t18;
|
|
2233
|
-
t3 += 38 * t19;
|
|
2234
|
-
t4 += 38 * t20;
|
|
2235
|
-
t5 += 38 * t21;
|
|
2236
|
-
t6 += 38 * t22;
|
|
2237
|
-
t7 += 38 * t23;
|
|
2238
|
-
t8 += 38 * t24;
|
|
2239
|
-
t9 += 38 * t25;
|
|
2240
|
-
t10 += 38 * t26;
|
|
2241
|
-
t11 += 38 * t27;
|
|
2242
|
-
t12 += 38 * t28;
|
|
2243
|
-
t13 += 38 * t29;
|
|
2244
|
-
t14 += 38 * t30;
|
|
2245
|
-
// t15 left as is
|
|
2246
|
-
|
|
2247
|
-
// first car
|
|
2248
|
-
c = 1;
|
|
2249
|
-
v = t0 + c + 65535; c = Math.floor(v / 65536); t0 = v - c * 65536;
|
|
2250
|
-
v = t1 + c + 65535; c = Math.floor(v / 65536); t1 = v - c * 65536;
|
|
2251
|
-
v = t2 + c + 65535; c = Math.floor(v / 65536); t2 = v - c * 65536;
|
|
2252
|
-
v = t3 + c + 65535; c = Math.floor(v / 65536); t3 = v - c * 65536;
|
|
2253
|
-
v = t4 + c + 65535; c = Math.floor(v / 65536); t4 = v - c * 65536;
|
|
2254
|
-
v = t5 + c + 65535; c = Math.floor(v / 65536); t5 = v - c * 65536;
|
|
2255
|
-
v = t6 + c + 65535; c = Math.floor(v / 65536); t6 = v - c * 65536;
|
|
2256
|
-
v = t7 + c + 65535; c = Math.floor(v / 65536); t7 = v - c * 65536;
|
|
2257
|
-
v = t8 + c + 65535; c = Math.floor(v / 65536); t8 = v - c * 65536;
|
|
2258
|
-
v = t9 + c + 65535; c = Math.floor(v / 65536); t9 = v - c * 65536;
|
|
2259
|
-
v = t10 + c + 65535; c = Math.floor(v / 65536); t10 = v - c * 65536;
|
|
2260
|
-
v = t11 + c + 65535; c = Math.floor(v / 65536); t11 = v - c * 65536;
|
|
2261
|
-
v = t12 + c + 65535; c = Math.floor(v / 65536); t12 = v - c * 65536;
|
|
2262
|
-
v = t13 + c + 65535; c = Math.floor(v / 65536); t13 = v - c * 65536;
|
|
2263
|
-
v = t14 + c + 65535; c = Math.floor(v / 65536); t14 = v - c * 65536;
|
|
2264
|
-
v = t15 + c + 65535; c = Math.floor(v / 65536); t15 = v - c * 65536;
|
|
2265
|
-
t0 += c-1 + 37 * (c-1);
|
|
2266
|
-
|
|
2267
|
-
// second car
|
|
2268
|
-
c = 1;
|
|
2269
|
-
v = t0 + c + 65535; c = Math.floor(v / 65536); t0 = v - c * 65536;
|
|
2270
|
-
v = t1 + c + 65535; c = Math.floor(v / 65536); t1 = v - c * 65536;
|
|
2271
|
-
v = t2 + c + 65535; c = Math.floor(v / 65536); t2 = v - c * 65536;
|
|
2272
|
-
v = t3 + c + 65535; c = Math.floor(v / 65536); t3 = v - c * 65536;
|
|
2273
|
-
v = t4 + c + 65535; c = Math.floor(v / 65536); t4 = v - c * 65536;
|
|
2274
|
-
v = t5 + c + 65535; c = Math.floor(v / 65536); t5 = v - c * 65536;
|
|
2275
|
-
v = t6 + c + 65535; c = Math.floor(v / 65536); t6 = v - c * 65536;
|
|
2276
|
-
v = t7 + c + 65535; c = Math.floor(v / 65536); t7 = v - c * 65536;
|
|
2277
|
-
v = t8 + c + 65535; c = Math.floor(v / 65536); t8 = v - c * 65536;
|
|
2278
|
-
v = t9 + c + 65535; c = Math.floor(v / 65536); t9 = v - c * 65536;
|
|
2279
|
-
v = t10 + c + 65535; c = Math.floor(v / 65536); t10 = v - c * 65536;
|
|
2280
|
-
v = t11 + c + 65535; c = Math.floor(v / 65536); t11 = v - c * 65536;
|
|
2281
|
-
v = t12 + c + 65535; c = Math.floor(v / 65536); t12 = v - c * 65536;
|
|
2282
|
-
v = t13 + c + 65535; c = Math.floor(v / 65536); t13 = v - c * 65536;
|
|
2283
|
-
v = t14 + c + 65535; c = Math.floor(v / 65536); t14 = v - c * 65536;
|
|
2284
|
-
v = t15 + c + 65535; c = Math.floor(v / 65536); t15 = v - c * 65536;
|
|
2285
|
-
t0 += c-1 + 37 * (c-1);
|
|
2286
|
-
|
|
2287
|
-
o[ 0] = t0;
|
|
2288
|
-
o[ 1] = t1;
|
|
2289
|
-
o[ 2] = t2;
|
|
2290
|
-
o[ 3] = t3;
|
|
2291
|
-
o[ 4] = t4;
|
|
2292
|
-
o[ 5] = t5;
|
|
2293
|
-
o[ 6] = t6;
|
|
2294
|
-
o[ 7] = t7;
|
|
2295
|
-
o[ 8] = t8;
|
|
2296
|
-
o[ 9] = t9;
|
|
2297
|
-
o[10] = t10;
|
|
2298
|
-
o[11] = t11;
|
|
2299
|
-
o[12] = t12;
|
|
2300
|
-
o[13] = t13;
|
|
2301
|
-
o[14] = t14;
|
|
2302
|
-
o[15] = t15;
|
|
2303
|
-
}
|
|
2304
|
-
|
|
2305
|
-
function S(o, a) {
|
|
2306
|
-
M(o, a, a);
|
|
2307
|
-
}
|
|
2308
|
-
|
|
2309
|
-
function inv25519(o, i) {
|
|
2310
|
-
var c = gf();
|
|
2311
|
-
var a;
|
|
2312
|
-
for (a = 0; a < 16; a++) c[a] = i[a];
|
|
2313
|
-
for (a = 253; a >= 0; a--) {
|
|
2314
|
-
S(c, c);
|
|
2315
|
-
if(a !== 2 && a !== 4) M(c, c, i);
|
|
2316
|
-
}
|
|
2317
|
-
for (a = 0; a < 16; a++) o[a] = c[a];
|
|
2318
|
-
}
|
|
2319
|
-
|
|
2320
|
-
function pow2523(o, i) {
|
|
2321
|
-
var c = gf();
|
|
2322
|
-
var a;
|
|
2323
|
-
for (a = 0; a < 16; a++) c[a] = i[a];
|
|
2324
|
-
for (a = 250; a >= 0; a--) {
|
|
2325
|
-
S(c, c);
|
|
2326
|
-
if(a !== 1) M(c, c, i);
|
|
2327
|
-
}
|
|
2328
|
-
for (a = 0; a < 16; a++) o[a] = c[a];
|
|
2329
|
-
}
|
|
2330
|
-
|
|
2331
|
-
function crypto_scalarmult(q, n, p) {
|
|
2332
|
-
var z = new Uint8Array(32);
|
|
2333
|
-
var x = new Float64Array(80), r, i;
|
|
2334
|
-
var a = gf(), b = gf(), c = gf(),
|
|
2335
|
-
d = gf(), e = gf(), f = gf();
|
|
2336
|
-
for (i = 0; i < 31; i++) z[i] = n[i];
|
|
2337
|
-
z[31]=(n[31]&127)|64;
|
|
2338
|
-
z[0]&=248;
|
|
2339
|
-
unpack25519(x,p);
|
|
2340
|
-
for (i = 0; i < 16; i++) {
|
|
2341
|
-
b[i]=x[i];
|
|
2342
|
-
d[i]=a[i]=c[i]=0;
|
|
2343
|
-
}
|
|
2344
|
-
a[0]=d[0]=1;
|
|
2345
|
-
for (i=254; i>=0; --i) {
|
|
2346
|
-
r=(z[i>>>3]>>>(i&7))&1;
|
|
2347
|
-
sel25519(a,b,r);
|
|
2348
|
-
sel25519(c,d,r);
|
|
2349
|
-
A(e,a,c);
|
|
2350
|
-
Z(a,a,c);
|
|
2351
|
-
A(c,b,d);
|
|
2352
|
-
Z(b,b,d);
|
|
2353
|
-
S(d,e);
|
|
2354
|
-
S(f,a);
|
|
2355
|
-
M(a,c,a);
|
|
2356
|
-
M(c,b,e);
|
|
2357
|
-
A(e,a,c);
|
|
2358
|
-
Z(a,a,c);
|
|
2359
|
-
S(b,a);
|
|
2360
|
-
Z(c,d,f);
|
|
2361
|
-
M(a,c,_121665);
|
|
2362
|
-
A(a,a,d);
|
|
2363
|
-
M(c,c,a);
|
|
2364
|
-
M(a,d,f);
|
|
2365
|
-
M(d,b,x);
|
|
2366
|
-
S(b,e);
|
|
2367
|
-
sel25519(a,b,r);
|
|
2368
|
-
sel25519(c,d,r);
|
|
2369
|
-
}
|
|
2370
|
-
for (i = 0; i < 16; i++) {
|
|
2371
|
-
x[i+16]=a[i];
|
|
2372
|
-
x[i+32]=c[i];
|
|
2373
|
-
x[i+48]=b[i];
|
|
2374
|
-
x[i+64]=d[i];
|
|
2375
|
-
}
|
|
2376
|
-
var x32 = x.subarray(32);
|
|
2377
|
-
var x16 = x.subarray(16);
|
|
2378
|
-
inv25519(x32,x32);
|
|
2379
|
-
M(x16,x16,x32);
|
|
2380
|
-
pack25519(q,x16);
|
|
2381
|
-
return 0;
|
|
2382
|
-
}
|
|
2383
|
-
|
|
2384
|
-
function crypto_scalarmult_base(q, n) {
|
|
2385
|
-
return crypto_scalarmult(q, n, _9);
|
|
2386
|
-
}
|
|
2387
|
-
|
|
2388
|
-
function crypto_box_keypair(y, x) {
|
|
2389
|
-
randombytes(x, 32);
|
|
2390
|
-
return crypto_scalarmult_base(y, x);
|
|
2391
|
-
}
|
|
2392
|
-
|
|
2393
|
-
function crypto_box_beforenm(k, y, x) {
|
|
2394
|
-
var s = new Uint8Array(32);
|
|
2395
|
-
crypto_scalarmult(s, x, y);
|
|
2396
|
-
return crypto_core_hsalsa20(k, _0, s, sigma);
|
|
2397
|
-
}
|
|
2398
|
-
|
|
2399
|
-
var crypto_box_afternm = crypto_secretbox;
|
|
2400
|
-
var crypto_box_open_afternm = crypto_secretbox_open;
|
|
2401
|
-
|
|
2402
|
-
function crypto_box(c, m, d, n, y, x) {
|
|
2403
|
-
var k = new Uint8Array(32);
|
|
2404
|
-
crypto_box_beforenm(k, y, x);
|
|
2405
|
-
return crypto_box_afternm(c, m, d, n, k);
|
|
2406
|
-
}
|
|
2407
|
-
|
|
2408
|
-
function crypto_box_open(m, c, d, n, y, x) {
|
|
2409
|
-
var k = new Uint8Array(32);
|
|
2410
|
-
crypto_box_beforenm(k, y, x);
|
|
2411
|
-
return crypto_box_open_afternm(m, c, d, n, k);
|
|
2412
|
-
}
|
|
2413
|
-
|
|
2414
|
-
var K = [
|
|
2415
|
-
0x428a2f98, 0xd728ae22, 0x71374491, 0x23ef65cd,
|
|
2416
|
-
0xb5c0fbcf, 0xec4d3b2f, 0xe9b5dba5, 0x8189dbbc,
|
|
2417
|
-
0x3956c25b, 0xf348b538, 0x59f111f1, 0xb605d019,
|
|
2418
|
-
0x923f82a4, 0xaf194f9b, 0xab1c5ed5, 0xda6d8118,
|
|
2419
|
-
0xd807aa98, 0xa3030242, 0x12835b01, 0x45706fbe,
|
|
2420
|
-
0x243185be, 0x4ee4b28c, 0x550c7dc3, 0xd5ffb4e2,
|
|
2421
|
-
0x72be5d74, 0xf27b896f, 0x80deb1fe, 0x3b1696b1,
|
|
2422
|
-
0x9bdc06a7, 0x25c71235, 0xc19bf174, 0xcf692694,
|
|
2423
|
-
0xe49b69c1, 0x9ef14ad2, 0xefbe4786, 0x384f25e3,
|
|
2424
|
-
0x0fc19dc6, 0x8b8cd5b5, 0x240ca1cc, 0x77ac9c65,
|
|
2425
|
-
0x2de92c6f, 0x592b0275, 0x4a7484aa, 0x6ea6e483,
|
|
2426
|
-
0x5cb0a9dc, 0xbd41fbd4, 0x76f988da, 0x831153b5,
|
|
2427
|
-
0x983e5152, 0xee66dfab, 0xa831c66d, 0x2db43210,
|
|
2428
|
-
0xb00327c8, 0x98fb213f, 0xbf597fc7, 0xbeef0ee4,
|
|
2429
|
-
0xc6e00bf3, 0x3da88fc2, 0xd5a79147, 0x930aa725,
|
|
2430
|
-
0x06ca6351, 0xe003826f, 0x14292967, 0x0a0e6e70,
|
|
2431
|
-
0x27b70a85, 0x46d22ffc, 0x2e1b2138, 0x5c26c926,
|
|
2432
|
-
0x4d2c6dfc, 0x5ac42aed, 0x53380d13, 0x9d95b3df,
|
|
2433
|
-
0x650a7354, 0x8baf63de, 0x766a0abb, 0x3c77b2a8,
|
|
2434
|
-
0x81c2c92e, 0x47edaee6, 0x92722c85, 0x1482353b,
|
|
2435
|
-
0xa2bfe8a1, 0x4cf10364, 0xa81a664b, 0xbc423001,
|
|
2436
|
-
0xc24b8b70, 0xd0f89791, 0xc76c51a3, 0x0654be30,
|
|
2437
|
-
0xd192e819, 0xd6ef5218, 0xd6990624, 0x5565a910,
|
|
2438
|
-
0xf40e3585, 0x5771202a, 0x106aa070, 0x32bbd1b8,
|
|
2439
|
-
0x19a4c116, 0xb8d2d0c8, 0x1e376c08, 0x5141ab53,
|
|
2440
|
-
0x2748774c, 0xdf8eeb99, 0x34b0bcb5, 0xe19b48a8,
|
|
2441
|
-
0x391c0cb3, 0xc5c95a63, 0x4ed8aa4a, 0xe3418acb,
|
|
2442
|
-
0x5b9cca4f, 0x7763e373, 0x682e6ff3, 0xd6b2b8a3,
|
|
2443
|
-
0x748f82ee, 0x5defb2fc, 0x78a5636f, 0x43172f60,
|
|
2444
|
-
0x84c87814, 0xa1f0ab72, 0x8cc70208, 0x1a6439ec,
|
|
2445
|
-
0x90befffa, 0x23631e28, 0xa4506ceb, 0xde82bde9,
|
|
2446
|
-
0xbef9a3f7, 0xb2c67915, 0xc67178f2, 0xe372532b,
|
|
2447
|
-
0xca273ece, 0xea26619c, 0xd186b8c7, 0x21c0c207,
|
|
2448
|
-
0xeada7dd6, 0xcde0eb1e, 0xf57d4f7f, 0xee6ed178,
|
|
2449
|
-
0x06f067aa, 0x72176fba, 0x0a637dc5, 0xa2c898a6,
|
|
2450
|
-
0x113f9804, 0xbef90dae, 0x1b710b35, 0x131c471b,
|
|
2451
|
-
0x28db77f5, 0x23047d84, 0x32caab7b, 0x40c72493,
|
|
2452
|
-
0x3c9ebe0a, 0x15c9bebc, 0x431d67c4, 0x9c100d4c,
|
|
2453
|
-
0x4cc5d4be, 0xcb3e42b6, 0x597f299c, 0xfc657e2a,
|
|
2454
|
-
0x5fcb6fab, 0x3ad6faec, 0x6c44198c, 0x4a475817
|
|
2455
|
-
];
|
|
2456
|
-
|
|
2457
|
-
function crypto_hashblocks_hl(hh, hl, m, n) {
|
|
2458
|
-
var wh = new Int32Array(16), wl = new Int32Array(16),
|
|
2459
|
-
bh0, bh1, bh2, bh3, bh4, bh5, bh6, bh7,
|
|
2460
|
-
bl0, bl1, bl2, bl3, bl4, bl5, bl6, bl7,
|
|
2461
|
-
th, tl, i, j, h, l, a, b, c, d;
|
|
2462
|
-
|
|
2463
|
-
var ah0 = hh[0],
|
|
2464
|
-
ah1 = hh[1],
|
|
2465
|
-
ah2 = hh[2],
|
|
2466
|
-
ah3 = hh[3],
|
|
2467
|
-
ah4 = hh[4],
|
|
2468
|
-
ah5 = hh[5],
|
|
2469
|
-
ah6 = hh[6],
|
|
2470
|
-
ah7 = hh[7],
|
|
2471
|
-
|
|
2472
|
-
al0 = hl[0],
|
|
2473
|
-
al1 = hl[1],
|
|
2474
|
-
al2 = hl[2],
|
|
2475
|
-
al3 = hl[3],
|
|
2476
|
-
al4 = hl[4],
|
|
2477
|
-
al5 = hl[5],
|
|
2478
|
-
al6 = hl[6],
|
|
2479
|
-
al7 = hl[7];
|
|
2480
|
-
|
|
2481
|
-
var pos = 0;
|
|
2482
|
-
while (n >= 128) {
|
|
2483
|
-
for (i = 0; i < 16; i++) {
|
|
2484
|
-
j = 8 * i + pos;
|
|
2485
|
-
wh[i] = (m[j+0] << 24) | (m[j+1] << 16) | (m[j+2] << 8) | m[j+3];
|
|
2486
|
-
wl[i] = (m[j+4] << 24) | (m[j+5] << 16) | (m[j+6] << 8) | m[j+7];
|
|
2487
|
-
}
|
|
2488
|
-
for (i = 0; i < 80; i++) {
|
|
2489
|
-
bh0 = ah0;
|
|
2490
|
-
bh1 = ah1;
|
|
2491
|
-
bh2 = ah2;
|
|
2492
|
-
bh3 = ah3;
|
|
2493
|
-
bh4 = ah4;
|
|
2494
|
-
bh5 = ah5;
|
|
2495
|
-
bh6 = ah6;
|
|
2496
|
-
bh7 = ah7;
|
|
2497
|
-
|
|
2498
|
-
bl0 = al0;
|
|
2499
|
-
bl1 = al1;
|
|
2500
|
-
bl2 = al2;
|
|
2501
|
-
bl3 = al3;
|
|
2502
|
-
bl4 = al4;
|
|
2503
|
-
bl5 = al5;
|
|
2504
|
-
bl6 = al6;
|
|
2505
|
-
bl7 = al7;
|
|
2506
|
-
|
|
2507
|
-
// add
|
|
2508
|
-
h = ah7;
|
|
2509
|
-
l = al7;
|
|
2510
|
-
|
|
2511
|
-
a = l & 0xffff; b = l >>> 16;
|
|
2512
|
-
c = h & 0xffff; d = h >>> 16;
|
|
2513
|
-
|
|
2514
|
-
// Sigma1
|
|
2515
|
-
h = ((ah4 >>> 14) | (al4 << (32-14))) ^ ((ah4 >>> 18) | (al4 << (32-18))) ^ ((al4 >>> (41-32)) | (ah4 << (32-(41-32))));
|
|
2516
|
-
l = ((al4 >>> 14) | (ah4 << (32-14))) ^ ((al4 >>> 18) | (ah4 << (32-18))) ^ ((ah4 >>> (41-32)) | (al4 << (32-(41-32))));
|
|
2517
|
-
|
|
2518
|
-
a += l & 0xffff; b += l >>> 16;
|
|
2519
|
-
c += h & 0xffff; d += h >>> 16;
|
|
2520
|
-
|
|
2521
|
-
// Ch
|
|
2522
|
-
h = (ah4 & ah5) ^ (~ah4 & ah6);
|
|
2523
|
-
l = (al4 & al5) ^ (~al4 & al6);
|
|
2524
|
-
|
|
2525
|
-
a += l & 0xffff; b += l >>> 16;
|
|
2526
|
-
c += h & 0xffff; d += h >>> 16;
|
|
2527
|
-
|
|
2528
|
-
// K
|
|
2529
|
-
h = K[i*2];
|
|
2530
|
-
l = K[i*2+1];
|
|
2531
|
-
|
|
2532
|
-
a += l & 0xffff; b += l >>> 16;
|
|
2533
|
-
c += h & 0xffff; d += h >>> 16;
|
|
2534
|
-
|
|
2535
|
-
// w
|
|
2536
|
-
h = wh[i%16];
|
|
2537
|
-
l = wl[i%16];
|
|
2538
|
-
|
|
2539
|
-
a += l & 0xffff; b += l >>> 16;
|
|
2540
|
-
c += h & 0xffff; d += h >>> 16;
|
|
2541
|
-
|
|
2542
|
-
b += a >>> 16;
|
|
2543
|
-
c += b >>> 16;
|
|
2544
|
-
d += c >>> 16;
|
|
2545
|
-
|
|
2546
|
-
th = c & 0xffff | d << 16;
|
|
2547
|
-
tl = a & 0xffff | b << 16;
|
|
2548
|
-
|
|
2549
|
-
// add
|
|
2550
|
-
h = th;
|
|
2551
|
-
l = tl;
|
|
2552
|
-
|
|
2553
|
-
a = l & 0xffff; b = l >>> 16;
|
|
2554
|
-
c = h & 0xffff; d = h >>> 16;
|
|
2555
|
-
|
|
2556
|
-
// Sigma0
|
|
2557
|
-
h = ((ah0 >>> 28) | (al0 << (32-28))) ^ ((al0 >>> (34-32)) | (ah0 << (32-(34-32)))) ^ ((al0 >>> (39-32)) | (ah0 << (32-(39-32))));
|
|
2558
|
-
l = ((al0 >>> 28) | (ah0 << (32-28))) ^ ((ah0 >>> (34-32)) | (al0 << (32-(34-32)))) ^ ((ah0 >>> (39-32)) | (al0 << (32-(39-32))));
|
|
2559
|
-
|
|
2560
|
-
a += l & 0xffff; b += l >>> 16;
|
|
2561
|
-
c += h & 0xffff; d += h >>> 16;
|
|
2562
|
-
|
|
2563
|
-
// Maj
|
|
2564
|
-
h = (ah0 & ah1) ^ (ah0 & ah2) ^ (ah1 & ah2);
|
|
2565
|
-
l = (al0 & al1) ^ (al0 & al2) ^ (al1 & al2);
|
|
2566
|
-
|
|
2567
|
-
a += l & 0xffff; b += l >>> 16;
|
|
2568
|
-
c += h & 0xffff; d += h >>> 16;
|
|
2569
|
-
|
|
2570
|
-
b += a >>> 16;
|
|
2571
|
-
c += b >>> 16;
|
|
2572
|
-
d += c >>> 16;
|
|
2573
|
-
|
|
2574
|
-
bh7 = (c & 0xffff) | (d << 16);
|
|
2575
|
-
bl7 = (a & 0xffff) | (b << 16);
|
|
2576
|
-
|
|
2577
|
-
// add
|
|
2578
|
-
h = bh3;
|
|
2579
|
-
l = bl3;
|
|
2580
|
-
|
|
2581
|
-
a = l & 0xffff; b = l >>> 16;
|
|
2582
|
-
c = h & 0xffff; d = h >>> 16;
|
|
2583
|
-
|
|
2584
|
-
h = th;
|
|
2585
|
-
l = tl;
|
|
2586
|
-
|
|
2587
|
-
a += l & 0xffff; b += l >>> 16;
|
|
2588
|
-
c += h & 0xffff; d += h >>> 16;
|
|
2589
|
-
|
|
2590
|
-
b += a >>> 16;
|
|
2591
|
-
c += b >>> 16;
|
|
2592
|
-
d += c >>> 16;
|
|
2593
|
-
|
|
2594
|
-
bh3 = (c & 0xffff) | (d << 16);
|
|
2595
|
-
bl3 = (a & 0xffff) | (b << 16);
|
|
2596
|
-
|
|
2597
|
-
ah1 = bh0;
|
|
2598
|
-
ah2 = bh1;
|
|
2599
|
-
ah3 = bh2;
|
|
2600
|
-
ah4 = bh3;
|
|
2601
|
-
ah5 = bh4;
|
|
2602
|
-
ah6 = bh5;
|
|
2603
|
-
ah7 = bh6;
|
|
2604
|
-
ah0 = bh7;
|
|
2605
|
-
|
|
2606
|
-
al1 = bl0;
|
|
2607
|
-
al2 = bl1;
|
|
2608
|
-
al3 = bl2;
|
|
2609
|
-
al4 = bl3;
|
|
2610
|
-
al5 = bl4;
|
|
2611
|
-
al6 = bl5;
|
|
2612
|
-
al7 = bl6;
|
|
2613
|
-
al0 = bl7;
|
|
2614
|
-
|
|
2615
|
-
if (i%16 === 15) {
|
|
2616
|
-
for (j = 0; j < 16; j++) {
|
|
2617
|
-
// add
|
|
2618
|
-
h = wh[j];
|
|
2619
|
-
l = wl[j];
|
|
2620
|
-
|
|
2621
|
-
a = l & 0xffff; b = l >>> 16;
|
|
2622
|
-
c = h & 0xffff; d = h >>> 16;
|
|
2623
|
-
|
|
2624
|
-
h = wh[(j+9)%16];
|
|
2625
|
-
l = wl[(j+9)%16];
|
|
2626
|
-
|
|
2627
|
-
a += l & 0xffff; b += l >>> 16;
|
|
2628
|
-
c += h & 0xffff; d += h >>> 16;
|
|
2629
|
-
|
|
2630
|
-
// sigma0
|
|
2631
|
-
th = wh[(j+1)%16];
|
|
2632
|
-
tl = wl[(j+1)%16];
|
|
2633
|
-
h = ((th >>> 1) | (tl << (32-1))) ^ ((th >>> 8) | (tl << (32-8))) ^ (th >>> 7);
|
|
2634
|
-
l = ((tl >>> 1) | (th << (32-1))) ^ ((tl >>> 8) | (th << (32-8))) ^ ((tl >>> 7) | (th << (32-7)));
|
|
2635
|
-
|
|
2636
|
-
a += l & 0xffff; b += l >>> 16;
|
|
2637
|
-
c += h & 0xffff; d += h >>> 16;
|
|
2638
|
-
|
|
2639
|
-
// sigma1
|
|
2640
|
-
th = wh[(j+14)%16];
|
|
2641
|
-
tl = wl[(j+14)%16];
|
|
2642
|
-
h = ((th >>> 19) | (tl << (32-19))) ^ ((tl >>> (61-32)) | (th << (32-(61-32)))) ^ (th >>> 6);
|
|
2643
|
-
l = ((tl >>> 19) | (th << (32-19))) ^ ((th >>> (61-32)) | (tl << (32-(61-32)))) ^ ((tl >>> 6) | (th << (32-6)));
|
|
2644
|
-
|
|
2645
|
-
a += l & 0xffff; b += l >>> 16;
|
|
2646
|
-
c += h & 0xffff; d += h >>> 16;
|
|
2647
|
-
|
|
2648
|
-
b += a >>> 16;
|
|
2649
|
-
c += b >>> 16;
|
|
2650
|
-
d += c >>> 16;
|
|
2651
|
-
|
|
2652
|
-
wh[j] = (c & 0xffff) | (d << 16);
|
|
2653
|
-
wl[j] = (a & 0xffff) | (b << 16);
|
|
2654
|
-
}
|
|
2655
|
-
}
|
|
2656
|
-
}
|
|
2657
|
-
|
|
2658
|
-
// add
|
|
2659
|
-
h = ah0;
|
|
2660
|
-
l = al0;
|
|
2661
|
-
|
|
2662
|
-
a = l & 0xffff; b = l >>> 16;
|
|
2663
|
-
c = h & 0xffff; d = h >>> 16;
|
|
2664
|
-
|
|
2665
|
-
h = hh[0];
|
|
2666
|
-
l = hl[0];
|
|
2667
|
-
|
|
2668
|
-
a += l & 0xffff; b += l >>> 16;
|
|
2669
|
-
c += h & 0xffff; d += h >>> 16;
|
|
2670
|
-
|
|
2671
|
-
b += a >>> 16;
|
|
2672
|
-
c += b >>> 16;
|
|
2673
|
-
d += c >>> 16;
|
|
2674
|
-
|
|
2675
|
-
hh[0] = ah0 = (c & 0xffff) | (d << 16);
|
|
2676
|
-
hl[0] = al0 = (a & 0xffff) | (b << 16);
|
|
2677
|
-
|
|
2678
|
-
h = ah1;
|
|
2679
|
-
l = al1;
|
|
2680
|
-
|
|
2681
|
-
a = l & 0xffff; b = l >>> 16;
|
|
2682
|
-
c = h & 0xffff; d = h >>> 16;
|
|
2683
|
-
|
|
2684
|
-
h = hh[1];
|
|
2685
|
-
l = hl[1];
|
|
2686
|
-
|
|
2687
|
-
a += l & 0xffff; b += l >>> 16;
|
|
2688
|
-
c += h & 0xffff; d += h >>> 16;
|
|
2689
|
-
|
|
2690
|
-
b += a >>> 16;
|
|
2691
|
-
c += b >>> 16;
|
|
2692
|
-
d += c >>> 16;
|
|
2693
|
-
|
|
2694
|
-
hh[1] = ah1 = (c & 0xffff) | (d << 16);
|
|
2695
|
-
hl[1] = al1 = (a & 0xffff) | (b << 16);
|
|
2696
|
-
|
|
2697
|
-
h = ah2;
|
|
2698
|
-
l = al2;
|
|
2699
|
-
|
|
2700
|
-
a = l & 0xffff; b = l >>> 16;
|
|
2701
|
-
c = h & 0xffff; d = h >>> 16;
|
|
2702
|
-
|
|
2703
|
-
h = hh[2];
|
|
2704
|
-
l = hl[2];
|
|
2705
|
-
|
|
2706
|
-
a += l & 0xffff; b += l >>> 16;
|
|
2707
|
-
c += h & 0xffff; d += h >>> 16;
|
|
2708
|
-
|
|
2709
|
-
b += a >>> 16;
|
|
2710
|
-
c += b >>> 16;
|
|
2711
|
-
d += c >>> 16;
|
|
2712
|
-
|
|
2713
|
-
hh[2] = ah2 = (c & 0xffff) | (d << 16);
|
|
2714
|
-
hl[2] = al2 = (a & 0xffff) | (b << 16);
|
|
2715
|
-
|
|
2716
|
-
h = ah3;
|
|
2717
|
-
l = al3;
|
|
2718
|
-
|
|
2719
|
-
a = l & 0xffff; b = l >>> 16;
|
|
2720
|
-
c = h & 0xffff; d = h >>> 16;
|
|
2721
|
-
|
|
2722
|
-
h = hh[3];
|
|
2723
|
-
l = hl[3];
|
|
2724
|
-
|
|
2725
|
-
a += l & 0xffff; b += l >>> 16;
|
|
2726
|
-
c += h & 0xffff; d += h >>> 16;
|
|
2727
|
-
|
|
2728
|
-
b += a >>> 16;
|
|
2729
|
-
c += b >>> 16;
|
|
2730
|
-
d += c >>> 16;
|
|
2731
|
-
|
|
2732
|
-
hh[3] = ah3 = (c & 0xffff) | (d << 16);
|
|
2733
|
-
hl[3] = al3 = (a & 0xffff) | (b << 16);
|
|
2734
|
-
|
|
2735
|
-
h = ah4;
|
|
2736
|
-
l = al4;
|
|
2737
|
-
|
|
2738
|
-
a = l & 0xffff; b = l >>> 16;
|
|
2739
|
-
c = h & 0xffff; d = h >>> 16;
|
|
2740
|
-
|
|
2741
|
-
h = hh[4];
|
|
2742
|
-
l = hl[4];
|
|
2743
|
-
|
|
2744
|
-
a += l & 0xffff; b += l >>> 16;
|
|
2745
|
-
c += h & 0xffff; d += h >>> 16;
|
|
2746
|
-
|
|
2747
|
-
b += a >>> 16;
|
|
2748
|
-
c += b >>> 16;
|
|
2749
|
-
d += c >>> 16;
|
|
2750
|
-
|
|
2751
|
-
hh[4] = ah4 = (c & 0xffff) | (d << 16);
|
|
2752
|
-
hl[4] = al4 = (a & 0xffff) | (b << 16);
|
|
2753
|
-
|
|
2754
|
-
h = ah5;
|
|
2755
|
-
l = al5;
|
|
2756
|
-
|
|
2757
|
-
a = l & 0xffff; b = l >>> 16;
|
|
2758
|
-
c = h & 0xffff; d = h >>> 16;
|
|
2759
|
-
|
|
2760
|
-
h = hh[5];
|
|
2761
|
-
l = hl[5];
|
|
2762
|
-
|
|
2763
|
-
a += l & 0xffff; b += l >>> 16;
|
|
2764
|
-
c += h & 0xffff; d += h >>> 16;
|
|
2765
|
-
|
|
2766
|
-
b += a >>> 16;
|
|
2767
|
-
c += b >>> 16;
|
|
2768
|
-
d += c >>> 16;
|
|
2769
|
-
|
|
2770
|
-
hh[5] = ah5 = (c & 0xffff) | (d << 16);
|
|
2771
|
-
hl[5] = al5 = (a & 0xffff) | (b << 16);
|
|
2772
|
-
|
|
2773
|
-
h = ah6;
|
|
2774
|
-
l = al6;
|
|
2775
|
-
|
|
2776
|
-
a = l & 0xffff; b = l >>> 16;
|
|
2777
|
-
c = h & 0xffff; d = h >>> 16;
|
|
2778
|
-
|
|
2779
|
-
h = hh[6];
|
|
2780
|
-
l = hl[6];
|
|
2781
|
-
|
|
2782
|
-
a += l & 0xffff; b += l >>> 16;
|
|
2783
|
-
c += h & 0xffff; d += h >>> 16;
|
|
2784
|
-
|
|
2785
|
-
b += a >>> 16;
|
|
2786
|
-
c += b >>> 16;
|
|
2787
|
-
d += c >>> 16;
|
|
2788
|
-
|
|
2789
|
-
hh[6] = ah6 = (c & 0xffff) | (d << 16);
|
|
2790
|
-
hl[6] = al6 = (a & 0xffff) | (b << 16);
|
|
2791
|
-
|
|
2792
|
-
h = ah7;
|
|
2793
|
-
l = al7;
|
|
2794
|
-
|
|
2795
|
-
a = l & 0xffff; b = l >>> 16;
|
|
2796
|
-
c = h & 0xffff; d = h >>> 16;
|
|
2797
|
-
|
|
2798
|
-
h = hh[7];
|
|
2799
|
-
l = hl[7];
|
|
2800
|
-
|
|
2801
|
-
a += l & 0xffff; b += l >>> 16;
|
|
2802
|
-
c += h & 0xffff; d += h >>> 16;
|
|
2803
|
-
|
|
2804
|
-
b += a >>> 16;
|
|
2805
|
-
c += b >>> 16;
|
|
2806
|
-
d += c >>> 16;
|
|
2807
|
-
|
|
2808
|
-
hh[7] = ah7 = (c & 0xffff) | (d << 16);
|
|
2809
|
-
hl[7] = al7 = (a & 0xffff) | (b << 16);
|
|
2810
|
-
|
|
2811
|
-
pos += 128;
|
|
2812
|
-
n -= 128;
|
|
2813
|
-
}
|
|
2814
|
-
|
|
2815
|
-
return n;
|
|
2816
|
-
}
|
|
2817
|
-
|
|
2818
|
-
function crypto_hash(out, m, n) {
|
|
2819
|
-
var hh = new Int32Array(8),
|
|
2820
|
-
hl = new Int32Array(8),
|
|
2821
|
-
x = new Uint8Array(256),
|
|
2822
|
-
i, b = n;
|
|
2823
|
-
|
|
2824
|
-
hh[0] = 0x6a09e667;
|
|
2825
|
-
hh[1] = 0xbb67ae85;
|
|
2826
|
-
hh[2] = 0x3c6ef372;
|
|
2827
|
-
hh[3] = 0xa54ff53a;
|
|
2828
|
-
hh[4] = 0x510e527f;
|
|
2829
|
-
hh[5] = 0x9b05688c;
|
|
2830
|
-
hh[6] = 0x1f83d9ab;
|
|
2831
|
-
hh[7] = 0x5be0cd19;
|
|
2832
|
-
|
|
2833
|
-
hl[0] = 0xf3bcc908;
|
|
2834
|
-
hl[1] = 0x84caa73b;
|
|
2835
|
-
hl[2] = 0xfe94f82b;
|
|
2836
|
-
hl[3] = 0x5f1d36f1;
|
|
2837
|
-
hl[4] = 0xade682d1;
|
|
2838
|
-
hl[5] = 0x2b3e6c1f;
|
|
2839
|
-
hl[6] = 0xfb41bd6b;
|
|
2840
|
-
hl[7] = 0x137e2179;
|
|
2841
|
-
|
|
2842
|
-
crypto_hashblocks_hl(hh, hl, m, n);
|
|
2843
|
-
n %= 128;
|
|
2844
|
-
|
|
2845
|
-
for (i = 0; i < n; i++) x[i] = m[b-n+i];
|
|
2846
|
-
x[n] = 128;
|
|
2847
|
-
|
|
2848
|
-
n = 256-128*(n<112?1:0);
|
|
2849
|
-
x[n-9] = 0;
|
|
2850
|
-
ts64(x, n-8, (b / 0x20000000) | 0, b << 3);
|
|
2851
|
-
crypto_hashblocks_hl(hh, hl, x, n);
|
|
2852
|
-
|
|
2853
|
-
for (i = 0; i < 8; i++) ts64(out, 8*i, hh[i], hl[i]);
|
|
2854
|
-
|
|
2855
|
-
return 0;
|
|
2856
|
-
}
|
|
2857
|
-
|
|
2858
|
-
function add(p, q) {
|
|
2859
|
-
var a = gf(), b = gf(), c = gf(),
|
|
2860
|
-
d = gf(), e = gf(), f = gf(),
|
|
2861
|
-
g = gf(), h = gf(), t = gf();
|
|
2862
|
-
|
|
2863
|
-
Z(a, p[1], p[0]);
|
|
2864
|
-
Z(t, q[1], q[0]);
|
|
2865
|
-
M(a, a, t);
|
|
2866
|
-
A(b, p[0], p[1]);
|
|
2867
|
-
A(t, q[0], q[1]);
|
|
2868
|
-
M(b, b, t);
|
|
2869
|
-
M(c, p[3], q[3]);
|
|
2870
|
-
M(c, c, D2);
|
|
2871
|
-
M(d, p[2], q[2]);
|
|
2872
|
-
A(d, d, d);
|
|
2873
|
-
Z(e, b, a);
|
|
2874
|
-
Z(f, d, c);
|
|
2875
|
-
A(g, d, c);
|
|
2876
|
-
A(h, b, a);
|
|
2877
|
-
|
|
2878
|
-
M(p[0], e, f);
|
|
2879
|
-
M(p[1], h, g);
|
|
2880
|
-
M(p[2], g, f);
|
|
2881
|
-
M(p[3], e, h);
|
|
2882
|
-
}
|
|
2883
|
-
|
|
2884
|
-
function cswap(p, q, b) {
|
|
2885
|
-
var i;
|
|
2886
|
-
for (i = 0; i < 4; i++) {
|
|
2887
|
-
sel25519(p[i], q[i], b);
|
|
2888
|
-
}
|
|
2889
|
-
}
|
|
2890
|
-
|
|
2891
|
-
function pack(r, p) {
|
|
2892
|
-
var tx = gf(), ty = gf(), zi = gf();
|
|
2893
|
-
inv25519(zi, p[2]);
|
|
2894
|
-
M(tx, p[0], zi);
|
|
2895
|
-
M(ty, p[1], zi);
|
|
2896
|
-
pack25519(r, ty);
|
|
2897
|
-
r[31] ^= par25519(tx) << 7;
|
|
2898
|
-
}
|
|
2899
|
-
|
|
2900
|
-
function scalarmult(p, q, s) {
|
|
2901
|
-
var b, i;
|
|
2902
|
-
set25519(p[0], gf0);
|
|
2903
|
-
set25519(p[1], gf1);
|
|
2904
|
-
set25519(p[2], gf1);
|
|
2905
|
-
set25519(p[3], gf0);
|
|
2906
|
-
for (i = 255; i >= 0; --i) {
|
|
2907
|
-
b = (s[(i/8)|0] >> (i&7)) & 1;
|
|
2908
|
-
cswap(p, q, b);
|
|
2909
|
-
add(q, p);
|
|
2910
|
-
add(p, p);
|
|
2911
|
-
cswap(p, q, b);
|
|
2912
|
-
}
|
|
2913
|
-
}
|
|
2914
|
-
|
|
2915
|
-
function scalarbase(p, s) {
|
|
2916
|
-
var q = [gf(), gf(), gf(), gf()];
|
|
2917
|
-
set25519(q[0], X);
|
|
2918
|
-
set25519(q[1], Y);
|
|
2919
|
-
set25519(q[2], gf1);
|
|
2920
|
-
M(q[3], X, Y);
|
|
2921
|
-
scalarmult(p, q, s);
|
|
2922
|
-
}
|
|
2923
|
-
|
|
2924
|
-
function crypto_sign_keypair(pk, sk, seeded) {
|
|
2925
|
-
var d = new Uint8Array(64);
|
|
2926
|
-
var p = [gf(), gf(), gf(), gf()];
|
|
2927
|
-
var i;
|
|
2928
|
-
|
|
2929
|
-
if (!seeded) randombytes(sk, 32);
|
|
2930
|
-
crypto_hash(d, sk, 32);
|
|
2931
|
-
d[0] &= 248;
|
|
2932
|
-
d[31] &= 127;
|
|
2933
|
-
d[31] |= 64;
|
|
2934
|
-
|
|
2935
|
-
scalarbase(p, d);
|
|
2936
|
-
pack(pk, p);
|
|
2937
|
-
|
|
2938
|
-
for (i = 0; i < 32; i++) sk[i+32] = pk[i];
|
|
2939
|
-
return 0;
|
|
2940
|
-
}
|
|
2941
|
-
|
|
2942
|
-
var L = new Float64Array([0xed, 0xd3, 0xf5, 0x5c, 0x1a, 0x63, 0x12, 0x58, 0xd6, 0x9c, 0xf7, 0xa2, 0xde, 0xf9, 0xde, 0x14, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0x10]);
|
|
2943
|
-
|
|
2944
|
-
function modL(r, x) {
|
|
2945
|
-
var carry, i, j, k;
|
|
2946
|
-
for (i = 63; i >= 32; --i) {
|
|
2947
|
-
carry = 0;
|
|
2948
|
-
for (j = i - 32, k = i - 12; j < k; ++j) {
|
|
2949
|
-
x[j] += carry - 16 * x[i] * L[j - (i - 32)];
|
|
2950
|
-
carry = Math.floor((x[j] + 128) / 256);
|
|
2951
|
-
x[j] -= carry * 256;
|
|
2952
|
-
}
|
|
2953
|
-
x[j] += carry;
|
|
2954
|
-
x[i] = 0;
|
|
2955
|
-
}
|
|
2956
|
-
carry = 0;
|
|
2957
|
-
for (j = 0; j < 32; j++) {
|
|
2958
|
-
x[j] += carry - (x[31] >> 4) * L[j];
|
|
2959
|
-
carry = x[j] >> 8;
|
|
2960
|
-
x[j] &= 255;
|
|
2961
|
-
}
|
|
2962
|
-
for (j = 0; j < 32; j++) x[j] -= carry * L[j];
|
|
2963
|
-
for (i = 0; i < 32; i++) {
|
|
2964
|
-
x[i+1] += x[i] >> 8;
|
|
2965
|
-
r[i] = x[i] & 255;
|
|
2966
|
-
}
|
|
2967
|
-
}
|
|
2968
|
-
|
|
2969
|
-
function reduce(r) {
|
|
2970
|
-
var x = new Float64Array(64), i;
|
|
2971
|
-
for (i = 0; i < 64; i++) x[i] = r[i];
|
|
2972
|
-
for (i = 0; i < 64; i++) r[i] = 0;
|
|
2973
|
-
modL(r, x);
|
|
2974
|
-
}
|
|
2975
|
-
|
|
2976
|
-
// Note: difference from C - smlen returned, not passed as argument.
|
|
2977
|
-
function crypto_sign(sm, m, n, sk) {
|
|
2978
|
-
var d = new Uint8Array(64), h = new Uint8Array(64), r = new Uint8Array(64);
|
|
2979
|
-
var i, j, x = new Float64Array(64);
|
|
2980
|
-
var p = [gf(), gf(), gf(), gf()];
|
|
2981
|
-
|
|
2982
|
-
crypto_hash(d, sk, 32);
|
|
2983
|
-
d[0] &= 248;
|
|
2984
|
-
d[31] &= 127;
|
|
2985
|
-
d[31] |= 64;
|
|
2986
|
-
|
|
2987
|
-
var smlen = n + 64;
|
|
2988
|
-
for (i = 0; i < n; i++) sm[64 + i] = m[i];
|
|
2989
|
-
for (i = 0; i < 32; i++) sm[32 + i] = d[32 + i];
|
|
2990
|
-
|
|
2991
|
-
crypto_hash(r, sm.subarray(32), n+32);
|
|
2992
|
-
reduce(r);
|
|
2993
|
-
scalarbase(p, r);
|
|
2994
|
-
pack(sm, p);
|
|
2995
|
-
|
|
2996
|
-
for (i = 32; i < 64; i++) sm[i] = sk[i];
|
|
2997
|
-
crypto_hash(h, sm, n + 64);
|
|
2998
|
-
reduce(h);
|
|
2999
|
-
|
|
3000
|
-
for (i = 0; i < 64; i++) x[i] = 0;
|
|
3001
|
-
for (i = 0; i < 32; i++) x[i] = r[i];
|
|
3002
|
-
for (i = 0; i < 32; i++) {
|
|
3003
|
-
for (j = 0; j < 32; j++) {
|
|
3004
|
-
x[i+j] += h[i] * d[j];
|
|
3005
|
-
}
|
|
3006
|
-
}
|
|
3007
|
-
|
|
3008
|
-
modL(sm.subarray(32), x);
|
|
3009
|
-
return smlen;
|
|
3010
|
-
}
|
|
3011
|
-
|
|
3012
|
-
function unpackneg(r, p) {
|
|
3013
|
-
var t = gf(), chk = gf(), num = gf(),
|
|
3014
|
-
den = gf(), den2 = gf(), den4 = gf(),
|
|
3015
|
-
den6 = gf();
|
|
3016
|
-
|
|
3017
|
-
set25519(r[2], gf1);
|
|
3018
|
-
unpack25519(r[1], p);
|
|
3019
|
-
S(num, r[1]);
|
|
3020
|
-
M(den, num, D);
|
|
3021
|
-
Z(num, num, r[2]);
|
|
3022
|
-
A(den, r[2], den);
|
|
3023
|
-
|
|
3024
|
-
S(den2, den);
|
|
3025
|
-
S(den4, den2);
|
|
3026
|
-
M(den6, den4, den2);
|
|
3027
|
-
M(t, den6, num);
|
|
3028
|
-
M(t, t, den);
|
|
3029
|
-
|
|
3030
|
-
pow2523(t, t);
|
|
3031
|
-
M(t, t, num);
|
|
3032
|
-
M(t, t, den);
|
|
3033
|
-
M(t, t, den);
|
|
3034
|
-
M(r[0], t, den);
|
|
3035
|
-
|
|
3036
|
-
S(chk, r[0]);
|
|
3037
|
-
M(chk, chk, den);
|
|
3038
|
-
if (neq25519(chk, num)) M(r[0], r[0], I);
|
|
3039
|
-
|
|
3040
|
-
S(chk, r[0]);
|
|
3041
|
-
M(chk, chk, den);
|
|
3042
|
-
if (neq25519(chk, num)) return -1;
|
|
3043
|
-
|
|
3044
|
-
if (par25519(r[0]) === (p[31]>>7)) Z(r[0], gf0, r[0]);
|
|
3045
|
-
|
|
3046
|
-
M(r[3], r[0], r[1]);
|
|
3047
|
-
return 0;
|
|
3048
|
-
}
|
|
3049
|
-
|
|
3050
|
-
function crypto_sign_open(m, sm, n, pk) {
|
|
3051
|
-
var i;
|
|
3052
|
-
var t = new Uint8Array(32), h = new Uint8Array(64);
|
|
3053
|
-
var p = [gf(), gf(), gf(), gf()],
|
|
3054
|
-
q = [gf(), gf(), gf(), gf()];
|
|
3055
|
-
|
|
3056
|
-
if (n < 64) return -1;
|
|
3057
|
-
|
|
3058
|
-
if (unpackneg(q, pk)) return -1;
|
|
3059
|
-
|
|
3060
|
-
for (i = 0; i < n; i++) m[i] = sm[i];
|
|
3061
|
-
for (i = 0; i < 32; i++) m[i+32] = pk[i];
|
|
3062
|
-
crypto_hash(h, m, n);
|
|
3063
|
-
reduce(h);
|
|
3064
|
-
scalarmult(p, q, h);
|
|
3065
|
-
|
|
3066
|
-
scalarbase(q, sm.subarray(32));
|
|
3067
|
-
add(p, q);
|
|
3068
|
-
pack(t, p);
|
|
3069
|
-
|
|
3070
|
-
n -= 64;
|
|
3071
|
-
if (crypto_verify_32(sm, 0, t, 0)) {
|
|
3072
|
-
for (i = 0; i < n; i++) m[i] = 0;
|
|
3073
|
-
return -1;
|
|
3074
|
-
}
|
|
3075
|
-
|
|
3076
|
-
for (i = 0; i < n; i++) m[i] = sm[i + 64];
|
|
3077
|
-
return n;
|
|
3078
|
-
}
|
|
3079
|
-
|
|
3080
|
-
var crypto_secretbox_KEYBYTES = 32,
|
|
3081
|
-
crypto_secretbox_NONCEBYTES = 24,
|
|
3082
|
-
crypto_secretbox_ZEROBYTES = 32,
|
|
3083
|
-
crypto_secretbox_BOXZEROBYTES = 16,
|
|
3084
|
-
crypto_scalarmult_BYTES = 32,
|
|
3085
|
-
crypto_scalarmult_SCALARBYTES = 32,
|
|
3086
|
-
crypto_box_PUBLICKEYBYTES = 32,
|
|
3087
|
-
crypto_box_SECRETKEYBYTES = 32,
|
|
3088
|
-
crypto_box_BEFORENMBYTES = 32,
|
|
3089
|
-
crypto_box_NONCEBYTES = crypto_secretbox_NONCEBYTES,
|
|
3090
|
-
crypto_box_ZEROBYTES = crypto_secretbox_ZEROBYTES,
|
|
3091
|
-
crypto_box_BOXZEROBYTES = crypto_secretbox_BOXZEROBYTES,
|
|
3092
|
-
crypto_sign_BYTES = 64,
|
|
3093
|
-
crypto_sign_PUBLICKEYBYTES = 32,
|
|
3094
|
-
crypto_sign_SECRETKEYBYTES = 64,
|
|
3095
|
-
crypto_sign_SEEDBYTES = 32,
|
|
3096
|
-
crypto_hash_BYTES = 64;
|
|
3097
|
-
|
|
3098
|
-
nacl.lowlevel = {
|
|
3099
|
-
crypto_core_hsalsa20: crypto_core_hsalsa20,
|
|
3100
|
-
crypto_stream_xor: crypto_stream_xor,
|
|
3101
|
-
crypto_stream: crypto_stream,
|
|
3102
|
-
crypto_stream_salsa20_xor: crypto_stream_salsa20_xor,
|
|
3103
|
-
crypto_stream_salsa20: crypto_stream_salsa20,
|
|
3104
|
-
crypto_onetimeauth: crypto_onetimeauth,
|
|
3105
|
-
crypto_onetimeauth_verify: crypto_onetimeauth_verify,
|
|
3106
|
-
crypto_verify_16: crypto_verify_16,
|
|
3107
|
-
crypto_verify_32: crypto_verify_32,
|
|
3108
|
-
crypto_secretbox: crypto_secretbox,
|
|
3109
|
-
crypto_secretbox_open: crypto_secretbox_open,
|
|
3110
|
-
crypto_scalarmult: crypto_scalarmult,
|
|
3111
|
-
crypto_scalarmult_base: crypto_scalarmult_base,
|
|
3112
|
-
crypto_box_beforenm: crypto_box_beforenm,
|
|
3113
|
-
crypto_box_afternm: crypto_box_afternm,
|
|
3114
|
-
crypto_box: crypto_box,
|
|
3115
|
-
crypto_box_open: crypto_box_open,
|
|
3116
|
-
crypto_box_keypair: crypto_box_keypair,
|
|
3117
|
-
crypto_hash: crypto_hash,
|
|
3118
|
-
crypto_sign: crypto_sign,
|
|
3119
|
-
crypto_sign_keypair: crypto_sign_keypair,
|
|
3120
|
-
crypto_sign_open: crypto_sign_open,
|
|
3121
|
-
|
|
3122
|
-
crypto_secretbox_KEYBYTES: crypto_secretbox_KEYBYTES,
|
|
3123
|
-
crypto_secretbox_NONCEBYTES: crypto_secretbox_NONCEBYTES,
|
|
3124
|
-
crypto_secretbox_ZEROBYTES: crypto_secretbox_ZEROBYTES,
|
|
3125
|
-
crypto_secretbox_BOXZEROBYTES: crypto_secretbox_BOXZEROBYTES,
|
|
3126
|
-
crypto_scalarmult_BYTES: crypto_scalarmult_BYTES,
|
|
3127
|
-
crypto_scalarmult_SCALARBYTES: crypto_scalarmult_SCALARBYTES,
|
|
3128
|
-
crypto_box_PUBLICKEYBYTES: crypto_box_PUBLICKEYBYTES,
|
|
3129
|
-
crypto_box_SECRETKEYBYTES: crypto_box_SECRETKEYBYTES,
|
|
3130
|
-
crypto_box_BEFORENMBYTES: crypto_box_BEFORENMBYTES,
|
|
3131
|
-
crypto_box_NONCEBYTES: crypto_box_NONCEBYTES,
|
|
3132
|
-
crypto_box_ZEROBYTES: crypto_box_ZEROBYTES,
|
|
3133
|
-
crypto_box_BOXZEROBYTES: crypto_box_BOXZEROBYTES,
|
|
3134
|
-
crypto_sign_BYTES: crypto_sign_BYTES,
|
|
3135
|
-
crypto_sign_PUBLICKEYBYTES: crypto_sign_PUBLICKEYBYTES,
|
|
3136
|
-
crypto_sign_SECRETKEYBYTES: crypto_sign_SECRETKEYBYTES,
|
|
3137
|
-
crypto_sign_SEEDBYTES: crypto_sign_SEEDBYTES,
|
|
3138
|
-
crypto_hash_BYTES: crypto_hash_BYTES,
|
|
3139
|
-
|
|
3140
|
-
gf: gf,
|
|
3141
|
-
D: D,
|
|
3142
|
-
L: L,
|
|
3143
|
-
pack25519: pack25519,
|
|
3144
|
-
unpack25519: unpack25519,
|
|
3145
|
-
M: M,
|
|
3146
|
-
A: A,
|
|
3147
|
-
S: S,
|
|
3148
|
-
Z: Z,
|
|
3149
|
-
pow2523: pow2523,
|
|
3150
|
-
add: add,
|
|
3151
|
-
set25519: set25519,
|
|
3152
|
-
modL: modL,
|
|
3153
|
-
scalarmult: scalarmult,
|
|
3154
|
-
scalarbase: scalarbase,
|
|
3155
|
-
};
|
|
3156
|
-
|
|
3157
|
-
/* High-level API */
|
|
3158
|
-
|
|
3159
|
-
function checkLengths(k, n) {
|
|
3160
|
-
if (k.length !== crypto_secretbox_KEYBYTES) throw new Error('bad key size');
|
|
3161
|
-
if (n.length !== crypto_secretbox_NONCEBYTES) throw new Error('bad nonce size');
|
|
3162
|
-
}
|
|
3163
|
-
|
|
3164
|
-
function checkBoxLengths(pk, sk) {
|
|
3165
|
-
if (pk.length !== crypto_box_PUBLICKEYBYTES) throw new Error('bad public key size');
|
|
3166
|
-
if (sk.length !== crypto_box_SECRETKEYBYTES) throw new Error('bad secret key size');
|
|
3167
|
-
}
|
|
3168
|
-
|
|
3169
|
-
function checkArrayTypes() {
|
|
3170
|
-
for (var i = 0; i < arguments.length; i++) {
|
|
3171
|
-
if (!(arguments[i] instanceof Uint8Array))
|
|
3172
|
-
throw new TypeError('unexpected type, use Uint8Array');
|
|
3173
|
-
}
|
|
3174
|
-
}
|
|
3175
|
-
|
|
3176
|
-
function cleanup(arr) {
|
|
3177
|
-
for (var i = 0; i < arr.length; i++) arr[i] = 0;
|
|
3178
|
-
}
|
|
3179
|
-
|
|
3180
|
-
nacl.randomBytes = function(n) {
|
|
3181
|
-
var b = new Uint8Array(n);
|
|
3182
|
-
randombytes(b, n);
|
|
3183
|
-
return b;
|
|
3184
|
-
};
|
|
3185
|
-
|
|
3186
|
-
nacl.secretbox = function(msg, nonce, key) {
|
|
3187
|
-
checkArrayTypes(msg, nonce, key);
|
|
3188
|
-
checkLengths(key, nonce);
|
|
3189
|
-
var m = new Uint8Array(crypto_secretbox_ZEROBYTES + msg.length);
|
|
3190
|
-
var c = new Uint8Array(m.length);
|
|
3191
|
-
for (var i = 0; i < msg.length; i++) m[i+crypto_secretbox_ZEROBYTES] = msg[i];
|
|
3192
|
-
crypto_secretbox(c, m, m.length, nonce, key);
|
|
3193
|
-
return c.subarray(crypto_secretbox_BOXZEROBYTES);
|
|
3194
|
-
};
|
|
3195
|
-
|
|
3196
|
-
nacl.secretbox.open = function(box, nonce, key) {
|
|
3197
|
-
checkArrayTypes(box, nonce, key);
|
|
3198
|
-
checkLengths(key, nonce);
|
|
3199
|
-
var c = new Uint8Array(crypto_secretbox_BOXZEROBYTES + box.length);
|
|
3200
|
-
var m = new Uint8Array(c.length);
|
|
3201
|
-
for (var i = 0; i < box.length; i++) c[i+crypto_secretbox_BOXZEROBYTES] = box[i];
|
|
3202
|
-
if (c.length < 32) return null;
|
|
3203
|
-
if (crypto_secretbox_open(m, c, c.length, nonce, key) !== 0) return null;
|
|
3204
|
-
return m.subarray(crypto_secretbox_ZEROBYTES);
|
|
3205
|
-
};
|
|
3206
|
-
|
|
3207
|
-
nacl.secretbox.keyLength = crypto_secretbox_KEYBYTES;
|
|
3208
|
-
nacl.secretbox.nonceLength = crypto_secretbox_NONCEBYTES;
|
|
3209
|
-
nacl.secretbox.overheadLength = crypto_secretbox_BOXZEROBYTES;
|
|
3210
|
-
|
|
3211
|
-
nacl.scalarMult = function(n, p) {
|
|
3212
|
-
checkArrayTypes(n, p);
|
|
3213
|
-
if (n.length !== crypto_scalarmult_SCALARBYTES) throw new Error('bad n size');
|
|
3214
|
-
if (p.length !== crypto_scalarmult_BYTES) throw new Error('bad p size');
|
|
3215
|
-
var q = new Uint8Array(crypto_scalarmult_BYTES);
|
|
3216
|
-
crypto_scalarmult(q, n, p);
|
|
3217
|
-
return q;
|
|
3218
|
-
};
|
|
3219
|
-
|
|
3220
|
-
nacl.scalarMult.base = function(n) {
|
|
3221
|
-
checkArrayTypes(n);
|
|
3222
|
-
if (n.length !== crypto_scalarmult_SCALARBYTES) throw new Error('bad n size');
|
|
3223
|
-
var q = new Uint8Array(crypto_scalarmult_BYTES);
|
|
3224
|
-
crypto_scalarmult_base(q, n);
|
|
3225
|
-
return q;
|
|
3226
|
-
};
|
|
3227
|
-
|
|
3228
|
-
nacl.scalarMult.scalarLength = crypto_scalarmult_SCALARBYTES;
|
|
3229
|
-
nacl.scalarMult.groupElementLength = crypto_scalarmult_BYTES;
|
|
3230
|
-
|
|
3231
|
-
nacl.box = function(msg, nonce, publicKey, secretKey) {
|
|
3232
|
-
var k = nacl.box.before(publicKey, secretKey);
|
|
3233
|
-
return nacl.secretbox(msg, nonce, k);
|
|
3234
|
-
};
|
|
3235
|
-
|
|
3236
|
-
nacl.box.before = function(publicKey, secretKey) {
|
|
3237
|
-
checkArrayTypes(publicKey, secretKey);
|
|
3238
|
-
checkBoxLengths(publicKey, secretKey);
|
|
3239
|
-
var k = new Uint8Array(crypto_box_BEFORENMBYTES);
|
|
3240
|
-
crypto_box_beforenm(k, publicKey, secretKey);
|
|
3241
|
-
return k;
|
|
3242
|
-
};
|
|
3243
|
-
|
|
3244
|
-
nacl.box.after = nacl.secretbox;
|
|
3245
|
-
|
|
3246
|
-
nacl.box.open = function(msg, nonce, publicKey, secretKey) {
|
|
3247
|
-
var k = nacl.box.before(publicKey, secretKey);
|
|
3248
|
-
return nacl.secretbox.open(msg, nonce, k);
|
|
3249
|
-
};
|
|
3250
|
-
|
|
3251
|
-
nacl.box.open.after = nacl.secretbox.open;
|
|
3252
|
-
|
|
3253
|
-
nacl.box.keyPair = function() {
|
|
3254
|
-
var pk = new Uint8Array(crypto_box_PUBLICKEYBYTES);
|
|
3255
|
-
var sk = new Uint8Array(crypto_box_SECRETKEYBYTES);
|
|
3256
|
-
crypto_box_keypair(pk, sk);
|
|
3257
|
-
return {publicKey: pk, secretKey: sk};
|
|
3258
|
-
};
|
|
3259
|
-
|
|
3260
|
-
nacl.box.keyPair.fromSecretKey = function(secretKey) {
|
|
3261
|
-
checkArrayTypes(secretKey);
|
|
3262
|
-
if (secretKey.length !== crypto_box_SECRETKEYBYTES)
|
|
3263
|
-
throw new Error('bad secret key size');
|
|
3264
|
-
var pk = new Uint8Array(crypto_box_PUBLICKEYBYTES);
|
|
3265
|
-
crypto_scalarmult_base(pk, secretKey);
|
|
3266
|
-
return {publicKey: pk, secretKey: new Uint8Array(secretKey)};
|
|
3267
|
-
};
|
|
3268
|
-
|
|
3269
|
-
nacl.box.publicKeyLength = crypto_box_PUBLICKEYBYTES;
|
|
3270
|
-
nacl.box.secretKeyLength = crypto_box_SECRETKEYBYTES;
|
|
3271
|
-
nacl.box.sharedKeyLength = crypto_box_BEFORENMBYTES;
|
|
3272
|
-
nacl.box.nonceLength = crypto_box_NONCEBYTES;
|
|
3273
|
-
nacl.box.overheadLength = nacl.secretbox.overheadLength;
|
|
3274
|
-
|
|
3275
|
-
nacl.sign = function(msg, secretKey) {
|
|
3276
|
-
checkArrayTypes(msg, secretKey);
|
|
3277
|
-
if (secretKey.length !== crypto_sign_SECRETKEYBYTES)
|
|
3278
|
-
throw new Error('bad secret key size');
|
|
3279
|
-
var signedMsg = new Uint8Array(crypto_sign_BYTES+msg.length);
|
|
3280
|
-
crypto_sign(signedMsg, msg, msg.length, secretKey);
|
|
3281
|
-
return signedMsg;
|
|
3282
|
-
};
|
|
3283
|
-
|
|
3284
|
-
nacl.sign.open = function(signedMsg, publicKey) {
|
|
3285
|
-
checkArrayTypes(signedMsg, publicKey);
|
|
3286
|
-
if (publicKey.length !== crypto_sign_PUBLICKEYBYTES)
|
|
3287
|
-
throw new Error('bad public key size');
|
|
3288
|
-
var tmp = new Uint8Array(signedMsg.length);
|
|
3289
|
-
var mlen = crypto_sign_open(tmp, signedMsg, signedMsg.length, publicKey);
|
|
3290
|
-
if (mlen < 0) return null;
|
|
3291
|
-
var m = new Uint8Array(mlen);
|
|
3292
|
-
for (var i = 0; i < m.length; i++) m[i] = tmp[i];
|
|
3293
|
-
return m;
|
|
3294
|
-
};
|
|
3295
|
-
|
|
3296
|
-
nacl.sign.detached = function(msg, secretKey) {
|
|
3297
|
-
var signedMsg = nacl.sign(msg, secretKey);
|
|
3298
|
-
var sig = new Uint8Array(crypto_sign_BYTES);
|
|
3299
|
-
for (var i = 0; i < sig.length; i++) sig[i] = signedMsg[i];
|
|
3300
|
-
return sig;
|
|
3301
|
-
};
|
|
3302
|
-
|
|
3303
|
-
nacl.sign.detached.verify = function(msg, sig, publicKey) {
|
|
3304
|
-
checkArrayTypes(msg, sig, publicKey);
|
|
3305
|
-
if (sig.length !== crypto_sign_BYTES)
|
|
3306
|
-
throw new Error('bad signature size');
|
|
3307
|
-
if (publicKey.length !== crypto_sign_PUBLICKEYBYTES)
|
|
3308
|
-
throw new Error('bad public key size');
|
|
3309
|
-
var sm = new Uint8Array(crypto_sign_BYTES + msg.length);
|
|
3310
|
-
var m = new Uint8Array(crypto_sign_BYTES + msg.length);
|
|
3311
|
-
var i;
|
|
3312
|
-
for (i = 0; i < crypto_sign_BYTES; i++) sm[i] = sig[i];
|
|
3313
|
-
for (i = 0; i < msg.length; i++) sm[i+crypto_sign_BYTES] = msg[i];
|
|
3314
|
-
return (crypto_sign_open(m, sm, sm.length, publicKey) >= 0);
|
|
3315
|
-
};
|
|
3316
|
-
|
|
3317
|
-
nacl.sign.keyPair = function() {
|
|
3318
|
-
var pk = new Uint8Array(crypto_sign_PUBLICKEYBYTES);
|
|
3319
|
-
var sk = new Uint8Array(crypto_sign_SECRETKEYBYTES);
|
|
3320
|
-
crypto_sign_keypair(pk, sk);
|
|
3321
|
-
return {publicKey: pk, secretKey: sk};
|
|
3322
|
-
};
|
|
3323
|
-
|
|
3324
|
-
nacl.sign.keyPair.fromSecretKey = function(secretKey) {
|
|
3325
|
-
checkArrayTypes(secretKey);
|
|
3326
|
-
if (secretKey.length !== crypto_sign_SECRETKEYBYTES)
|
|
3327
|
-
throw new Error('bad secret key size');
|
|
3328
|
-
var pk = new Uint8Array(crypto_sign_PUBLICKEYBYTES);
|
|
3329
|
-
for (var i = 0; i < pk.length; i++) pk[i] = secretKey[32+i];
|
|
3330
|
-
return {publicKey: pk, secretKey: new Uint8Array(secretKey)};
|
|
3331
|
-
};
|
|
3332
|
-
|
|
3333
|
-
nacl.sign.keyPair.fromSeed = function(seed) {
|
|
3334
|
-
checkArrayTypes(seed);
|
|
3335
|
-
if (seed.length !== crypto_sign_SEEDBYTES)
|
|
3336
|
-
throw new Error('bad seed size');
|
|
3337
|
-
var pk = new Uint8Array(crypto_sign_PUBLICKEYBYTES);
|
|
3338
|
-
var sk = new Uint8Array(crypto_sign_SECRETKEYBYTES);
|
|
3339
|
-
for (var i = 0; i < 32; i++) sk[i] = seed[i];
|
|
3340
|
-
crypto_sign_keypair(pk, sk, true);
|
|
3341
|
-
return {publicKey: pk, secretKey: sk};
|
|
3342
|
-
};
|
|
3343
|
-
|
|
3344
|
-
nacl.sign.publicKeyLength = crypto_sign_PUBLICKEYBYTES;
|
|
3345
|
-
nacl.sign.secretKeyLength = crypto_sign_SECRETKEYBYTES;
|
|
3346
|
-
nacl.sign.seedLength = crypto_sign_SEEDBYTES;
|
|
3347
|
-
nacl.sign.signatureLength = crypto_sign_BYTES;
|
|
3348
|
-
|
|
3349
|
-
nacl.hash = function(msg) {
|
|
3350
|
-
checkArrayTypes(msg);
|
|
3351
|
-
var h = new Uint8Array(crypto_hash_BYTES);
|
|
3352
|
-
crypto_hash(h, msg, msg.length);
|
|
3353
|
-
return h;
|
|
3354
|
-
};
|
|
3355
|
-
|
|
3356
|
-
nacl.hash.hashLength = crypto_hash_BYTES;
|
|
3357
|
-
|
|
3358
|
-
nacl.verify = function(x, y) {
|
|
3359
|
-
checkArrayTypes(x, y);
|
|
3360
|
-
// Zero length arguments are considered not equal.
|
|
3361
|
-
if (x.length === 0 || y.length === 0) return false;
|
|
3362
|
-
if (x.length !== y.length) return false;
|
|
3363
|
-
return (vn(x, 0, y, 0, x.length) === 0) ? true : false;
|
|
3364
|
-
};
|
|
3365
|
-
|
|
3366
|
-
nacl.setPRNG = function(fn) {
|
|
3367
|
-
randombytes = fn;
|
|
3368
|
-
};
|
|
3369
|
-
|
|
3370
|
-
(function() {
|
|
3371
|
-
// Initialize PRNG if environment provides CSPRNG.
|
|
3372
|
-
// If not, methods calling randombytes will throw.
|
|
3373
|
-
var crypto = typeof self !== 'undefined' ? (self.crypto || self.msCrypto) : null;
|
|
3374
|
-
if (crypto && crypto.getRandomValues) {
|
|
3375
|
-
// Browsers.
|
|
3376
|
-
var QUOTA = 65536;
|
|
3377
|
-
nacl.setPRNG(function(x, n) {
|
|
3378
|
-
var i, v = new Uint8Array(n);
|
|
3379
|
-
for (i = 0; i < n; i += QUOTA) {
|
|
3380
|
-
crypto.getRandomValues(v.subarray(i, i + Math.min(n - i, QUOTA)));
|
|
3381
|
-
}
|
|
3382
|
-
for (i = 0; i < n; i++) x[i] = v[i];
|
|
3383
|
-
cleanup(v);
|
|
3384
|
-
});
|
|
3385
|
-
} else if (typeof commonjsRequire !== 'undefined') {
|
|
3386
|
-
// Node.js.
|
|
3387
|
-
crypto = require$$0;
|
|
3388
|
-
if (crypto && crypto.randomBytes) {
|
|
3389
|
-
nacl.setPRNG(function(x, n) {
|
|
3390
|
-
var i, v = crypto.randomBytes(n);
|
|
3391
|
-
for (i = 0; i < n; i++) x[i] = v[i];
|
|
3392
|
-
cleanup(v);
|
|
3393
|
-
});
|
|
3394
|
-
}
|
|
3395
|
-
}
|
|
3396
|
-
})();
|
|
3397
|
-
|
|
3398
|
-
})(module.exports ? module.exports : (self.nacl = self.nacl || {}));
|
|
3399
|
-
} (naclFast));
|
|
3400
|
-
return naclFast.exports;
|
|
3401
|
-
}
|
|
3402
|
-
|
|
3403
|
-
requireNaclFast();
|
|
3404
|
-
|
|
3405
1001
|
var src;
|
|
3406
1002
|
var hasRequiredSrc;
|
|
3407
1003
|
|
|
@@ -3841,7 +1437,7 @@ var PhantomClient = class {
|
|
|
3841
1437
|
throw new Error(`Failed to create wallet: ${error.response?.data?.message || error.message}`);
|
|
3842
1438
|
}
|
|
3843
1439
|
}
|
|
3844
|
-
async prepare(transaction, organizationId, submissionConfig, account) {
|
|
1440
|
+
async prepare(transaction, organizationId, submissionConfig, account, methodName) {
|
|
3845
1441
|
try {
|
|
3846
1442
|
const request = {
|
|
3847
1443
|
transaction,
|
|
@@ -3851,7 +1447,8 @@ var PhantomClient = class {
|
|
|
3851
1447
|
};
|
|
3852
1448
|
const response = await this.axiosInstance.post(`${this.config.apiBaseUrl}/prepare`, request, {
|
|
3853
1449
|
headers: {
|
|
3854
|
-
"Content-Type": "application/json"
|
|
1450
|
+
"Content-Type": "application/json",
|
|
1451
|
+
"X-Rpc-Method": methodName
|
|
3855
1452
|
}
|
|
3856
1453
|
});
|
|
3857
1454
|
return response.data;
|
|
@@ -3881,7 +1478,8 @@ var PhantomClient = class {
|
|
|
3881
1478
|
encodedTransaction,
|
|
3882
1479
|
this.config.organizationId,
|
|
3883
1480
|
submissionConfig,
|
|
3884
|
-
account
|
|
1481
|
+
account,
|
|
1482
|
+
params.methodName
|
|
3885
1483
|
);
|
|
3886
1484
|
return prepareResponse.transaction;
|
|
3887
1485
|
} catch (e) {
|
|
@@ -3894,6 +1492,13 @@ var PhantomClient = class {
|
|
|
3894
1492
|
}
|
|
3895
1493
|
return encodedTransaction;
|
|
3896
1494
|
}
|
|
1495
|
+
getRpcMethodName(networkId, includeSubmissionConfig) {
|
|
1496
|
+
const isEvm = isEthereumChain(networkId);
|
|
1497
|
+
if (isEvm) {
|
|
1498
|
+
return includeSubmissionConfig ? "eth_sendTransaction" : "eth_signTransaction";
|
|
1499
|
+
}
|
|
1500
|
+
return includeSubmissionConfig ? "signAndSendTransaction" : "signTransaction";
|
|
1501
|
+
}
|
|
3897
1502
|
/**
|
|
3898
1503
|
* Private method for shared signing logic
|
|
3899
1504
|
*/
|
|
@@ -3902,6 +1507,7 @@ var PhantomClient = class {
|
|
|
3902
1507
|
const encodedTransaction = params.transaction;
|
|
3903
1508
|
const networkIdParam = params.networkId;
|
|
3904
1509
|
const derivationIndex = params.derivationIndex ?? 0;
|
|
1510
|
+
const methodName = this.getRpcMethodName(networkIdParam, includeSubmissionConfig);
|
|
3905
1511
|
try {
|
|
3906
1512
|
if (!this.config.organizationId) {
|
|
3907
1513
|
throw new Error("organizationId is required to sign a transaction");
|
|
@@ -3923,7 +1529,8 @@ var PhantomClient = class {
|
|
|
3923
1529
|
encodedTransaction,
|
|
3924
1530
|
networkId: networkIdParam,
|
|
3925
1531
|
submissionConfig,
|
|
3926
|
-
account: params.account
|
|
1532
|
+
account: params.account,
|
|
1533
|
+
methodName
|
|
3927
1534
|
});
|
|
3928
1535
|
const signRequest = {
|
|
3929
1536
|
organizationId: this.config.organizationId,
|
|
@@ -3944,7 +1551,11 @@ var PhantomClient = class {
|
|
|
3944
1551
|
params: signRequest,
|
|
3945
1552
|
timestampMs: await getSecureTimestamp()
|
|
3946
1553
|
};
|
|
3947
|
-
const response = await this.kmsApi.postKmsRpc(request
|
|
1554
|
+
const response = await this.kmsApi.postKmsRpc(request, {
|
|
1555
|
+
headers: {
|
|
1556
|
+
"X-Rpc-Method": methodName
|
|
1557
|
+
}
|
|
1558
|
+
});
|
|
3948
1559
|
const result = response.data.result;
|
|
3949
1560
|
const rpcSubmissionResult = response.data["rpc_submission_result"];
|
|
3950
1561
|
const hash = includeSubmissionConfig && rpcSubmissionResult ? rpcSubmissionResult.result : null;
|
|
@@ -4370,6 +1981,129 @@ var __privateMethod = (obj, member, method) => {
|
|
|
4370
1981
|
return method;
|
|
4371
1982
|
};
|
|
4372
1983
|
|
|
1984
|
+
// src/ethereum/siwe.ts
|
|
1985
|
+
var ADDRESS_REGEX = /^0x[a-fA-F0-9]{40}$/;
|
|
1986
|
+
var DOMAIN_REGEX = /^([a-zA-Z0-9]([a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?\.)+[a-zA-Z]{2,}(:[0-9]{1,5})?$/;
|
|
1987
|
+
var IP_REGEX = /^(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)(:[0-9]{1,5})?$/;
|
|
1988
|
+
var LOCALHOST_REGEX = /^localhost(:[0-9]{1,5})?$/;
|
|
1989
|
+
var NONCE_REGEX = /^[a-zA-Z0-9]{8,}$/;
|
|
1990
|
+
var SCHEME_REGEX = /^([a-zA-Z][a-zA-Z0-9+-.]*)$/;
|
|
1991
|
+
function createSiweMessage({
|
|
1992
|
+
address,
|
|
1993
|
+
chainId,
|
|
1994
|
+
domain,
|
|
1995
|
+
nonce,
|
|
1996
|
+
uri,
|
|
1997
|
+
version,
|
|
1998
|
+
scheme,
|
|
1999
|
+
statement: _statement,
|
|
2000
|
+
requestId,
|
|
2001
|
+
resources,
|
|
2002
|
+
issuedAt = /* @__PURE__ */ new Date(),
|
|
2003
|
+
expirationTime,
|
|
2004
|
+
notBefore
|
|
2005
|
+
}) {
|
|
2006
|
+
if (!ADDRESS_REGEX.test(address)) {
|
|
2007
|
+
throw new Error("address must be a hex value of 20 bytes (40 hex characters).");
|
|
2008
|
+
}
|
|
2009
|
+
if (chainId !== Math.floor(chainId)) {
|
|
2010
|
+
throw new Error("chainId must be a EIP-155 chain ID.");
|
|
2011
|
+
}
|
|
2012
|
+
if (!(DOMAIN_REGEX.test(domain) || IP_REGEX.test(domain) || LOCALHOST_REGEX.test(domain))) {
|
|
2013
|
+
throw new Error("domain must be an RFC 3986 authority.");
|
|
2014
|
+
}
|
|
2015
|
+
if (!NONCE_REGEX.test(nonce)) {
|
|
2016
|
+
throw new Error("nonce must be at least 8 characters.");
|
|
2017
|
+
}
|
|
2018
|
+
if (!_isUri(uri)) {
|
|
2019
|
+
throw new Error("uri must be a RFC 3986 URI referring to the resource that is the subject of the signing.");
|
|
2020
|
+
}
|
|
2021
|
+
if (version !== "1") {
|
|
2022
|
+
throw new Error("version must be '1'.");
|
|
2023
|
+
}
|
|
2024
|
+
if (scheme && !SCHEME_REGEX.test(scheme)) {
|
|
2025
|
+
throw new Error("scheme must be an RFC 3986 URI scheme.");
|
|
2026
|
+
}
|
|
2027
|
+
if (_statement?.includes("\n")) {
|
|
2028
|
+
throw new Error("statement must not include '\\n'.");
|
|
2029
|
+
}
|
|
2030
|
+
const origin = scheme ? `${scheme}://${domain}` : domain;
|
|
2031
|
+
const statement = _statement ? `${_statement}
|
|
2032
|
+
` : "";
|
|
2033
|
+
const prefix = `${origin} wants you to sign in with your Ethereum account:
|
|
2034
|
+
${address}
|
|
2035
|
+
|
|
2036
|
+
${statement}`;
|
|
2037
|
+
let suffix = `URI: ${uri}
|
|
2038
|
+
Version: ${version}
|
|
2039
|
+
Chain ID: ${chainId}
|
|
2040
|
+
Nonce: ${nonce}
|
|
2041
|
+
Issued At: ${issuedAt.toISOString()}`;
|
|
2042
|
+
if (expirationTime) {
|
|
2043
|
+
suffix += `
|
|
2044
|
+
Expiration Time: ${expirationTime.toISOString()}`;
|
|
2045
|
+
}
|
|
2046
|
+
if (notBefore) {
|
|
2047
|
+
suffix += `
|
|
2048
|
+
Not Before: ${notBefore.toISOString()}`;
|
|
2049
|
+
}
|
|
2050
|
+
if (requestId) {
|
|
2051
|
+
suffix += `
|
|
2052
|
+
Request ID: ${requestId}`;
|
|
2053
|
+
}
|
|
2054
|
+
if (resources) {
|
|
2055
|
+
let content = "\nResources:";
|
|
2056
|
+
for (const resource of resources) {
|
|
2057
|
+
if (!_isUri(resource)) {
|
|
2058
|
+
throw new Error("resources must be RFC 3986 URIs.");
|
|
2059
|
+
}
|
|
2060
|
+
content += `
|
|
2061
|
+
- ${resource}`;
|
|
2062
|
+
}
|
|
2063
|
+
suffix += content;
|
|
2064
|
+
}
|
|
2065
|
+
return `${prefix}
|
|
2066
|
+
${suffix}`;
|
|
2067
|
+
}
|
|
2068
|
+
function _isUri(value) {
|
|
2069
|
+
if (/[^a-z0-9:/?#[\]@!$&'()*+,;=.\-_~%]/i.test(value))
|
|
2070
|
+
return false;
|
|
2071
|
+
if (/%[^0-9a-f]/i.test(value))
|
|
2072
|
+
return false;
|
|
2073
|
+
if (/%[0-9a-f](:?[^0-9a-f]|$)/i.test(value))
|
|
2074
|
+
return false;
|
|
2075
|
+
const splitted = splitUri(value);
|
|
2076
|
+
const scheme = splitted[1];
|
|
2077
|
+
const authority = splitted[2];
|
|
2078
|
+
const path = splitted[3];
|
|
2079
|
+
const query = splitted[4];
|
|
2080
|
+
const fragment = splitted[5];
|
|
2081
|
+
if (!(scheme?.length && path.length >= 0))
|
|
2082
|
+
return false;
|
|
2083
|
+
if (authority?.length) {
|
|
2084
|
+
if (!(path.length === 0 || /^\//.test(path)))
|
|
2085
|
+
return false;
|
|
2086
|
+
} else {
|
|
2087
|
+
if (/^\/\//.test(path))
|
|
2088
|
+
return false;
|
|
2089
|
+
}
|
|
2090
|
+
if (!/^[a-z][a-z0-9+\-.]*$/.test(scheme.toLowerCase()))
|
|
2091
|
+
return false;
|
|
2092
|
+
let out = "";
|
|
2093
|
+
out += `${scheme}:`;
|
|
2094
|
+
if (authority?.length)
|
|
2095
|
+
out += `//${authority}`;
|
|
2096
|
+
out += path;
|
|
2097
|
+
if (query?.length)
|
|
2098
|
+
out += `?${query}`;
|
|
2099
|
+
if (fragment?.length)
|
|
2100
|
+
out += `#${fragment}`;
|
|
2101
|
+
return out;
|
|
2102
|
+
}
|
|
2103
|
+
function splitUri(value) {
|
|
2104
|
+
return value.match(/(?:([^:/?#]+):)?(?:\/\/([^/?#]*))?([^?#]*)(?:\?([^#]*))?(?:#(.*))?/);
|
|
2105
|
+
}
|
|
2106
|
+
|
|
4373
2107
|
// src/ethereum/strategies/injected.ts
|
|
4374
2108
|
var MAX_RETRIES$1 = 4;
|
|
4375
2109
|
var BASE_DELAY$1 = 100;
|
|
@@ -4486,7 +2220,7 @@ var InjectedEthereumStrategy = class {
|
|
|
4486
2220
|
if (!provider) {
|
|
4487
2221
|
throw new Error("Provider not found.");
|
|
4488
2222
|
}
|
|
4489
|
-
const message =
|
|
2223
|
+
const message = createSiweMessage(signInData);
|
|
4490
2224
|
const address = provider.selectedAddress;
|
|
4491
2225
|
if (!address) {
|
|
4492
2226
|
throw new Error("No address available.");
|
|
@@ -4582,7 +2316,7 @@ function addEventListener$1(event, callback) {
|
|
|
4582
2316
|
eventListeners.set(event, /* @__PURE__ */ new Set());
|
|
4583
2317
|
}
|
|
4584
2318
|
const listeners = eventListeners.get(event);
|
|
4585
|
-
listeners
|
|
2319
|
+
listeners?.add(callback);
|
|
4586
2320
|
return () => removeEventListener$1(event, callback);
|
|
4587
2321
|
}
|
|
4588
2322
|
function removeEventListener$1(event, callback) {
|
|
@@ -4656,16 +2390,6 @@ async function getAccounts() {
|
|
|
4656
2390
|
}
|
|
4657
2391
|
|
|
4658
2392
|
// src/ethereum/signMessage.ts
|
|
4659
|
-
async function signMessage$1(message, address) {
|
|
4660
|
-
const provider = await getProvider$2();
|
|
4661
|
-
if (!provider) {
|
|
4662
|
-
throw new Error("Provider not found.");
|
|
4663
|
-
}
|
|
4664
|
-
if (!provider.isConnected) {
|
|
4665
|
-
await provider.connect({ onlyIfTrusted: false });
|
|
4666
|
-
}
|
|
4667
|
-
return provider.signMessage(message, address);
|
|
4668
|
-
}
|
|
4669
2393
|
async function signPersonalMessage(message, address) {
|
|
4670
2394
|
const provider = await getProvider$2();
|
|
4671
2395
|
if (!provider) {
|
|
@@ -4687,18 +2411,6 @@ async function signTypedData(typedData, address) {
|
|
|
4687
2411
|
return provider.signTypedData(typedData, address);
|
|
4688
2412
|
}
|
|
4689
2413
|
|
|
4690
|
-
// src/ethereum/signIn.ts
|
|
4691
|
-
async function signIn$1(signInData) {
|
|
4692
|
-
const provider = await getProvider$2();
|
|
4693
|
-
if (!provider) {
|
|
4694
|
-
throw new Error("Provider not found.");
|
|
4695
|
-
}
|
|
4696
|
-
if (!provider.isConnected) {
|
|
4697
|
-
await provider.connect({ onlyIfTrusted: false });
|
|
4698
|
-
}
|
|
4699
|
-
return provider.signIn(signInData);
|
|
4700
|
-
}
|
|
4701
|
-
|
|
4702
2414
|
// src/ethereum/sendTransaction.ts
|
|
4703
2415
|
async function sendTransaction(transaction) {
|
|
4704
2416
|
const provider = await getProvider$2();
|
|
@@ -4738,47 +2450,122 @@ async function switchChain(chainId) {
|
|
|
4738
2450
|
}
|
|
4739
2451
|
|
|
4740
2452
|
// src/ethereum/plugin.ts
|
|
4741
|
-
var
|
|
4742
|
-
|
|
4743
|
-
|
|
4744
|
-
|
|
4745
|
-
|
|
4746
|
-
|
|
4747
|
-
|
|
4748
|
-
|
|
4749
|
-
|
|
4750
|
-
|
|
4751
|
-
|
|
4752
|
-
|
|
4753
|
-
|
|
4754
|
-
|
|
4755
|
-
|
|
4756
|
-
|
|
4757
|
-
|
|
4758
|
-
|
|
4759
|
-
|
|
4760
|
-
|
|
4761
|
-
|
|
4762
|
-
|
|
4763
|
-
|
|
4764
|
-
|
|
2453
|
+
var Ethereum = class {
|
|
2454
|
+
constructor() {
|
|
2455
|
+
this._chainId = "0x1";
|
|
2456
|
+
this._accounts = [];
|
|
2457
|
+
this.bindProviderEvents();
|
|
2458
|
+
}
|
|
2459
|
+
get connected() {
|
|
2460
|
+
return this._accounts.length > 0;
|
|
2461
|
+
}
|
|
2462
|
+
get chainId() {
|
|
2463
|
+
return this._chainId;
|
|
2464
|
+
}
|
|
2465
|
+
get accounts() {
|
|
2466
|
+
return this._accounts;
|
|
2467
|
+
}
|
|
2468
|
+
async request(args) {
|
|
2469
|
+
const provider = await getProvider$2();
|
|
2470
|
+
if (!provider) {
|
|
2471
|
+
throw new Error("Provider not found.");
|
|
2472
|
+
}
|
|
2473
|
+
const providerInstance = provider.getProvider();
|
|
2474
|
+
if (!providerInstance) {
|
|
2475
|
+
throw new Error("Provider instance not found.");
|
|
2476
|
+
}
|
|
2477
|
+
return providerInstance.request(args);
|
|
2478
|
+
}
|
|
2479
|
+
async connect() {
|
|
2480
|
+
const accounts = await connect$1();
|
|
2481
|
+
this._accounts = accounts;
|
|
2482
|
+
return accounts;
|
|
2483
|
+
}
|
|
2484
|
+
async disconnect() {
|
|
2485
|
+
await disconnect$1();
|
|
2486
|
+
this._accounts = [];
|
|
2487
|
+
}
|
|
2488
|
+
signPersonalMessage(message, address) {
|
|
2489
|
+
return signPersonalMessage(message, address);
|
|
2490
|
+
}
|
|
2491
|
+
signTypedData(data, address) {
|
|
2492
|
+
return signTypedData(data, address);
|
|
2493
|
+
}
|
|
2494
|
+
signTransaction(transaction) {
|
|
2495
|
+
return signTransaction$1(transaction);
|
|
2496
|
+
}
|
|
2497
|
+
sendTransaction(transaction) {
|
|
2498
|
+
return sendTransaction(transaction);
|
|
2499
|
+
}
|
|
2500
|
+
async switchChain(chainId) {
|
|
2501
|
+
const hexChainId = typeof chainId === "string" ? chainId.toLowerCase().startsWith("0x") ? chainId.toLowerCase() : `0x${parseInt(chainId, 10).toString(16)}` : `0x${chainId.toString(16)}`;
|
|
2502
|
+
await switchChain(hexChainId);
|
|
2503
|
+
this._chainId = hexChainId;
|
|
2504
|
+
}
|
|
2505
|
+
async getChainId() {
|
|
2506
|
+
const chainId = await getChainId();
|
|
2507
|
+
const parsed = parseInt(chainId, 16);
|
|
2508
|
+
this._chainId = chainId;
|
|
2509
|
+
return parsed;
|
|
2510
|
+
}
|
|
2511
|
+
async getAccounts() {
|
|
2512
|
+
const accounts = await getAccounts();
|
|
2513
|
+
this._accounts = accounts;
|
|
2514
|
+
return accounts;
|
|
2515
|
+
}
|
|
2516
|
+
isConnected() {
|
|
2517
|
+
return this._accounts.length > 0;
|
|
2518
|
+
}
|
|
2519
|
+
on(event, listener) {
|
|
2520
|
+
addEventListener$1(event, listener);
|
|
2521
|
+
}
|
|
2522
|
+
off(event, listener) {
|
|
2523
|
+
removeEventListener$1(event, listener);
|
|
2524
|
+
}
|
|
2525
|
+
async bindProviderEvents() {
|
|
2526
|
+
try {
|
|
2527
|
+
const strategy = await getProvider$2();
|
|
2528
|
+
const provider = strategy.getProvider();
|
|
2529
|
+
if (provider) {
|
|
2530
|
+
provider.on("connect", async () => {
|
|
2531
|
+
try {
|
|
2532
|
+
const accounts = await provider.request({ method: "eth_accounts" });
|
|
2533
|
+
if (accounts?.length > 0) {
|
|
2534
|
+
this._accounts = accounts;
|
|
2535
|
+
triggerEvent$1("connect", accounts);
|
|
2536
|
+
}
|
|
2537
|
+
} catch {
|
|
2538
|
+
}
|
|
2539
|
+
});
|
|
2540
|
+
provider.on("disconnect", () => {
|
|
2541
|
+
this._accounts = [];
|
|
2542
|
+
const error = {
|
|
2543
|
+
code: 4900,
|
|
2544
|
+
message: "Provider disconnected"
|
|
2545
|
+
};
|
|
2546
|
+
triggerEvent$1("disconnect", error);
|
|
2547
|
+
});
|
|
2548
|
+
provider.on("accountsChanged", (accounts) => {
|
|
2549
|
+
this._accounts = accounts;
|
|
2550
|
+
triggerEvent$1("accountsChanged", accounts);
|
|
2551
|
+
if (accounts && accounts.length > 0) {
|
|
4765
2552
|
triggerEvent$1("connect", accounts);
|
|
4766
|
-
|
|
2553
|
+
}
|
|
4767
2554
|
});
|
|
4768
|
-
|
|
4769
|
-
|
|
4770
|
-
|
|
4771
|
-
|
|
2555
|
+
provider.on("chainChanged", (chainId) => {
|
|
2556
|
+
this._chainId = chainId;
|
|
2557
|
+
triggerEvent$1("chainChanged", chainId);
|
|
2558
|
+
});
|
|
2559
|
+
}
|
|
2560
|
+
} catch (error) {
|
|
4772
2561
|
}
|
|
4773
|
-
} catch (error) {
|
|
4774
2562
|
}
|
|
4775
|
-
}
|
|
2563
|
+
};
|
|
4776
2564
|
function createEthereumPlugin() {
|
|
4777
2565
|
return {
|
|
4778
2566
|
name: "ethereum",
|
|
4779
2567
|
create: () => {
|
|
4780
|
-
|
|
4781
|
-
return ethereum;
|
|
2568
|
+
return new Ethereum();
|
|
4782
2569
|
}
|
|
4783
2570
|
};
|
|
4784
2571
|
}
|
|
@@ -4988,28 +2775,26 @@ function addEventListener(event, callback) {
|
|
|
4988
2775
|
if (!eventCallbacks.has(event)) {
|
|
4989
2776
|
eventCallbacks.set(event, /* @__PURE__ */ new Set());
|
|
4990
2777
|
}
|
|
4991
|
-
eventCallbacks.get(event)
|
|
2778
|
+
eventCallbacks.get(event)?.add(callback);
|
|
4992
2779
|
return () => {
|
|
4993
2780
|
removeEventListener(event, callback);
|
|
4994
2781
|
};
|
|
4995
2782
|
}
|
|
4996
2783
|
function removeEventListener(event, callback) {
|
|
4997
2784
|
if (eventCallbacks.has(event)) {
|
|
4998
|
-
eventCallbacks.get(event)
|
|
4999
|
-
if (eventCallbacks.get(event)
|
|
2785
|
+
eventCallbacks.get(event)?.delete(callback);
|
|
2786
|
+
if (eventCallbacks.get(event)?.size === 0) {
|
|
5000
2787
|
eventCallbacks.delete(event);
|
|
5001
2788
|
}
|
|
5002
2789
|
}
|
|
5003
2790
|
}
|
|
5004
2791
|
function triggerEvent(event, ...args) {
|
|
5005
2792
|
if (eventCallbacks.has(event)) {
|
|
5006
|
-
eventCallbacks.get(event)
|
|
5007
|
-
|
|
5008
|
-
cb(args
|
|
5009
|
-
}
|
|
5010
|
-
|
|
5011
|
-
} else if (event === "accountChanged" && args[0] && typeof args[0] === "string") {
|
|
5012
|
-
cb(args[0]);
|
|
2793
|
+
eventCallbacks.get(event)?.forEach((cb) => {
|
|
2794
|
+
try {
|
|
2795
|
+
cb(...args);
|
|
2796
|
+
} catch (error) {
|
|
2797
|
+
console.error(`Error in ${event} event listener:`, error);
|
|
5013
2798
|
}
|
|
5014
2799
|
});
|
|
5015
2800
|
}
|
|
@@ -5099,28 +2884,15 @@ async function signTransaction(transaction) {
|
|
|
5099
2884
|
}
|
|
5100
2885
|
|
|
5101
2886
|
// src/solana/signAllTransactions.ts
|
|
5102
|
-
async function signAllTransactions(transactions) {
|
|
5103
|
-
const provider = await getProvider$1();
|
|
5104
|
-
if (!provider) {
|
|
5105
|
-
throw new Error("Provider not found.");
|
|
5106
|
-
}
|
|
5107
|
-
if (!provider.isConnected) {
|
|
5108
|
-
await provider.connect({ onlyIfTrusted: false });
|
|
5109
|
-
}
|
|
5110
|
-
return provider.signAllTransactions(transactions);
|
|
5111
|
-
}
|
|
5112
|
-
|
|
5113
|
-
// src/solana/signIn.ts
|
|
5114
|
-
async function signIn(signInData) {
|
|
2887
|
+
async function signAllTransactions(transactions) {
|
|
5115
2888
|
const provider = await getProvider$1();
|
|
5116
2889
|
if (!provider) {
|
|
5117
2890
|
throw new Error("Provider not found.");
|
|
5118
2891
|
}
|
|
5119
|
-
|
|
5120
|
-
|
|
5121
|
-
triggerEvent("connect", result.address);
|
|
2892
|
+
if (!provider.isConnected) {
|
|
2893
|
+
await provider.connect({ onlyIfTrusted: false });
|
|
5122
2894
|
}
|
|
5123
|
-
return
|
|
2895
|
+
return provider.signAllTransactions(transactions);
|
|
5124
2896
|
}
|
|
5125
2897
|
|
|
5126
2898
|
// src/solana/signMessage.ts
|
|
@@ -5136,43 +2908,112 @@ async function signMessage(message, display) {
|
|
|
5136
2908
|
}
|
|
5137
2909
|
|
|
5138
2910
|
// src/solana/plugin.ts
|
|
5139
|
-
var
|
|
5140
|
-
|
|
5141
|
-
|
|
5142
|
-
|
|
5143
|
-
|
|
5144
|
-
|
|
5145
|
-
|
|
5146
|
-
|
|
5147
|
-
|
|
5148
|
-
|
|
5149
|
-
|
|
5150
|
-
|
|
5151
|
-
|
|
5152
|
-
|
|
5153
|
-
|
|
5154
|
-
const strategy = await getProvider$1();
|
|
5155
|
-
const provider = strategy.getProvider();
|
|
5156
|
-
if (provider) {
|
|
5157
|
-
provider.on("connect", (publicKey) => {
|
|
5158
|
-
if (publicKey)
|
|
5159
|
-
triggerEvent("connect", publicKey.toString());
|
|
5160
|
-
});
|
|
5161
|
-
provider.on("disconnect", () => triggerEvent("disconnect"));
|
|
5162
|
-
provider.on("accountChanged", (publicKey) => {
|
|
5163
|
-
if (publicKey)
|
|
5164
|
-
triggerEvent("accountChanged", publicKey.toString());
|
|
5165
|
-
});
|
|
2911
|
+
var Solana = class {
|
|
2912
|
+
constructor() {
|
|
2913
|
+
this._publicKey = null;
|
|
2914
|
+
this.bindProviderEvents();
|
|
2915
|
+
}
|
|
2916
|
+
get publicKey() {
|
|
2917
|
+
return this._publicKey;
|
|
2918
|
+
}
|
|
2919
|
+
get connected() {
|
|
2920
|
+
return this._publicKey !== null;
|
|
2921
|
+
}
|
|
2922
|
+
async connect(options) {
|
|
2923
|
+
const address = await connect(options);
|
|
2924
|
+
if (!address) {
|
|
2925
|
+
throw new Error("Failed to connect to Solana wallet");
|
|
5166
2926
|
}
|
|
5167
|
-
|
|
2927
|
+
this._publicKey = address;
|
|
2928
|
+
return { publicKey: address };
|
|
5168
2929
|
}
|
|
5169
|
-
|
|
2930
|
+
async disconnect() {
|
|
2931
|
+
await disconnect();
|
|
2932
|
+
this._publicKey = null;
|
|
2933
|
+
}
|
|
2934
|
+
async signMessage(message) {
|
|
2935
|
+
const messageBytes = typeof message === "string" ? new TextEncoder().encode(message) : message;
|
|
2936
|
+
const result = await signMessage(messageBytes);
|
|
2937
|
+
return {
|
|
2938
|
+
signature: result.signature instanceof Uint8Array ? result.signature : new Uint8Array(result.signature),
|
|
2939
|
+
publicKey: result.address || this._publicKey || ""
|
|
2940
|
+
};
|
|
2941
|
+
}
|
|
2942
|
+
signTransaction(transaction) {
|
|
2943
|
+
return signTransaction(transaction);
|
|
2944
|
+
}
|
|
2945
|
+
async signAndSendTransaction(transaction) {
|
|
2946
|
+
const result = await signAndSendTransaction(transaction);
|
|
2947
|
+
return { signature: result.signature };
|
|
2948
|
+
}
|
|
2949
|
+
signAllTransactions(transactions) {
|
|
2950
|
+
return signAllTransactions(transactions);
|
|
2951
|
+
}
|
|
2952
|
+
async signAndSendAllTransactions(transactions) {
|
|
2953
|
+
const result = await signAndSendAllTransactions(transactions);
|
|
2954
|
+
return { signatures: result.signatures };
|
|
2955
|
+
}
|
|
2956
|
+
async switchNetwork(_network) {
|
|
2957
|
+
return Promise.resolve();
|
|
2958
|
+
}
|
|
2959
|
+
async getPublicKey() {
|
|
2960
|
+
if (this._publicKey) {
|
|
2961
|
+
return this._publicKey;
|
|
2962
|
+
}
|
|
2963
|
+
try {
|
|
2964
|
+
const account = await getAccount();
|
|
2965
|
+
this._publicKey = account || null;
|
|
2966
|
+
return this._publicKey;
|
|
2967
|
+
} catch {
|
|
2968
|
+
return null;
|
|
2969
|
+
}
|
|
2970
|
+
}
|
|
2971
|
+
isConnected() {
|
|
2972
|
+
return this._publicKey !== null;
|
|
2973
|
+
}
|
|
2974
|
+
on(event, listener) {
|
|
2975
|
+
addEventListener(event, listener);
|
|
2976
|
+
}
|
|
2977
|
+
off(event, listener) {
|
|
2978
|
+
removeEventListener(event, listener);
|
|
2979
|
+
}
|
|
2980
|
+
async bindProviderEvents() {
|
|
2981
|
+
try {
|
|
2982
|
+
const strategy = await getProvider$1();
|
|
2983
|
+
const provider = strategy.getProvider();
|
|
2984
|
+
if (provider) {
|
|
2985
|
+
provider.on("connect", (publicKey) => {
|
|
2986
|
+
if (publicKey) {
|
|
2987
|
+
const pubKey = publicKey.toString();
|
|
2988
|
+
this._publicKey = pubKey;
|
|
2989
|
+
triggerEvent("connect", pubKey);
|
|
2990
|
+
}
|
|
2991
|
+
});
|
|
2992
|
+
provider.on("disconnect", () => {
|
|
2993
|
+
this._publicKey = null;
|
|
2994
|
+
triggerEvent("disconnect");
|
|
2995
|
+
});
|
|
2996
|
+
provider.on("accountChanged", (publicKey) => {
|
|
2997
|
+
if (publicKey) {
|
|
2998
|
+
const pubKey = publicKey.toString();
|
|
2999
|
+
this._publicKey = pubKey;
|
|
3000
|
+
triggerEvent("accountChanged", pubKey);
|
|
3001
|
+
triggerEvent("connect", pubKey);
|
|
3002
|
+
} else {
|
|
3003
|
+
this._publicKey = null;
|
|
3004
|
+
triggerEvent("accountChanged", null);
|
|
3005
|
+
}
|
|
3006
|
+
});
|
|
3007
|
+
}
|
|
3008
|
+
} catch (error) {
|
|
3009
|
+
}
|
|
3010
|
+
}
|
|
3011
|
+
};
|
|
5170
3012
|
function createSolanaPlugin() {
|
|
5171
3013
|
return {
|
|
5172
3014
|
name: "solana",
|
|
5173
3015
|
create: () => {
|
|
5174
|
-
|
|
5175
|
-
return solana;
|
|
3016
|
+
return new Solana();
|
|
5176
3017
|
}
|
|
5177
3018
|
};
|
|
5178
3019
|
}
|
|
@@ -10719,7 +8560,7 @@ var EmbeddedSolanaChain = class {
|
|
|
10719
8560
|
this.currentNetworkId = NetworkId.SOLANA_MAINNET;
|
|
10720
8561
|
this._connected = false;
|
|
10721
8562
|
this._publicKey = null;
|
|
10722
|
-
this.eventEmitter = new
|
|
8563
|
+
this.eventEmitter = new EventEmitter3();
|
|
10723
8564
|
this.setupEventListeners();
|
|
10724
8565
|
this.syncInitialState();
|
|
10725
8566
|
}
|
|
@@ -10849,7 +8690,7 @@ var EmbeddedEthereumChain = class {
|
|
|
10849
8690
|
this.currentNetworkId = NetworkId.ETHEREUM_MAINNET;
|
|
10850
8691
|
this._connected = false;
|
|
10851
8692
|
this._accounts = [];
|
|
10852
|
-
this.eventEmitter = new
|
|
8693
|
+
this.eventEmitter = new EventEmitter3();
|
|
10853
8694
|
this.setupEventListeners();
|
|
10854
8695
|
this.syncInitialState();
|
|
10855
8696
|
}
|
|
@@ -11113,7 +8954,7 @@ var EmbeddedProvider$1 = class EmbeddedProvider {
|
|
|
11113
8954
|
if (!this.eventListeners.has(event)) {
|
|
11114
8955
|
this.eventListeners.set(event, /* @__PURE__ */ new Set());
|
|
11115
8956
|
}
|
|
11116
|
-
this.eventListeners.get(event)
|
|
8957
|
+
this.eventListeners.get(event)?.add(callback);
|
|
11117
8958
|
this.logger.log("EMBEDDED_PROVIDER", "Event listener added", { event });
|
|
11118
8959
|
}
|
|
11119
8960
|
off(event, callback) {
|
|
@@ -12004,7 +9845,8 @@ var EmbeddedProvider$1 = class EmbeddedProvider {
|
|
|
12004
9845
|
apiBaseUrl: this.config.apiBaseUrl,
|
|
12005
9846
|
organizationId: session.organizationId,
|
|
12006
9847
|
headers: {
|
|
12007
|
-
...this.platform.analyticsHeaders || {}
|
|
9848
|
+
...this.platform.analyticsHeaders || {},
|
|
9849
|
+
...session.authUserId ? { "x-auth-user-id": session.authUserId } : {}
|
|
12008
9850
|
}
|
|
12009
9851
|
},
|
|
12010
9852
|
this.stamper
|
|
@@ -12554,7 +10396,7 @@ async function discoverSolanaWallets() {
|
|
|
12554
10396
|
return chainLower.startsWith("solana:") || chainLower === "solana";
|
|
12555
10397
|
}) || wallet.features && typeof wallet.features === "object" && Object.keys(wallet.features).some((featureKey) => {
|
|
12556
10398
|
const featureLower = featureKey.toLowerCase();
|
|
12557
|
-
return featureLower.
|
|
10399
|
+
return featureLower.startsWith("solana:");
|
|
12558
10400
|
});
|
|
12559
10401
|
if (!supportsSolana) {
|
|
12560
10402
|
const featureKeys = wallet.features ? Object.keys(wallet.features) : [];
|
|
@@ -12697,7 +10539,8 @@ async function discoverWallets(addressTypes) {
|
|
|
12697
10539
|
}
|
|
12698
10540
|
var InjectedWalletSolanaChain = class {
|
|
12699
10541
|
constructor(provider, walletId, walletName) {
|
|
12700
|
-
|
|
10542
|
+
// Expose eventEmitter for testing - allows tests to trigger events directly
|
|
10543
|
+
this.eventEmitter = new EventEmitter3();
|
|
12701
10544
|
this._connected = false;
|
|
12702
10545
|
this._publicKey = null;
|
|
12703
10546
|
this.provider = provider;
|
|
@@ -12925,6 +10768,7 @@ var InjectedWalletSolanaChain = class {
|
|
|
12925
10768
|
});
|
|
12926
10769
|
this.provider.on("accountChanged", (publicKey) => {
|
|
12927
10770
|
this._publicKey = publicKey;
|
|
10771
|
+
this._connected = publicKey != null && publicKey.length > 0;
|
|
12928
10772
|
this.eventEmitter.emit("accountChanged", publicKey);
|
|
12929
10773
|
});
|
|
12930
10774
|
}
|
|
@@ -12938,22 +10782,23 @@ var InjectedWalletSolanaChain = class {
|
|
|
12938
10782
|
};
|
|
12939
10783
|
var WalletStandardSolanaAdapter = class {
|
|
12940
10784
|
constructor(wallet, walletId, walletName) {
|
|
12941
|
-
this.
|
|
10785
|
+
this.eventEmitter = new EventEmitter3();
|
|
12942
10786
|
this._publicKey = null;
|
|
12943
10787
|
this.wallet = wallet;
|
|
12944
10788
|
this.walletId = walletId;
|
|
12945
10789
|
this.walletName = walletName;
|
|
10790
|
+
this.setupEventListeners();
|
|
12946
10791
|
}
|
|
12947
10792
|
get connected() {
|
|
12948
|
-
return this.
|
|
10793
|
+
return this._publicKey !== null;
|
|
12949
10794
|
}
|
|
12950
10795
|
get publicKey() {
|
|
12951
10796
|
return this._publicKey;
|
|
12952
10797
|
}
|
|
12953
10798
|
async connect(_options) {
|
|
12954
10799
|
try {
|
|
12955
|
-
const connectFeature = this.wallet.features
|
|
12956
|
-
if (!connectFeature
|
|
10800
|
+
const connectFeature = this.wallet.features["standard:connect"];
|
|
10801
|
+
if (!connectFeature) {
|
|
12957
10802
|
throw new Error("Wallet Standard connect feature not available");
|
|
12958
10803
|
}
|
|
12959
10804
|
const connectResult = await connectFeature.connect();
|
|
@@ -12974,14 +10819,13 @@ var WalletStandardSolanaAdapter = class {
|
|
|
12974
10819
|
if (typeof firstAccount === "string") {
|
|
12975
10820
|
address = firstAccount;
|
|
12976
10821
|
} else if (typeof firstAccount === "object" && firstAccount !== null) {
|
|
12977
|
-
address = firstAccount.address || firstAccount.publicKey?.toString() || (firstAccount.publicKey instanceof Uint8Array ? Buffer.from(firstAccount.publicKey).toString("hex") : void 0);
|
|
10822
|
+
address = firstAccount.address || firstAccount.publicKey?.toString() || (firstAccount.publicKey instanceof Uint8Array ? bufferExports.Buffer.from(firstAccount.publicKey).toString("hex") : void 0);
|
|
12978
10823
|
}
|
|
12979
10824
|
if (!address) {
|
|
12980
10825
|
throw new Error(
|
|
12981
10826
|
`Could not extract address from account. Account structure: ${JSON.stringify(firstAccount, null, 2)}`
|
|
12982
10827
|
);
|
|
12983
10828
|
}
|
|
12984
|
-
this._connected = true;
|
|
12985
10829
|
this._publicKey = address;
|
|
12986
10830
|
return { publicKey: address };
|
|
12987
10831
|
} catch (error) {
|
|
@@ -12995,11 +10839,10 @@ var WalletStandardSolanaAdapter = class {
|
|
|
12995
10839
|
}
|
|
12996
10840
|
async disconnect() {
|
|
12997
10841
|
try {
|
|
12998
|
-
const disconnectFeature = this.wallet.features
|
|
12999
|
-
if (disconnectFeature
|
|
10842
|
+
const disconnectFeature = this.wallet.features["standard:disconnect"];
|
|
10843
|
+
if (disconnectFeature) {
|
|
13000
10844
|
await disconnectFeature.disconnect();
|
|
13001
10845
|
}
|
|
13002
|
-
this._connected = false;
|
|
13003
10846
|
this._publicKey = null;
|
|
13004
10847
|
} catch (error) {
|
|
13005
10848
|
debug.error(DebugCategory.INJECTED_PROVIDER, "Wallet Standard Solana disconnect failed", {
|
|
@@ -13012,14 +10855,14 @@ var WalletStandardSolanaAdapter = class {
|
|
|
13012
10855
|
}
|
|
13013
10856
|
async signMessage(message) {
|
|
13014
10857
|
try {
|
|
13015
|
-
const signMessageFeature = this.wallet.features
|
|
13016
|
-
if (!signMessageFeature
|
|
10858
|
+
const signMessageFeature = this.wallet.features["solana:signMessage"];
|
|
10859
|
+
if (!signMessageFeature) {
|
|
13017
10860
|
throw new Error("Wallet Standard signMessage feature not available");
|
|
13018
10861
|
}
|
|
13019
10862
|
const messageBytes = typeof message === "string" ? new TextEncoder().encode(message) : message;
|
|
13020
10863
|
const result = await signMessageFeature.signMessage({
|
|
13021
10864
|
message: messageBytes,
|
|
13022
|
-
account: this.wallet.accounts
|
|
10865
|
+
account: this.wallet.accounts[0]
|
|
13023
10866
|
});
|
|
13024
10867
|
if (!Array.isArray(result) || result.length === 0) {
|
|
13025
10868
|
throw new Error(`Expected array result from signMessage, got: ${typeof result}`);
|
|
@@ -13032,7 +10875,7 @@ var WalletStandardSolanaAdapter = class {
|
|
|
13032
10875
|
if (signature.length === 0) {
|
|
13033
10876
|
throw new Error(`Signature is empty`);
|
|
13034
10877
|
}
|
|
13035
|
-
const publicKey = signedMessageResult.account?.address || this.wallet.accounts
|
|
10878
|
+
const publicKey = signedMessageResult.account?.address || this.wallet.accounts[0]?.address || this._publicKey || "";
|
|
13036
10879
|
return { signature, publicKey };
|
|
13037
10880
|
} catch (error) {
|
|
13038
10881
|
debug.error(DebugCategory.INJECTED_PROVIDER, "Wallet Standard Solana signMessage failed", {
|
|
@@ -13045,8 +10888,8 @@ var WalletStandardSolanaAdapter = class {
|
|
|
13045
10888
|
}
|
|
13046
10889
|
async signTransaction(transaction) {
|
|
13047
10890
|
try {
|
|
13048
|
-
const signTransactionFeature = this.wallet.features
|
|
13049
|
-
if (!signTransactionFeature
|
|
10891
|
+
const signTransactionFeature = this.wallet.features["solana:signTransaction"];
|
|
10892
|
+
if (!signTransactionFeature) {
|
|
13050
10893
|
throw new Error("Wallet Standard signTransaction feature not available");
|
|
13051
10894
|
}
|
|
13052
10895
|
if (!this.wallet.accounts || this.wallet.accounts.length === 0) {
|
|
@@ -13065,7 +10908,8 @@ var WalletStandardSolanaAdapter = class {
|
|
|
13065
10908
|
transactionData = firstItem.signedTransaction || firstItem.transaction;
|
|
13066
10909
|
}
|
|
13067
10910
|
} else if (results && typeof results === "object" && !Array.isArray(results)) {
|
|
13068
|
-
|
|
10911
|
+
const resultObj = results;
|
|
10912
|
+
transactionData = resultObj.transaction || resultObj.signedTransaction;
|
|
13069
10913
|
}
|
|
13070
10914
|
if (!transactionData) {
|
|
13071
10915
|
throw new Error("No transaction data found in Wallet Standard result");
|
|
@@ -13087,8 +10931,8 @@ var WalletStandardSolanaAdapter = class {
|
|
|
13087
10931
|
}
|
|
13088
10932
|
async signAndSendTransaction(transaction) {
|
|
13089
10933
|
try {
|
|
13090
|
-
const signAndSendTransactionFeature = this.wallet.features
|
|
13091
|
-
if (!signAndSendTransactionFeature
|
|
10934
|
+
const signAndSendTransactionFeature = this.wallet.features["solana:signAndSendTransaction"];
|
|
10935
|
+
if (!signAndSendTransactionFeature) {
|
|
13092
10936
|
throw new Error("Wallet Standard signAndSendTransaction feature not available");
|
|
13093
10937
|
}
|
|
13094
10938
|
if (!this.wallet.accounts || this.wallet.accounts.length === 0) {
|
|
@@ -13159,40 +11003,93 @@ var WalletStandardSolanaAdapter = class {
|
|
|
13159
11003
|
throw error;
|
|
13160
11004
|
}
|
|
13161
11005
|
}
|
|
13162
|
-
async switchNetwork(
|
|
13163
|
-
|
|
13164
|
-
const switchNetworkFeature = this.wallet.features?.["standard:switchNetwork"];
|
|
13165
|
-
if (switchNetworkFeature && typeof switchNetworkFeature.switchNetwork === "function") {
|
|
13166
|
-
const chainId = network === "mainnet" ? "solana:mainnet" : "solana:devnet";
|
|
13167
|
-
await switchNetworkFeature.switchNetwork({ chain: chainId });
|
|
13168
|
-
}
|
|
13169
|
-
} catch (error) {
|
|
13170
|
-
debug.error(DebugCategory.INJECTED_PROVIDER, "Wallet Standard Solana switchNetwork failed", {
|
|
13171
|
-
walletId: this.walletId,
|
|
13172
|
-
walletName: this.walletName,
|
|
13173
|
-
network,
|
|
13174
|
-
error: error instanceof Error ? error.message : String(error)
|
|
13175
|
-
});
|
|
13176
|
-
throw error;
|
|
13177
|
-
}
|
|
11006
|
+
async switchNetwork(_network) {
|
|
11007
|
+
return Promise.resolve();
|
|
13178
11008
|
}
|
|
13179
11009
|
getPublicKey() {
|
|
13180
11010
|
return Promise.resolve(this._publicKey);
|
|
13181
11011
|
}
|
|
13182
11012
|
isConnected() {
|
|
13183
|
-
return this.
|
|
11013
|
+
return this._publicKey !== null;
|
|
13184
11014
|
}
|
|
13185
|
-
|
|
13186
|
-
|
|
13187
|
-
|
|
13188
|
-
|
|
11015
|
+
/**
|
|
11016
|
+
* Set up event listeners for Wallet Standard events
|
|
11017
|
+
* Maps Wallet Standard "change" events to "accountChanged" events
|
|
11018
|
+
*
|
|
11019
|
+
* Note: Wallet Standard only has a "change" event. There are no "connect" or "disconnect" events.
|
|
11020
|
+
* Connection/disconnection is indicated by the presence or absence of accounts in the change event.
|
|
11021
|
+
*/
|
|
11022
|
+
setupEventListeners() {
|
|
11023
|
+
const eventsFeature = this.wallet.features["standard:events"];
|
|
11024
|
+
if (!eventsFeature) {
|
|
11025
|
+
debug.log(DebugCategory.INJECTED_PROVIDER, "Wallet Standard events feature not available", {
|
|
11026
|
+
walletId: this.walletId,
|
|
11027
|
+
walletName: this.walletName
|
|
11028
|
+
});
|
|
11029
|
+
return;
|
|
13189
11030
|
}
|
|
11031
|
+
debug.log(DebugCategory.INJECTED_PROVIDER, "Setting up Wallet Standard event listeners", {
|
|
11032
|
+
walletId: this.walletId,
|
|
11033
|
+
walletName: this.walletName
|
|
11034
|
+
});
|
|
11035
|
+
eventsFeature.on("change", (properties) => {
|
|
11036
|
+
debug.log(DebugCategory.INJECTED_PROVIDER, "Wallet Standard change event received", {
|
|
11037
|
+
walletId: this.walletId,
|
|
11038
|
+
walletName: this.walletName,
|
|
11039
|
+
hasAccounts: !!properties.accounts,
|
|
11040
|
+
accountCount: properties.accounts?.length || 0
|
|
11041
|
+
});
|
|
11042
|
+
if (properties.accounts !== void 0) {
|
|
11043
|
+
if (properties.accounts.length > 0) {
|
|
11044
|
+
const firstAccount = properties.accounts[0];
|
|
11045
|
+
const address = this.extractAccountAddress(firstAccount);
|
|
11046
|
+
if (address) {
|
|
11047
|
+
this._publicKey = address;
|
|
11048
|
+
this.eventEmitter.emit("accountChanged", address);
|
|
11049
|
+
this.eventEmitter.emit("connect", address);
|
|
11050
|
+
debug.log(DebugCategory.INJECTED_PROVIDER, "Emitted accountChanged and connect events", {
|
|
11051
|
+
walletId: this.walletId,
|
|
11052
|
+
walletName: this.walletName,
|
|
11053
|
+
address
|
|
11054
|
+
});
|
|
11055
|
+
} else {
|
|
11056
|
+
this._publicKey = null;
|
|
11057
|
+
this.eventEmitter.emit("accountChanged", null);
|
|
11058
|
+
debug.log(DebugCategory.INJECTED_PROVIDER, "Emitted accountChanged event (null - invalid account)", {
|
|
11059
|
+
walletId: this.walletId,
|
|
11060
|
+
walletName: this.walletName
|
|
11061
|
+
});
|
|
11062
|
+
}
|
|
11063
|
+
} else {
|
|
11064
|
+
this._publicKey = null;
|
|
11065
|
+
this.eventEmitter.emit("accountChanged", null);
|
|
11066
|
+
this.eventEmitter.emit("disconnect");
|
|
11067
|
+
debug.log(DebugCategory.INJECTED_PROVIDER, "Emitted accountChanged and disconnect events", {
|
|
11068
|
+
walletId: this.walletId,
|
|
11069
|
+
walletName: this.walletName
|
|
11070
|
+
});
|
|
11071
|
+
}
|
|
11072
|
+
}
|
|
11073
|
+
});
|
|
13190
11074
|
}
|
|
13191
|
-
|
|
13192
|
-
|
|
13193
|
-
|
|
13194
|
-
|
|
13195
|
-
|
|
11075
|
+
extractAccountAddress(account) {
|
|
11076
|
+
return account.address;
|
|
11077
|
+
}
|
|
11078
|
+
on(event, listener) {
|
|
11079
|
+
this.eventEmitter.on(event, listener);
|
|
11080
|
+
debug.log(DebugCategory.INJECTED_PROVIDER, "Added event listener", {
|
|
11081
|
+
walletId: this.walletId,
|
|
11082
|
+
walletName: this.walletName,
|
|
11083
|
+
event
|
|
11084
|
+
});
|
|
11085
|
+
}
|
|
11086
|
+
off(event, listener) {
|
|
11087
|
+
this.eventEmitter.off(event, listener);
|
|
11088
|
+
debug.log(DebugCategory.INJECTED_PROVIDER, "Removed event listener", {
|
|
11089
|
+
walletId: this.walletId,
|
|
11090
|
+
walletName: this.walletName,
|
|
11091
|
+
event
|
|
11092
|
+
});
|
|
13196
11093
|
}
|
|
13197
11094
|
/**
|
|
13198
11095
|
* Serialize a transaction to Uint8Array for Wallet Standard API
|
|
@@ -13236,7 +11133,8 @@ var WalletStandardSolanaAdapter = class {
|
|
|
13236
11133
|
};
|
|
13237
11134
|
var InjectedWalletEthereumChain = class {
|
|
13238
11135
|
constructor(provider, walletId, walletName) {
|
|
13239
|
-
|
|
11136
|
+
// Expose eventEmitter for testing - allows tests to trigger events directly
|
|
11137
|
+
this.eventEmitter = new EventEmitter3();
|
|
13240
11138
|
this._connected = false;
|
|
13241
11139
|
this._chainId = "0x1";
|
|
13242
11140
|
this._accounts = [];
|
|
@@ -13610,215 +11508,15 @@ var InjectedWalletEthereumChain = class {
|
|
|
13610
11508
|
});
|
|
13611
11509
|
this.provider.on("accountsChanged", (accounts) => {
|
|
13612
11510
|
this._accounts = accounts;
|
|
13613
|
-
this.
|
|
13614
|
-
|
|
13615
|
-
|
|
13616
|
-
|
|
13617
|
-
this.
|
|
13618
|
-
|
|
13619
|
-
|
|
13620
|
-
|
|
13621
|
-
on(event, listener) {
|
|
13622
|
-
this.eventEmitter.on(event, listener);
|
|
13623
|
-
}
|
|
13624
|
-
off(event, listener) {
|
|
13625
|
-
this.eventEmitter.off(event, listener);
|
|
13626
|
-
}
|
|
13627
|
-
};
|
|
13628
|
-
var PhantomSolanaChain = class {
|
|
13629
|
-
constructor(phantom) {
|
|
13630
|
-
this._publicKey = null;
|
|
13631
|
-
this.eventEmitter = new EventEmitter4();
|
|
13632
|
-
this.phantom = phantom;
|
|
13633
|
-
this.setupEventListeners();
|
|
13634
|
-
}
|
|
13635
|
-
// Wallet adapter compliant properties
|
|
13636
|
-
get connected() {
|
|
13637
|
-
return this._publicKey !== null;
|
|
13638
|
-
}
|
|
13639
|
-
get publicKey() {
|
|
13640
|
-
return this._publicKey;
|
|
13641
|
-
}
|
|
13642
|
-
// Connection methods
|
|
13643
|
-
async connect(options) {
|
|
13644
|
-
const result = await this.phantom.solana.connect(options);
|
|
13645
|
-
if (!result) {
|
|
13646
|
-
throw new Error("Failed to connect to Solana wallet");
|
|
13647
|
-
}
|
|
13648
|
-
const publicKey = typeof result === "string" ? result : "";
|
|
13649
|
-
this._publicKey = publicKey;
|
|
13650
|
-
return { publicKey };
|
|
13651
|
-
}
|
|
13652
|
-
async disconnect() {
|
|
13653
|
-
await this.phantom.solana.disconnect();
|
|
13654
|
-
this._publicKey = null;
|
|
13655
|
-
}
|
|
13656
|
-
// Standard wallet adapter methods
|
|
13657
|
-
async signMessage(message) {
|
|
13658
|
-
const messageBytes = typeof message === "string" ? new TextEncoder().encode(message) : message;
|
|
13659
|
-
const result = await this.phantom.solana.signMessage(messageBytes);
|
|
13660
|
-
return {
|
|
13661
|
-
signature: result.signature instanceof Uint8Array ? result.signature : new Uint8Array(bufferExports.Buffer.from(result.signature, "base64")),
|
|
13662
|
-
publicKey: this._publicKey || ""
|
|
13663
|
-
};
|
|
13664
|
-
}
|
|
13665
|
-
async signTransaction(transaction) {
|
|
13666
|
-
if (!this.connected) {
|
|
13667
|
-
return Promise.reject(new Error("Provider not connected. Call provider connect first."));
|
|
13668
|
-
}
|
|
13669
|
-
try {
|
|
13670
|
-
const result = await this.phantom.solana.signTransaction(transaction);
|
|
13671
|
-
return result;
|
|
13672
|
-
} catch (error) {
|
|
13673
|
-
return Promise.reject(error);
|
|
13674
|
-
}
|
|
13675
|
-
}
|
|
13676
|
-
async signAndSendTransaction(transaction) {
|
|
13677
|
-
const result = await this.phantom.solana.signAndSendTransaction(transaction);
|
|
13678
|
-
return { signature: result.signature };
|
|
13679
|
-
}
|
|
13680
|
-
async signAllTransactions(transactions) {
|
|
13681
|
-
if (!this.connected) {
|
|
13682
|
-
return Promise.reject(new Error("Provider not connected. Call provider connect first."));
|
|
13683
|
-
}
|
|
13684
|
-
try {
|
|
13685
|
-
const result = await this.phantom.solana.signAllTransactions(transactions);
|
|
13686
|
-
return result;
|
|
13687
|
-
} catch (error) {
|
|
13688
|
-
return Promise.reject(error);
|
|
13689
|
-
}
|
|
13690
|
-
}
|
|
13691
|
-
async signAndSendAllTransactions(transactions) {
|
|
13692
|
-
if (!this.connected) {
|
|
13693
|
-
return Promise.reject(new Error("Provider not connected. Call provider connect first."));
|
|
13694
|
-
}
|
|
13695
|
-
try {
|
|
13696
|
-
const result = await this.phantom.solana.signAndSendAllTransactions(transactions);
|
|
13697
|
-
return { signatures: result.signatures };
|
|
13698
|
-
} catch (error) {
|
|
13699
|
-
return Promise.reject(error);
|
|
13700
|
-
}
|
|
13701
|
-
}
|
|
13702
|
-
switchNetwork(_network) {
|
|
13703
|
-
return Promise.resolve();
|
|
13704
|
-
}
|
|
13705
|
-
// Legacy methods
|
|
13706
|
-
getPublicKey() {
|
|
13707
|
-
return Promise.resolve(this._publicKey);
|
|
13708
|
-
}
|
|
13709
|
-
isConnected() {
|
|
13710
|
-
return this.connected;
|
|
13711
|
-
}
|
|
13712
|
-
setupEventListeners() {
|
|
13713
|
-
this.phantom.solana.addEventListener("connect", (publicKey) => {
|
|
13714
|
-
this._publicKey = publicKey;
|
|
13715
|
-
this.eventEmitter.emit("connect", publicKey);
|
|
13716
|
-
});
|
|
13717
|
-
this.phantom.solana.addEventListener("disconnect", () => {
|
|
13718
|
-
this._publicKey = null;
|
|
13719
|
-
this.eventEmitter.emit("disconnect");
|
|
13720
|
-
});
|
|
13721
|
-
this.phantom.solana.addEventListener("accountChanged", (publicKey) => {
|
|
13722
|
-
this._publicKey = publicKey;
|
|
13723
|
-
this.eventEmitter.emit("accountChanged", publicKey);
|
|
13724
|
-
});
|
|
13725
|
-
}
|
|
13726
|
-
// Event methods for interface compliance
|
|
13727
|
-
on(event, listener) {
|
|
13728
|
-
this.eventEmitter.on(event, listener);
|
|
13729
|
-
}
|
|
13730
|
-
off(event, listener) {
|
|
13731
|
-
this.eventEmitter.off(event, listener);
|
|
13732
|
-
}
|
|
13733
|
-
};
|
|
13734
|
-
var PhantomEthereumChain = class {
|
|
13735
|
-
constructor(phantom) {
|
|
13736
|
-
this._chainId = "0x1";
|
|
13737
|
-
this._accounts = [];
|
|
13738
|
-
this.eventEmitter = new EventEmitter4();
|
|
13739
|
-
this.phantom = phantom;
|
|
13740
|
-
this.setupEventListeners();
|
|
13741
|
-
}
|
|
13742
|
-
// EIP-1193 compliant properties
|
|
13743
|
-
get connected() {
|
|
13744
|
-
return this._accounts.length > 0;
|
|
13745
|
-
}
|
|
13746
|
-
get chainId() {
|
|
13747
|
-
return this._chainId;
|
|
13748
|
-
}
|
|
13749
|
-
get accounts() {
|
|
13750
|
-
return this._accounts;
|
|
13751
|
-
}
|
|
13752
|
-
// EIP-1193 core method with eth_signTransaction support
|
|
13753
|
-
async request(args) {
|
|
13754
|
-
if (args.method === "eth_signTransaction") {
|
|
13755
|
-
const [transaction] = args.params;
|
|
13756
|
-
const result = await this.signTransaction(transaction);
|
|
13757
|
-
return result;
|
|
13758
|
-
}
|
|
13759
|
-
const phantomProvider = await this.phantom.ethereum.getProvider();
|
|
13760
|
-
return await phantomProvider.request(args);
|
|
13761
|
-
}
|
|
13762
|
-
// Connection methods
|
|
13763
|
-
async connect() {
|
|
13764
|
-
const accounts = await this.phantom.ethereum.getAccounts();
|
|
13765
|
-
this._accounts = accounts;
|
|
13766
|
-
return accounts;
|
|
13767
|
-
}
|
|
13768
|
-
async disconnect() {
|
|
13769
|
-
await this.phantom.ethereum.disconnect();
|
|
13770
|
-
this._accounts = [];
|
|
13771
|
-
}
|
|
13772
|
-
// Standard compliant methods (return raw values, not wrapped objects)
|
|
13773
|
-
async signPersonalMessage(message, address) {
|
|
13774
|
-
return await this.phantom.ethereum.signPersonalMessage(message, address);
|
|
13775
|
-
}
|
|
13776
|
-
async signTypedData(typedData, address) {
|
|
13777
|
-
return await this.phantom.ethereum.signTypedData(typedData, address);
|
|
13778
|
-
}
|
|
13779
|
-
async signTransaction(transaction) {
|
|
13780
|
-
return await this.phantom.ethereum.signTransaction(transaction);
|
|
13781
|
-
}
|
|
13782
|
-
async sendTransaction(transaction) {
|
|
13783
|
-
return await this.phantom.ethereum.sendTransaction(transaction);
|
|
13784
|
-
}
|
|
13785
|
-
async switchChain(chainId) {
|
|
13786
|
-
const hexChainId = typeof chainId === "string" ? chainId.toLowerCase().startsWith("0x") ? chainId : `0x${parseInt(chainId, 10).toString(16)}` : `0x${chainId.toString(16)}`;
|
|
13787
|
-
await this.phantom.ethereum.switchChain(hexChainId);
|
|
13788
|
-
this._chainId = hexChainId;
|
|
13789
|
-
this.eventEmitter.emit("chainChanged", this._chainId);
|
|
13790
|
-
}
|
|
13791
|
-
async getChainId() {
|
|
13792
|
-
const chainId = await this.phantom.ethereum.getChainId();
|
|
13793
|
-
return parseInt(chainId, 16);
|
|
13794
|
-
}
|
|
13795
|
-
async getAccounts() {
|
|
13796
|
-
return await this.phantom.ethereum.getAccounts();
|
|
13797
|
-
}
|
|
13798
|
-
isConnected() {
|
|
13799
|
-
return this.connected;
|
|
13800
|
-
}
|
|
13801
|
-
setupEventListeners() {
|
|
13802
|
-
this.phantom.ethereum.addEventListener("connect", (accounts) => {
|
|
13803
|
-
this._accounts = accounts;
|
|
13804
|
-
this.eventEmitter.emit("connect", { chainId: this._chainId });
|
|
13805
|
-
this.eventEmitter.emit("accountsChanged", accounts);
|
|
13806
|
-
});
|
|
13807
|
-
this.phantom.ethereum.addEventListener("disconnect", () => {
|
|
13808
|
-
this._accounts = [];
|
|
13809
|
-
this.eventEmitter.emit("disconnect", { code: 4900, message: "Provider disconnected" });
|
|
13810
|
-
this.eventEmitter.emit("accountsChanged", []);
|
|
13811
|
-
});
|
|
13812
|
-
this.phantom.ethereum.addEventListener("accountsChanged", (accounts) => {
|
|
13813
|
-
this._accounts = accounts;
|
|
13814
|
-
this.eventEmitter.emit("accountsChanged", accounts);
|
|
13815
|
-
});
|
|
13816
|
-
this.phantom.ethereum.addEventListener("chainChanged", (chainId) => {
|
|
13817
|
-
this._chainId = chainId;
|
|
13818
|
-
this.eventEmitter.emit("chainChanged", chainId);
|
|
13819
|
-
});
|
|
11511
|
+
this._connected = accounts.length > 0;
|
|
11512
|
+
this.eventEmitter.emit("accountsChanged", accounts);
|
|
11513
|
+
});
|
|
11514
|
+
this.provider.on("chainChanged", (chainId) => {
|
|
11515
|
+
this._chainId = chainId;
|
|
11516
|
+
this.eventEmitter.emit("chainChanged", chainId);
|
|
11517
|
+
});
|
|
11518
|
+
}
|
|
13820
11519
|
}
|
|
13821
|
-
// Event methods for interface compliance
|
|
13822
11520
|
on(event, listener) {
|
|
13823
11521
|
this.eventEmitter.on(event, listener);
|
|
13824
11522
|
}
|
|
@@ -13831,6 +11529,9 @@ var PhantomEthereumChain = class {
|
|
|
13831
11529
|
function isPhantomWallet(wallet) {
|
|
13832
11530
|
return wallet !== void 0 && wallet.id === "phantom" && "isPhantom" in wallet && wallet.isPhantom === true;
|
|
13833
11531
|
}
|
|
11532
|
+
function isWalletStandardWallet(provider) {
|
|
11533
|
+
return provider !== null && typeof provider === "object" && "features" in provider && typeof provider.features === "object";
|
|
11534
|
+
}
|
|
13834
11535
|
var InjectedWalletRegistry = class {
|
|
13835
11536
|
constructor() {
|
|
13836
11537
|
this.wallets = /* @__PURE__ */ new Map();
|
|
@@ -13839,8 +11540,7 @@ var InjectedWalletRegistry = class {
|
|
|
13839
11540
|
register(info) {
|
|
13840
11541
|
const wrappedProviders = {};
|
|
13841
11542
|
if (info.providers?.solana) {
|
|
13842
|
-
|
|
13843
|
-
if (isWalletStandard) {
|
|
11543
|
+
if (isWalletStandardWallet(info.providers.solana)) {
|
|
13844
11544
|
wrappedProviders.solana = new WalletStandardSolanaAdapter(info.providers.solana, info.id, info.name);
|
|
13845
11545
|
debug.log(DebugCategory.BROWSER_SDK, "Wrapped Wallet Standard Solana wallet with adapter", {
|
|
13846
11546
|
walletId: info.id,
|
|
@@ -13870,18 +11570,19 @@ var InjectedWalletRegistry = class {
|
|
|
13870
11570
|
/**
|
|
13871
11571
|
* Register Phantom wallet with its instance
|
|
13872
11572
|
* This creates wrapped providers and stores the Phantom instance for auto-confirm access
|
|
11573
|
+
* Uses unified InjectedWallet chains for both Phantom and external wallets
|
|
13873
11574
|
*/
|
|
13874
11575
|
registerPhantom(phantomInstance, addressTypes) {
|
|
13875
11576
|
const wrappedProviders = {};
|
|
13876
11577
|
if (addressTypes.includes(DerivationInfoAddressFormatEnum.solana) && phantomInstance.solana) {
|
|
13877
|
-
wrappedProviders.solana = new
|
|
13878
|
-
debug.log(DebugCategory.BROWSER_SDK, "Created
|
|
11578
|
+
wrappedProviders.solana = new InjectedWalletSolanaChain(phantomInstance.solana, "phantom", "Phantom");
|
|
11579
|
+
debug.log(DebugCategory.BROWSER_SDK, "Created InjectedWalletSolanaChain wrapper for Phantom", {
|
|
13879
11580
|
walletId: "phantom"
|
|
13880
11581
|
});
|
|
13881
11582
|
}
|
|
13882
11583
|
if (addressTypes.includes(DerivationInfoAddressFormatEnum.ethereum) && phantomInstance.ethereum) {
|
|
13883
|
-
wrappedProviders.ethereum = new
|
|
13884
|
-
debug.log(DebugCategory.BROWSER_SDK, "Created
|
|
11584
|
+
wrappedProviders.ethereum = new InjectedWalletEthereumChain(phantomInstance.ethereum, "phantom", "Phantom");
|
|
11585
|
+
debug.log(DebugCategory.BROWSER_SDK, "Created InjectedWalletEthereumChain wrapper for Phantom", {
|
|
13885
11586
|
walletId: "phantom"
|
|
13886
11587
|
});
|
|
13887
11588
|
}
|
|
@@ -13966,15 +11667,16 @@ var WAS_CONNECTED_KEY = "phantom-injected-was-connected";
|
|
|
13966
11667
|
var WAS_CONNECTED_VALUE = "true";
|
|
13967
11668
|
var LAST_WALLET_ID_KEY = "phantom-injected-last-wallet-id";
|
|
13968
11669
|
var InjectedProvider = class {
|
|
13969
|
-
//
|
|
11670
|
+
// Store cleanups per walletId
|
|
13970
11671
|
constructor(config) {
|
|
13971
11672
|
this.selectedWalletId = null;
|
|
13972
11673
|
this.walletStates = /* @__PURE__ */ new Map();
|
|
13973
11674
|
// Event management
|
|
13974
11675
|
this.eventListeners = /* @__PURE__ */ new Map();
|
|
13975
|
-
this.browserInjectedCleanupFunctions = [];
|
|
13976
11676
|
this.eventsInitialized = false;
|
|
13977
|
-
this.
|
|
11677
|
+
this.eventListenersSetup = /* @__PURE__ */ new Set();
|
|
11678
|
+
// Track walletId that have listeners set up
|
|
11679
|
+
this.eventListenerCleanups = /* @__PURE__ */ new Map();
|
|
13978
11680
|
debug.log(DebugCategory.INJECTED_PROVIDER, "Initializing InjectedProvider", { config });
|
|
13979
11681
|
this.addressTypes = config.addressTypes;
|
|
13980
11682
|
this.walletRegistry = getWalletRegistry();
|
|
@@ -14005,9 +11707,12 @@ var InjectedProvider = class {
|
|
|
14005
11707
|
});
|
|
14006
11708
|
}
|
|
14007
11709
|
}
|
|
14008
|
-
|
|
14009
|
-
|
|
14010
|
-
|
|
11710
|
+
/**
|
|
11711
|
+
* Helper method to get a chain provider with consistent error handling
|
|
11712
|
+
*/
|
|
11713
|
+
getChainProvider(addressType, providerKey, chainName) {
|
|
11714
|
+
if (!this.addressTypes.includes(addressType)) {
|
|
11715
|
+
throw new Error(`${chainName} not enabled for this provider`);
|
|
14011
11716
|
}
|
|
14012
11717
|
const walletId = this.selectedWalletId || "phantom";
|
|
14013
11718
|
const walletInfo = this.walletRegistry.getById(walletId);
|
|
@@ -14022,39 +11727,22 @@ var InjectedProvider = class {
|
|
|
14022
11727
|
`Wallet "${walletId}" not found. Please ensure wallet discovery has completed. Make sure you call sdk.discoverWallets() and await it before accessing chain properties.`
|
|
14023
11728
|
);
|
|
14024
11729
|
}
|
|
14025
|
-
|
|
11730
|
+
const provider = walletInfo.providers?.[providerKey];
|
|
11731
|
+
if (!provider) {
|
|
14026
11732
|
throw new Error(
|
|
14027
|
-
`Selected wallet "${walletInfo.name}" does not support
|
|
11733
|
+
`Selected wallet "${walletInfo.name}" does not support ${chainName}. This wallet only supports: ${walletInfo.addressTypes.join(", ")}. Make sure your SDK config includes ${chainName} in addressTypes.`
|
|
14028
11734
|
);
|
|
14029
11735
|
}
|
|
14030
|
-
return
|
|
11736
|
+
return provider;
|
|
11737
|
+
}
|
|
11738
|
+
get solana() {
|
|
11739
|
+
return this.getChainProvider(DerivationInfoAddressFormatEnum.solana, "solana", "Solana");
|
|
14031
11740
|
}
|
|
14032
11741
|
/**
|
|
14033
11742
|
* Access to Ethereum chain operations
|
|
14034
11743
|
*/
|
|
14035
11744
|
get ethereum() {
|
|
14036
|
-
|
|
14037
|
-
throw new Error("Ethereum not enabled for this provider");
|
|
14038
|
-
}
|
|
14039
|
-
const walletId = this.selectedWalletId || "phantom";
|
|
14040
|
-
const walletInfo = this.walletRegistry.getById(walletId);
|
|
14041
|
-
if (!walletInfo) {
|
|
14042
|
-
const registry = this.walletRegistry;
|
|
14043
|
-
if (registry.discoveryPromise) {
|
|
14044
|
-
throw new Error(
|
|
14045
|
-
`Wallet "${walletId}" not found. Wallet discovery is still in progress. Please wait for sdk.discoverWallets() to complete before accessing chain properties.`
|
|
14046
|
-
);
|
|
14047
|
-
}
|
|
14048
|
-
throw new Error(
|
|
14049
|
-
`Wallet "${walletId}" not found. Please ensure wallet discovery has completed. Make sure you call sdk.discoverWallets() and await it before accessing chain properties.`
|
|
14050
|
-
);
|
|
14051
|
-
}
|
|
14052
|
-
if (!walletInfo.providers?.ethereum) {
|
|
14053
|
-
throw new Error(
|
|
14054
|
-
`Selected wallet "${walletInfo.name}" does not support Ethereum. This wallet only supports: ${walletInfo.addressTypes.join(", ")}. Make sure your SDK config includes Ethereum in addressTypes.`
|
|
14055
|
-
);
|
|
14056
|
-
}
|
|
14057
|
-
return walletInfo.providers.ethereum;
|
|
11745
|
+
return this.getChainProvider(DerivationInfoAddressFormatEnum.ethereum, "ethereum", "Ethereum");
|
|
14058
11746
|
}
|
|
14059
11747
|
validateAndSelectWallet(requestedWalletId) {
|
|
14060
11748
|
if (!this.walletRegistry.has(requestedWalletId)) {
|
|
@@ -14092,13 +11780,7 @@ var InjectedProvider = class {
|
|
|
14092
11780
|
options
|
|
14093
11781
|
});
|
|
14094
11782
|
if (!options?.skipEventListeners) {
|
|
14095
|
-
this.
|
|
14096
|
-
if (this.selectedWalletId === "phantom" && isPhantomWallet(walletInfo)) {
|
|
14097
|
-
this.browserInjectedCleanupFunctions.forEach((cleanup) => cleanup());
|
|
14098
|
-
this.browserInjectedCleanupFunctions = [];
|
|
14099
|
-
this.setupBrowserInjectedEvents();
|
|
14100
|
-
this.eventsInitialized = true;
|
|
14101
|
-
}
|
|
11783
|
+
this.setupEventListeners(walletInfo);
|
|
14102
11784
|
}
|
|
14103
11785
|
const connectedAddresses = [];
|
|
14104
11786
|
if (this.addressTypes.includes(DerivationInfoAddressFormatEnum.solana) && walletInfo.providers?.solana) {
|
|
@@ -14280,10 +11962,14 @@ var InjectedProvider = class {
|
|
|
14280
11962
|
}
|
|
14281
11963
|
}
|
|
14282
11964
|
}
|
|
14283
|
-
this.
|
|
14284
|
-
|
|
11965
|
+
const walletId = this.selectedWalletId || "phantom";
|
|
11966
|
+
const cleanups = this.eventListenerCleanups.get(walletId);
|
|
11967
|
+
if (cleanups) {
|
|
11968
|
+
cleanups.forEach((cleanup) => cleanup());
|
|
11969
|
+
this.eventListenerCleanups.delete(walletId);
|
|
11970
|
+
}
|
|
11971
|
+
this.eventListenersSetup.delete(walletId);
|
|
14285
11972
|
if (this.selectedWalletId) {
|
|
14286
|
-
this.externalWalletEventListenersSetup.delete(this.selectedWalletId);
|
|
14287
11973
|
this.setWalletState(this.selectedWalletId, {
|
|
14288
11974
|
connected: false,
|
|
14289
11975
|
addresses: []
|
|
@@ -14352,13 +12038,7 @@ var InjectedProvider = class {
|
|
|
14352
12038
|
});
|
|
14353
12039
|
return;
|
|
14354
12040
|
}
|
|
14355
|
-
this.
|
|
14356
|
-
if (this.selectedWalletId === "phantom" && isPhantomWallet(walletInfo)) {
|
|
14357
|
-
this.browserInjectedCleanupFunctions.forEach((cleanup) => cleanup());
|
|
14358
|
-
this.browserInjectedCleanupFunctions = [];
|
|
14359
|
-
this.setupBrowserInjectedEvents();
|
|
14360
|
-
this.eventsInitialized = true;
|
|
14361
|
-
}
|
|
12041
|
+
this.setupEventListeners(walletInfo);
|
|
14362
12042
|
if (this.selectedWalletId) {
|
|
14363
12043
|
this.setWalletState(this.selectedWalletId, {
|
|
14364
12044
|
connected: true,
|
|
@@ -14399,6 +12079,166 @@ var InjectedProvider = class {
|
|
|
14399
12079
|
setWalletState(walletId, state) {
|
|
14400
12080
|
this.walletStates.set(walletId, state);
|
|
14401
12081
|
}
|
|
12082
|
+
/**
|
|
12083
|
+
* Update wallet state with new addresses for a specific address type
|
|
12084
|
+
* Replaces all existing addresses of the given type with the new addresses
|
|
12085
|
+
* @param walletId - The wallet ID to update
|
|
12086
|
+
* @param newAddresses - Array of new addresses (strings) for the address type
|
|
12087
|
+
* @param addressType - The type of addresses being updated
|
|
12088
|
+
* @returns The updated addresses array
|
|
12089
|
+
*/
|
|
12090
|
+
updateWalletAddresses(walletId, newAddresses, addressType) {
|
|
12091
|
+
const state = this.getWalletState(walletId);
|
|
12092
|
+
const otherAddresses = state.addresses.filter((addr) => addr.addressType !== addressType);
|
|
12093
|
+
const addressesOfType = newAddresses.map((address) => ({ addressType, address }));
|
|
12094
|
+
const updatedAddresses = [...otherAddresses, ...addressesOfType];
|
|
12095
|
+
this.setWalletState(walletId, {
|
|
12096
|
+
connected: updatedAddresses.length > 0,
|
|
12097
|
+
addresses: updatedAddresses
|
|
12098
|
+
});
|
|
12099
|
+
return updatedAddresses;
|
|
12100
|
+
}
|
|
12101
|
+
/**
|
|
12102
|
+
* Helper to construct account change source string
|
|
12103
|
+
*/
|
|
12104
|
+
getAccountChangeSource(source) {
|
|
12105
|
+
return `${source}-account-change`;
|
|
12106
|
+
}
|
|
12107
|
+
/**
|
|
12108
|
+
* Create a handler for Solana connect events
|
|
12109
|
+
*/
|
|
12110
|
+
createSolanaConnectHandler(walletId, source) {
|
|
12111
|
+
return async (publicKey) => {
|
|
12112
|
+
debug.log(DebugCategory.INJECTED_PROVIDER, "Solana connect event received", { publicKey, walletId });
|
|
12113
|
+
const newAddresses = this.updateWalletAddresses(walletId, [publicKey], DerivationInfoAddressFormatEnum.solana);
|
|
12114
|
+
const authUserId = await this.getAuthUserId("Solana connect event");
|
|
12115
|
+
this.emit("connect", {
|
|
12116
|
+
addresses: newAddresses,
|
|
12117
|
+
source,
|
|
12118
|
+
authUserId
|
|
12119
|
+
});
|
|
12120
|
+
};
|
|
12121
|
+
}
|
|
12122
|
+
/**
|
|
12123
|
+
* Create a handler for Solana disconnect events
|
|
12124
|
+
*/
|
|
12125
|
+
createSolanaDisconnectHandler(walletId, source) {
|
|
12126
|
+
return () => {
|
|
12127
|
+
debug.log(DebugCategory.INJECTED_PROVIDER, "Solana disconnect event received", { walletId });
|
|
12128
|
+
const state = this.getWalletState(walletId);
|
|
12129
|
+
const filteredAddresses = state.addresses.filter((addr) => addr.addressType !== DerivationInfoAddressFormatEnum.solana);
|
|
12130
|
+
this.setWalletState(walletId, {
|
|
12131
|
+
connected: filteredAddresses.length > 0,
|
|
12132
|
+
addresses: filteredAddresses
|
|
12133
|
+
});
|
|
12134
|
+
this.emit("disconnect", {
|
|
12135
|
+
source
|
|
12136
|
+
});
|
|
12137
|
+
};
|
|
12138
|
+
}
|
|
12139
|
+
/**
|
|
12140
|
+
* Create a handler for Solana account change events
|
|
12141
|
+
* Can receive string | null per Wallet Standard
|
|
12142
|
+
*/
|
|
12143
|
+
createSolanaAccountChangeHandler(walletId, source) {
|
|
12144
|
+
return async (publicKey) => {
|
|
12145
|
+
debug.log(DebugCategory.INJECTED_PROVIDER, "Solana account changed event received", { publicKey, walletId });
|
|
12146
|
+
if (publicKey) {
|
|
12147
|
+
const newAddresses = this.updateWalletAddresses(walletId, [publicKey], DerivationInfoAddressFormatEnum.solana);
|
|
12148
|
+
const authUserId = await this.getAuthUserId("Solana account changed event");
|
|
12149
|
+
this.emit("connect", {
|
|
12150
|
+
addresses: newAddresses,
|
|
12151
|
+
source: this.getAccountChangeSource(source),
|
|
12152
|
+
authUserId
|
|
12153
|
+
});
|
|
12154
|
+
} else {
|
|
12155
|
+
const state = this.getWalletState(walletId);
|
|
12156
|
+
const otherAddresses = state.addresses.filter((addr) => addr.addressType !== DerivationInfoAddressFormatEnum.solana);
|
|
12157
|
+
this.setWalletState(walletId, {
|
|
12158
|
+
connected: otherAddresses.length > 0,
|
|
12159
|
+
addresses: otherAddresses
|
|
12160
|
+
});
|
|
12161
|
+
this.emit("disconnect", {
|
|
12162
|
+
source: this.getAccountChangeSource(source)
|
|
12163
|
+
});
|
|
12164
|
+
}
|
|
12165
|
+
};
|
|
12166
|
+
}
|
|
12167
|
+
/**
|
|
12168
|
+
* Create a handler for Ethereum connect events
|
|
12169
|
+
* EIP-1193 connect event receives { chainId: string }, but we need to get accounts separately
|
|
12170
|
+
*/
|
|
12171
|
+
createEthereumConnectHandler(walletId, source) {
|
|
12172
|
+
return async (connectInfo) => {
|
|
12173
|
+
let accounts = [];
|
|
12174
|
+
if (Array.isArray(connectInfo)) {
|
|
12175
|
+
accounts = connectInfo;
|
|
12176
|
+
} else {
|
|
12177
|
+
try {
|
|
12178
|
+
const walletInfo = this.walletRegistry.getById(walletId);
|
|
12179
|
+
if (walletInfo?.providers?.ethereum) {
|
|
12180
|
+
accounts = await walletInfo.providers.ethereum.getAccounts();
|
|
12181
|
+
}
|
|
12182
|
+
} catch (error) {
|
|
12183
|
+
debug.warn(DebugCategory.INJECTED_PROVIDER, "Failed to get accounts on connect", { error });
|
|
12184
|
+
}
|
|
12185
|
+
}
|
|
12186
|
+
debug.log(DebugCategory.INJECTED_PROVIDER, "Ethereum connect event received", { accounts, walletId });
|
|
12187
|
+
if (accounts.length > 0) {
|
|
12188
|
+
const newAddresses = this.updateWalletAddresses(walletId, accounts, DerivationInfoAddressFormatEnum.ethereum);
|
|
12189
|
+
const authUserId = await this.getAuthUserId("Ethereum connect event");
|
|
12190
|
+
this.emit("connect", {
|
|
12191
|
+
addresses: newAddresses,
|
|
12192
|
+
source,
|
|
12193
|
+
authUserId
|
|
12194
|
+
});
|
|
12195
|
+
}
|
|
12196
|
+
};
|
|
12197
|
+
}
|
|
12198
|
+
/**
|
|
12199
|
+
* Create a handler for Ethereum disconnect events
|
|
12200
|
+
*/
|
|
12201
|
+
createEthereumDisconnectHandler(walletId, source) {
|
|
12202
|
+
return () => {
|
|
12203
|
+
debug.log(DebugCategory.INJECTED_PROVIDER, "Ethereum disconnect event received", { walletId });
|
|
12204
|
+
const state = this.getWalletState(walletId);
|
|
12205
|
+
const filteredAddresses = state.addresses.filter((addr) => addr.addressType !== DerivationInfoAddressFormatEnum.ethereum);
|
|
12206
|
+
this.setWalletState(walletId, {
|
|
12207
|
+
connected: filteredAddresses.length > 0,
|
|
12208
|
+
addresses: filteredAddresses
|
|
12209
|
+
});
|
|
12210
|
+
this.emit("disconnect", {
|
|
12211
|
+
source
|
|
12212
|
+
});
|
|
12213
|
+
};
|
|
12214
|
+
}
|
|
12215
|
+
/**
|
|
12216
|
+
* Create a handler for Ethereum account change events
|
|
12217
|
+
*/
|
|
12218
|
+
createEthereumAccountChangeHandler(walletId, source) {
|
|
12219
|
+
return async (accounts) => {
|
|
12220
|
+
debug.log(DebugCategory.INJECTED_PROVIDER, "Ethereum accounts changed event received", { accounts, walletId });
|
|
12221
|
+
if (accounts && accounts.length > 0) {
|
|
12222
|
+
const newAddresses = this.updateWalletAddresses(walletId, accounts, DerivationInfoAddressFormatEnum.ethereum);
|
|
12223
|
+
const authUserId = await this.getAuthUserId("Ethereum accounts changed event");
|
|
12224
|
+
this.emit("connect", {
|
|
12225
|
+
addresses: newAddresses,
|
|
12226
|
+
source: this.getAccountChangeSource(source),
|
|
12227
|
+
authUserId
|
|
12228
|
+
});
|
|
12229
|
+
} else {
|
|
12230
|
+
const state = this.getWalletState(walletId);
|
|
12231
|
+
const otherAddresses = state.addresses.filter((addr) => addr.addressType !== DerivationInfoAddressFormatEnum.ethereum);
|
|
12232
|
+
this.setWalletState(walletId, {
|
|
12233
|
+
connected: otherAddresses.length > 0,
|
|
12234
|
+
addresses: otherAddresses
|
|
12235
|
+
});
|
|
12236
|
+
this.emit("disconnect", {
|
|
12237
|
+
source: this.getAccountChangeSource(source)
|
|
12238
|
+
});
|
|
12239
|
+
}
|
|
12240
|
+
};
|
|
12241
|
+
}
|
|
14402
12242
|
getAddresses() {
|
|
14403
12243
|
const walletId = this.selectedWalletId || "phantom";
|
|
14404
12244
|
return this.getWalletState(walletId).addresses;
|
|
@@ -14492,19 +12332,22 @@ var InjectedProvider = class {
|
|
|
14492
12332
|
on(event, callback) {
|
|
14493
12333
|
debug.log(DebugCategory.INJECTED_PROVIDER, "Adding event listener", { event });
|
|
14494
12334
|
if (!this.eventsInitialized) {
|
|
14495
|
-
this.
|
|
14496
|
-
|
|
12335
|
+
const walletId = this.selectedWalletId || "phantom";
|
|
12336
|
+
const walletInfo = this.walletRegistry.getById(walletId);
|
|
12337
|
+
if (walletInfo) {
|
|
12338
|
+
this.setupEventListeners(walletInfo);
|
|
12339
|
+
}
|
|
14497
12340
|
}
|
|
14498
12341
|
if (!this.eventListeners.has(event)) {
|
|
14499
12342
|
this.eventListeners.set(event, /* @__PURE__ */ new Set());
|
|
14500
12343
|
}
|
|
14501
|
-
this.eventListeners.get(event)
|
|
12344
|
+
this.eventListeners.get(event)?.add(callback);
|
|
14502
12345
|
}
|
|
14503
12346
|
off(event, callback) {
|
|
14504
12347
|
debug.log(DebugCategory.INJECTED_PROVIDER, "Removing event listener", { event });
|
|
14505
12348
|
if (this.eventListeners.has(event)) {
|
|
14506
|
-
this.eventListeners.get(event)
|
|
14507
|
-
if (this.eventListeners.get(event)
|
|
12349
|
+
this.eventListeners.get(event)?.delete(callback);
|
|
12350
|
+
if (this.eventListeners.get(event)?.size === 0) {
|
|
14508
12351
|
this.eventListeners.delete(event);
|
|
14509
12352
|
}
|
|
14510
12353
|
}
|
|
@@ -14526,246 +12369,76 @@ var InjectedProvider = class {
|
|
|
14526
12369
|
});
|
|
14527
12370
|
}
|
|
14528
12371
|
}
|
|
14529
|
-
|
|
14530
|
-
|
|
14531
|
-
|
|
14532
|
-
|
|
12372
|
+
/**
|
|
12373
|
+
* Set up Solana event listeners for any provider (Phantom or external)
|
|
12374
|
+
*/
|
|
12375
|
+
setupSolanaEventListeners(provider, walletId, source) {
|
|
12376
|
+
if (typeof provider.on !== "function")
|
|
14533
12377
|
return;
|
|
14534
|
-
}
|
|
14535
|
-
|
|
14536
|
-
|
|
14537
|
-
|
|
14538
|
-
|
|
14539
|
-
}
|
|
14540
|
-
if (this.addressTypes.includes(DerivationInfoAddressFormatEnum.ethereum)) {
|
|
14541
|
-
this.setupEthereumEvents(walletInfo.phantomInstance);
|
|
14542
|
-
}
|
|
14543
|
-
}
|
|
14544
|
-
}
|
|
14545
|
-
setupSolanaEvents(phantom) {
|
|
14546
|
-
debug.log(DebugCategory.INJECTED_PROVIDER, "Setting up Solana event listeners");
|
|
14547
|
-
const handleSolanaConnect = async (publicKey) => {
|
|
14548
|
-
debug.log(DebugCategory.INJECTED_PROVIDER, "Solana connect event received", { publicKey });
|
|
14549
|
-
const walletId = this.selectedWalletId || "phantom";
|
|
14550
|
-
const state = this.getWalletState(walletId);
|
|
14551
|
-
const solanaAddress = { addressType: DerivationInfoAddressFormatEnum.solana, address: publicKey };
|
|
14552
|
-
const hasSolana = state.addresses.some((addr) => addr.addressType === DerivationInfoAddressFormatEnum.solana);
|
|
14553
|
-
const newAddresses = hasSolana ? state.addresses.map((addr) => addr.addressType === DerivationInfoAddressFormatEnum.solana ? solanaAddress : addr) : [...state.addresses, solanaAddress];
|
|
14554
|
-
this.setWalletState(walletId, {
|
|
14555
|
-
connected: true,
|
|
14556
|
-
addresses: newAddresses
|
|
14557
|
-
});
|
|
14558
|
-
const authUserId = await this.getAuthUserId("Solana connect event");
|
|
14559
|
-
this.emit("connect", {
|
|
14560
|
-
addresses: newAddresses,
|
|
14561
|
-
source: "injected-extension",
|
|
14562
|
-
authUserId
|
|
14563
|
-
});
|
|
14564
|
-
};
|
|
14565
|
-
const handleSolanaDisconnect = () => {
|
|
14566
|
-
debug.log(DebugCategory.INJECTED_PROVIDER, "Solana disconnect event received");
|
|
14567
|
-
const walletId = this.selectedWalletId || "phantom";
|
|
14568
|
-
const state = this.getWalletState(walletId);
|
|
14569
|
-
const filteredAddresses = state.addresses.filter((addr) => addr.addressType !== DerivationInfoAddressFormatEnum.solana);
|
|
14570
|
-
this.setWalletState(walletId, {
|
|
14571
|
-
connected: filteredAddresses.length > 0,
|
|
14572
|
-
addresses: filteredAddresses
|
|
14573
|
-
});
|
|
14574
|
-
this.emit("disconnect", {
|
|
14575
|
-
source: "injected-extension"
|
|
14576
|
-
});
|
|
14577
|
-
};
|
|
14578
|
-
const handleSolanaAccountChanged = async (publicKey) => {
|
|
14579
|
-
debug.log(DebugCategory.INJECTED_PROVIDER, "Solana account changed event received", { publicKey });
|
|
14580
|
-
const walletId = this.selectedWalletId || "phantom";
|
|
14581
|
-
const state = this.getWalletState(walletId);
|
|
14582
|
-
const solanaIndex = state.addresses.findIndex((addr) => addr.addressType === DerivationInfoAddressFormatEnum.solana);
|
|
14583
|
-
const newAddresses = solanaIndex >= 0 ? state.addresses.map(
|
|
14584
|
-
(addr, idx) => idx === solanaIndex ? { addressType: DerivationInfoAddressFormatEnum.solana, address: publicKey } : addr
|
|
14585
|
-
) : [...state.addresses, { addressType: DerivationInfoAddressFormatEnum.solana, address: publicKey }];
|
|
14586
|
-
this.setWalletState(walletId, {
|
|
14587
|
-
connected: true,
|
|
14588
|
-
addresses: newAddresses
|
|
14589
|
-
});
|
|
14590
|
-
const authUserId = await this.getAuthUserId("Solana account changed event");
|
|
14591
|
-
this.emit("connect", {
|
|
14592
|
-
addresses: newAddresses,
|
|
14593
|
-
source: "injected-extension-account-change",
|
|
14594
|
-
authUserId
|
|
14595
|
-
});
|
|
14596
|
-
};
|
|
14597
|
-
const cleanupConnect = phantom.solana.addEventListener("connect", handleSolanaConnect);
|
|
14598
|
-
const cleanupDisconnect = phantom.solana.addEventListener("disconnect", handleSolanaDisconnect);
|
|
14599
|
-
const cleanupAccountChanged = phantom.solana.addEventListener("accountChanged", handleSolanaAccountChanged);
|
|
14600
|
-
this.browserInjectedCleanupFunctions.push(cleanupConnect, cleanupDisconnect, cleanupAccountChanged);
|
|
14601
|
-
}
|
|
14602
|
-
setupEthereumEvents(phantom) {
|
|
14603
|
-
debug.log(DebugCategory.INJECTED_PROVIDER, "Setting up Ethereum event listeners");
|
|
14604
|
-
const handleEthereumConnect = async (accounts) => {
|
|
14605
|
-
debug.log(DebugCategory.INJECTED_PROVIDER, "Ethereum connect event received", { accounts });
|
|
14606
|
-
const walletId = this.selectedWalletId || "phantom";
|
|
14607
|
-
const state = this.getWalletState(walletId);
|
|
14608
|
-
const ethAddresses = accounts.map((address) => ({ addressType: DerivationInfoAddressFormatEnum.ethereum, address }));
|
|
14609
|
-
const otherAddresses = state.addresses.filter((addr) => addr.addressType !== DerivationInfoAddressFormatEnum.ethereum);
|
|
14610
|
-
const newAddresses = [...otherAddresses, ...ethAddresses];
|
|
14611
|
-
this.setWalletState(walletId, {
|
|
14612
|
-
connected: true,
|
|
14613
|
-
addresses: newAddresses
|
|
14614
|
-
});
|
|
14615
|
-
const authUserId = await this.getAuthUserId("Ethereum connect event");
|
|
14616
|
-
this.emit("connect", {
|
|
14617
|
-
addresses: newAddresses,
|
|
14618
|
-
source: "injected-extension",
|
|
14619
|
-
authUserId
|
|
14620
|
-
});
|
|
14621
|
-
};
|
|
14622
|
-
const handleEthereumDisconnect = () => {
|
|
14623
|
-
debug.log(DebugCategory.INJECTED_PROVIDER, "Ethereum disconnect event received");
|
|
14624
|
-
const walletId = this.selectedWalletId || "phantom";
|
|
14625
|
-
const state = this.getWalletState(walletId);
|
|
14626
|
-
const filteredAddresses = state.addresses.filter((addr) => addr.addressType !== DerivationInfoAddressFormatEnum.ethereum);
|
|
14627
|
-
this.setWalletState(walletId, {
|
|
14628
|
-
connected: filteredAddresses.length > 0,
|
|
14629
|
-
addresses: filteredAddresses
|
|
14630
|
-
});
|
|
14631
|
-
this.emit("disconnect", {
|
|
14632
|
-
source: "injected-extension"
|
|
14633
|
-
});
|
|
12378
|
+
debug.log(DebugCategory.INJECTED_PROVIDER, "Setting up Solana event listeners", { walletId, source });
|
|
12379
|
+
const handlers = {
|
|
12380
|
+
connect: this.createSolanaConnectHandler(walletId, source),
|
|
12381
|
+
disconnect: this.createSolanaDisconnectHandler(walletId, source),
|
|
12382
|
+
accountChanged: this.createSolanaAccountChangeHandler(walletId, source)
|
|
14634
12383
|
};
|
|
14635
|
-
|
|
14636
|
-
|
|
14637
|
-
|
|
14638
|
-
|
|
14639
|
-
|
|
14640
|
-
|
|
14641
|
-
|
|
14642
|
-
|
|
14643
|
-
|
|
14644
|
-
|
|
14645
|
-
|
|
14646
|
-
|
|
14647
|
-
|
|
14648
|
-
this.emit("connect", {
|
|
14649
|
-
addresses: newAddresses,
|
|
14650
|
-
source: "injected-extension-account-change",
|
|
14651
|
-
authUserId
|
|
14652
|
-
});
|
|
14653
|
-
} else {
|
|
14654
|
-
this.setWalletState(walletId, {
|
|
14655
|
-
connected: otherAddresses.length > 0,
|
|
14656
|
-
addresses: otherAddresses
|
|
14657
|
-
});
|
|
14658
|
-
this.emit("disconnect", {
|
|
14659
|
-
source: "injected-extension-account-change"
|
|
14660
|
-
});
|
|
14661
|
-
}
|
|
14662
|
-
};
|
|
14663
|
-
const cleanupConnect = phantom.ethereum.addEventListener("connect", handleEthereumConnect);
|
|
14664
|
-
const cleanupDisconnect = phantom.ethereum.addEventListener("disconnect", handleEthereumDisconnect);
|
|
14665
|
-
const cleanupAccountsChanged = phantom.ethereum.addEventListener("accountsChanged", handleEthereumAccountsChanged);
|
|
14666
|
-
this.browserInjectedCleanupFunctions.push(cleanupConnect, cleanupDisconnect, cleanupAccountsChanged);
|
|
12384
|
+
provider.on("connect", handlers.connect);
|
|
12385
|
+
provider.on("disconnect", handlers.disconnect);
|
|
12386
|
+
provider.on("accountChanged", handlers.accountChanged);
|
|
12387
|
+
const cleanups = [];
|
|
12388
|
+
if (typeof provider.off === "function") {
|
|
12389
|
+
cleanups.push(
|
|
12390
|
+
() => provider.off("connect", handlers.connect),
|
|
12391
|
+
() => provider.off("disconnect", handlers.disconnect),
|
|
12392
|
+
() => provider.off("accountChanged", handlers.accountChanged)
|
|
12393
|
+
);
|
|
12394
|
+
}
|
|
12395
|
+
const existingCleanups = this.eventListenerCleanups.get(walletId) || [];
|
|
12396
|
+
this.eventListenerCleanups.set(walletId, [...existingCleanups, ...cleanups]);
|
|
14667
12397
|
}
|
|
14668
|
-
|
|
14669
|
-
|
|
12398
|
+
/**
|
|
12399
|
+
* Set up Ethereum event listeners for any provider (Phantom or external)
|
|
12400
|
+
*/
|
|
12401
|
+
setupEthereumEventListeners(provider, walletId, source) {
|
|
12402
|
+
if (typeof provider.on !== "function")
|
|
14670
12403
|
return;
|
|
12404
|
+
debug.log(DebugCategory.INJECTED_PROVIDER, "Setting up Ethereum event listeners", { walletId, source });
|
|
12405
|
+
const handlers = {
|
|
12406
|
+
connect: this.createEthereumConnectHandler(walletId, source),
|
|
12407
|
+
disconnect: this.createEthereumDisconnectHandler(walletId, source),
|
|
12408
|
+
accountsChanged: this.createEthereumAccountChangeHandler(walletId, source)
|
|
12409
|
+
};
|
|
12410
|
+
provider.on("connect", handlers.connect);
|
|
12411
|
+
provider.on("disconnect", handlers.disconnect);
|
|
12412
|
+
provider.on("accountsChanged", handlers.accountsChanged);
|
|
12413
|
+
const cleanups = [];
|
|
12414
|
+
if (typeof provider.off === "function") {
|
|
12415
|
+
cleanups.push(
|
|
12416
|
+
() => provider.off("connect", handlers.connect),
|
|
12417
|
+
() => provider.off("disconnect", handlers.disconnect),
|
|
12418
|
+
() => provider.off("accountsChanged", handlers.accountsChanged)
|
|
12419
|
+
);
|
|
14671
12420
|
}
|
|
14672
|
-
|
|
12421
|
+
const existingCleanups = this.eventListenerCleanups.get(walletId) || [];
|
|
12422
|
+
this.eventListenerCleanups.set(walletId, [...existingCleanups, ...cleanups]);
|
|
12423
|
+
}
|
|
12424
|
+
/**
|
|
12425
|
+
* Unified event listener setup for all wallet types (Phantom and external)
|
|
12426
|
+
*/
|
|
12427
|
+
setupEventListeners(walletInfo) {
|
|
12428
|
+
const walletId = this.selectedWalletId || "phantom";
|
|
12429
|
+
if (this.eventListenersSetup.has(walletId)) {
|
|
12430
|
+
debug.log(DebugCategory.INJECTED_PROVIDER, "Event listeners already set up for wallet", { walletId });
|
|
14673
12431
|
return;
|
|
14674
12432
|
}
|
|
14675
|
-
debug.log(DebugCategory.INJECTED_PROVIDER, "Setting up
|
|
14676
|
-
|
|
14677
|
-
|
|
14678
|
-
if (walletInfo.providers?.ethereum) {
|
|
14679
|
-
const handleExternalEthereumAccountsChanged = async (accounts) => {
|
|
14680
|
-
debug.log(DebugCategory.INJECTED_PROVIDER, "External wallet Ethereum accounts changed event received", {
|
|
14681
|
-
walletId: this.selectedWalletId,
|
|
14682
|
-
accounts
|
|
14683
|
-
});
|
|
14684
|
-
const walletId = this.selectedWalletId;
|
|
14685
|
-
const state = this.getWalletState(walletId);
|
|
14686
|
-
const otherAddresses = state.addresses.filter((addr) => addr.addressType !== DerivationInfoAddressFormatEnum.ethereum);
|
|
14687
|
-
if (accounts && accounts.length > 0) {
|
|
14688
|
-
const ethAddresses = accounts.map((address) => ({ addressType: DerivationInfoAddressFormatEnum.ethereum, address }));
|
|
14689
|
-
const newAddresses = [...otherAddresses, ...ethAddresses];
|
|
14690
|
-
this.setWalletState(walletId, {
|
|
14691
|
-
connected: true,
|
|
14692
|
-
addresses: newAddresses
|
|
14693
|
-
});
|
|
14694
|
-
debug.log(DebugCategory.INJECTED_PROVIDER, "Updated Ethereum addresses after account change", {
|
|
14695
|
-
walletId,
|
|
14696
|
-
oldCount: 0,
|
|
14697
|
-
// We filtered them out
|
|
14698
|
-
newCount: accounts.length,
|
|
14699
|
-
addresses: newAddresses.filter((addr) => addr.addressType === DerivationInfoAddressFormatEnum.ethereum)
|
|
14700
|
-
});
|
|
14701
|
-
const authUserId = await this.getAuthUserId("External wallet Ethereum accounts changed event");
|
|
14702
|
-
this.emit("connect", {
|
|
14703
|
-
addresses: newAddresses,
|
|
14704
|
-
source: "external-wallet-account-change",
|
|
14705
|
-
authUserId
|
|
14706
|
-
});
|
|
14707
|
-
} else {
|
|
14708
|
-
this.setWalletState(walletId, {
|
|
14709
|
-
connected: otherAddresses.length > 0,
|
|
14710
|
-
addresses: otherAddresses
|
|
14711
|
-
});
|
|
14712
|
-
this.emit("disconnect", {
|
|
14713
|
-
source: "external-wallet-account-change"
|
|
14714
|
-
});
|
|
14715
|
-
}
|
|
14716
|
-
};
|
|
14717
|
-
if (typeof walletInfo.providers.ethereum.on === "function") {
|
|
14718
|
-
walletInfo.providers.ethereum.on("accountsChanged", handleExternalEthereumAccountsChanged);
|
|
14719
|
-
this.browserInjectedCleanupFunctions.push(() => {
|
|
14720
|
-
if (typeof walletInfo.providers?.ethereum?.off === "function") {
|
|
14721
|
-
walletInfo.providers.ethereum.off("accountsChanged", handleExternalEthereumAccountsChanged);
|
|
14722
|
-
}
|
|
14723
|
-
});
|
|
14724
|
-
}
|
|
14725
|
-
}
|
|
14726
|
-
if (walletInfo.providers?.solana) {
|
|
14727
|
-
const handleExternalSolanaAccountChanged = async (publicKey) => {
|
|
14728
|
-
debug.log(DebugCategory.INJECTED_PROVIDER, "External wallet Solana account changed event received", {
|
|
14729
|
-
walletId: this.selectedWalletId,
|
|
14730
|
-
publicKey
|
|
14731
|
-
});
|
|
14732
|
-
const walletId = this.selectedWalletId;
|
|
14733
|
-
const state = this.getWalletState(walletId);
|
|
14734
|
-
const otherAddresses = state.addresses.filter((addr) => addr.addressType !== DerivationInfoAddressFormatEnum.solana);
|
|
14735
|
-
if (publicKey) {
|
|
14736
|
-
const newAddresses = [...otherAddresses, { addressType: DerivationInfoAddressFormatEnum.solana, address: publicKey }];
|
|
14737
|
-
this.setWalletState(walletId, {
|
|
14738
|
-
connected: true,
|
|
14739
|
-
addresses: newAddresses
|
|
14740
|
-
});
|
|
14741
|
-
const authUserId = await this.getAuthUserId("External wallet Solana account changed event");
|
|
14742
|
-
this.emit("connect", {
|
|
14743
|
-
addresses: newAddresses,
|
|
14744
|
-
source: "external-wallet-account-change",
|
|
14745
|
-
authUserId
|
|
14746
|
-
});
|
|
14747
|
-
} else {
|
|
14748
|
-
this.setWalletState(walletId, {
|
|
14749
|
-
connected: otherAddresses.length > 0,
|
|
14750
|
-
addresses: otherAddresses
|
|
14751
|
-
});
|
|
14752
|
-
this.emit("disconnect", {
|
|
14753
|
-
source: "external-wallet-account-change"
|
|
14754
|
-
});
|
|
14755
|
-
}
|
|
14756
|
-
};
|
|
14757
|
-
if (typeof walletInfo.providers.solana.on === "function") {
|
|
14758
|
-
walletInfo.providers.solana.on("accountChanged", handleExternalSolanaAccountChanged);
|
|
14759
|
-
this.browserInjectedCleanupFunctions.push(() => {
|
|
14760
|
-
if (typeof walletInfo.providers?.solana?.off === "function") {
|
|
14761
|
-
walletInfo.providers.solana.off("accountChanged", handleExternalSolanaAccountChanged);
|
|
14762
|
-
}
|
|
14763
|
-
});
|
|
14764
|
-
}
|
|
12433
|
+
debug.log(DebugCategory.INJECTED_PROVIDER, "Setting up event listeners", { walletId });
|
|
12434
|
+
if (this.addressTypes.includes(DerivationInfoAddressFormatEnum.solana) && walletInfo.providers?.solana) {
|
|
12435
|
+
this.setupSolanaEventListeners(walletInfo.providers.solana, walletId, "wallet");
|
|
14765
12436
|
}
|
|
14766
|
-
if (this.
|
|
14767
|
-
this.
|
|
12437
|
+
if (this.addressTypes.includes(DerivationInfoAddressFormatEnum.ethereum) && walletInfo.providers?.ethereum) {
|
|
12438
|
+
this.setupEthereumEventListeners(walletInfo.providers.ethereum, walletId, "wallet");
|
|
14768
12439
|
}
|
|
12440
|
+
this.eventListenersSetup.add(walletId);
|
|
12441
|
+
this.eventsInitialized = true;
|
|
14769
12442
|
}
|
|
14770
12443
|
};
|
|
14771
12444
|
|
|
@@ -15067,7 +12740,7 @@ var BrowserAuthProvider = class {
|
|
|
15067
12740
|
// OAuth session management - defaults to allow refresh unless explicitly clearing after logout
|
|
15068
12741
|
clear_previous_session: (phantomOptions.clearPreviousSession ?? false).toString(),
|
|
15069
12742
|
allow_refresh: (phantomOptions.allowRefresh ?? true).toString(),
|
|
15070
|
-
sdk_version: "1.0.
|
|
12743
|
+
sdk_version: "1.0.2",
|
|
15071
12744
|
sdk_type: "browser",
|
|
15072
12745
|
platform: detectBrowser().name
|
|
15073
12746
|
});
|
|
@@ -15322,7 +12995,7 @@ var EmbeddedProvider = class extends EmbeddedProvider$1 {
|
|
|
15322
12995
|
// Full user agent for more detailed info
|
|
15323
12996
|
[ANALYTICS_HEADERS.APP_ID]: config.appId,
|
|
15324
12997
|
[ANALYTICS_HEADERS.WALLET_TYPE]: config.embeddedWalletType,
|
|
15325
|
-
[ANALYTICS_HEADERS.SDK_VERSION]: "1.0.
|
|
12998
|
+
[ANALYTICS_HEADERS.SDK_VERSION]: "1.0.2"
|
|
15326
12999
|
// Replaced at build time
|
|
15327
13000
|
}
|
|
15328
13001
|
};
|
|
@@ -15601,7 +13274,7 @@ var ProviderManager = class {
|
|
|
15601
13274
|
if (!this.eventListeners.has(event)) {
|
|
15602
13275
|
this.eventListeners.set(event, /* @__PURE__ */ new Set());
|
|
15603
13276
|
}
|
|
15604
|
-
this.eventListeners.get(event)
|
|
13277
|
+
this.eventListeners.get(event)?.add(callback);
|
|
15605
13278
|
this.ensureProviderEventForwarding();
|
|
15606
13279
|
}
|
|
15607
13280
|
/**
|
|
@@ -15610,8 +13283,8 @@ var ProviderManager = class {
|
|
|
15610
13283
|
off(event, callback) {
|
|
15611
13284
|
debug.log(DebugCategory.PROVIDER_MANAGER, "Removing event listener", { event });
|
|
15612
13285
|
if (this.eventListeners.has(event)) {
|
|
15613
|
-
this.eventListeners.get(event)
|
|
15614
|
-
if (this.eventListeners.get(event)
|
|
13286
|
+
this.eventListeners.get(event)?.delete(callback);
|
|
13287
|
+
if (this.eventListeners.get(event)?.size === 0) {
|
|
15615
13288
|
this.eventListeners.delete(event);
|
|
15616
13289
|
}
|
|
15617
13290
|
}
|
|
@@ -16868,7 +14541,8 @@ function ConnectModalContent({
|
|
|
16868
14541
|
const isConnectingState = baseConnect.isConnecting || isConnecting;
|
|
16869
14542
|
const errorState = baseConnect.error ? baseConnect.error.message : error;
|
|
16870
14543
|
const showDivider = !(allowedProviders.length === 1 && allowedProviders.includes("injected"));
|
|
16871
|
-
const
|
|
14544
|
+
const isInjectedOnly = allowedProviders.length === 1 && allowedProviders.includes("injected");
|
|
14545
|
+
const shouldShowOtherWalletsButton = !isInjectedOnly && discoveredWallets.length > 2;
|
|
16872
14546
|
const walletsToShowInline = shouldShowOtherWalletsButton ? [] : discoveredWallets;
|
|
16873
14547
|
const connectWithAuthProvider = useCallback(
|
|
16874
14548
|
async (provider, walletId) => {
|
|
@@ -17137,7 +14811,7 @@ function ConnectModalContent({
|
|
|
17137
14811
|
] })
|
|
17138
14812
|
}
|
|
17139
14813
|
),
|
|
17140
|
-
allowedProviders.includes("injected") && (isExtensionInstalled.isInstalled || discoveredWallets.length > 0) &&
|
|
14814
|
+
allowedProviders.includes("injected") && (isExtensionInstalled.isInstalled || discoveredWallets.length > 0) && /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
17141
14815
|
showDivider && /* @__PURE__ */ jsxs("div", { style: dividerStyle, children: [
|
|
17142
14816
|
/* @__PURE__ */ jsx("div", { style: dividerLineStyle }),
|
|
17143
14817
|
/* @__PURE__ */ jsx("span", { style: dividerTextStyle, children: "OR" }),
|
|
@@ -17695,4 +15369,4 @@ function ConnectBox({ maxWidth = "350px", transparent = false, appIcon, appName
|
|
|
17695
15369
|
}
|
|
17696
15370
|
|
|
17697
15371
|
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 };
|
|
17698
|
-
//# sourceMappingURL=index-
|
|
15372
|
+
//# sourceMappingURL=index-B1INQP2H.esm.js.map
|