near-api-js 0.43.0 → 0.44.2
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/near-api-js.js +75 -32
- package/dist/near-api-js.min.js +14 -14
- package/lib/account.d.ts +1 -0
- package/lib/account.js +2 -2
- package/lib/connection.js +1 -1
- package/lib/key_stores/unencrypted_file_system_keystore.js +1 -1
- package/lib/near.d.ts +7 -0
- package/lib/near.js +1 -1
- package/lib/providers/json-rpc-provider.d.ts +2 -2
- package/lib/providers/json-rpc-provider.js +14 -5
- package/lib/utils/errors.js +1 -1
- package/lib/utils/key_pair.d.ts +1 -0
- package/lib/utils/key_pair.js +7 -1
- package/lib/utils/web.d.ts +1 -1
- package/lib/utils/web.js +10 -10
- package/lib/validators.d.ts +4 -2
- package/lib/validators.js +31 -3
- package/lib/wallet-account.js +2 -0
- package/package.json +2 -1
package/dist/near-api-js.js
CHANGED
|
@@ -119,7 +119,7 @@ class Account {
|
|
|
119
119
|
deprecate('use `Account.signAndSendTransaction(SignAndSendTransactionOptions)` instead');
|
|
120
120
|
return this.signAndSendTransactionV2({ receiverId, actions });
|
|
121
121
|
}
|
|
122
|
-
async signAndSendTransactionV2({ receiverId, actions }) {
|
|
122
|
+
async signAndSendTransactionV2({ receiverId, actions, returnError }) {
|
|
123
123
|
let txHash, signedTx;
|
|
124
124
|
// TODO: TX_NONCE (different constants for different uses of exponentialBackoff?)
|
|
125
125
|
const result = await exponential_backoff_1.default(TX_NONCE_RETRY_WAIT, TX_NONCE_RETRY_NUMBER, TX_NONCE_RETRY_WAIT_BACKOFF, async () => {
|
|
@@ -159,7 +159,7 @@ class Account {
|
|
|
159
159
|
return acc;
|
|
160
160
|
}, []);
|
|
161
161
|
this.printLogsAndFailures(signedTx.transaction.receiverId, flatLogs);
|
|
162
|
-
if (typeof result.status === 'object' && typeof result.status.Failure === 'object') {
|
|
162
|
+
if (!returnError && typeof result.status === 'object' && typeof result.status.Failure === 'object') {
|
|
163
163
|
// if error data has error_message and error_type properties, we consider that node returned an error in the old format
|
|
164
164
|
if (result.status.Failure.error_message && result.status.Failure.error_type) {
|
|
165
165
|
throw new providers_1.TypedError(`Transaction ${result.transaction_outcome.id} failed. ${result.status.Failure.error_message}`, result.status.Failure.error_type);
|
|
@@ -963,7 +963,7 @@ function getProvider(config) {
|
|
|
963
963
|
switch (config.type) {
|
|
964
964
|
case undefined:
|
|
965
965
|
return config;
|
|
966
|
-
case 'JsonRpcProvider': return new providers_1.JsonRpcProvider(config.args
|
|
966
|
+
case 'JsonRpcProvider': return new providers_1.JsonRpcProvider({ ...config.args });
|
|
967
967
|
default: throw new Error(`Unknown provider type ${config.type}`);
|
|
968
968
|
}
|
|
969
969
|
}
|
|
@@ -2407,7 +2407,7 @@ class Near {
|
|
|
2407
2407
|
this.config = config;
|
|
2408
2408
|
this.connection = connection_1.Connection.fromConfig({
|
|
2409
2409
|
networkId: config.networkId,
|
|
2410
|
-
provider: { type: 'JsonRpcProvider', args: { url: config.nodeUrl } },
|
|
2410
|
+
provider: { type: 'JsonRpcProvider', args: { url: config.nodeUrl, headers: config.headers } },
|
|
2411
2411
|
signer: config.signer || { type: 'InMemorySigner', keyStore: config.keyStore || config.deps.keyStore }
|
|
2412
2412
|
});
|
|
2413
2413
|
if (config.masterAccount) {
|
|
@@ -2485,7 +2485,7 @@ Object.defineProperty(exports, "TypedError", { enumerable: true, get: function (
|
|
|
2485
2485
|
Object.defineProperty(exports, "ErrorContext", { enumerable: true, get: function () { return json_rpc_provider_1.ErrorContext; } });
|
|
2486
2486
|
|
|
2487
2487
|
},{"./json-rpc-provider":19,"./provider":20}],19:[function(require,module,exports){
|
|
2488
|
-
(function (Buffer){(function (){
|
|
2488
|
+
(function (process,Buffer){(function (){
|
|
2489
2489
|
"use strict";
|
|
2490
2490
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
2491
2491
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
@@ -2520,11 +2520,18 @@ let _nextId = 123;
|
|
|
2520
2520
|
*/
|
|
2521
2521
|
class JsonRpcProvider extends provider_1.Provider {
|
|
2522
2522
|
/**
|
|
2523
|
-
* @param
|
|
2523
|
+
* @param connectionInfoOrUrl ConnectionInfo or RPC API endpoint URL (deprecated)
|
|
2524
2524
|
*/
|
|
2525
|
-
constructor(
|
|
2525
|
+
constructor(connectionInfoOrUrl) {
|
|
2526
2526
|
super();
|
|
2527
|
-
|
|
2527
|
+
if (connectionInfoOrUrl != null && typeof connectionInfoOrUrl == 'object') {
|
|
2528
|
+
this.connection = connectionInfoOrUrl;
|
|
2529
|
+
}
|
|
2530
|
+
else {
|
|
2531
|
+
const deprecate = depd_1.default('JsonRpcProvider(url?: string)');
|
|
2532
|
+
deprecate('use `JsonRpcProvider(connectionInfo: ConnectionInfo)` instead');
|
|
2533
|
+
this.connection = { url: connectionInfoOrUrl };
|
|
2534
|
+
}
|
|
2528
2535
|
}
|
|
2529
2536
|
/**
|
|
2530
2537
|
* Gets the RPC's status
|
|
@@ -2594,7 +2601,7 @@ class JsonRpcProvider extends provider_1.Provider {
|
|
|
2594
2601
|
async query(...args) {
|
|
2595
2602
|
let result;
|
|
2596
2603
|
if (args.length === 1) {
|
|
2597
|
-
result = await this.sendJsonRpc('query',
|
|
2604
|
+
result = await this.sendJsonRpc('query', args[0]);
|
|
2598
2605
|
}
|
|
2599
2606
|
else {
|
|
2600
2607
|
const [path, data] = args;
|
|
@@ -2815,7 +2822,9 @@ class JsonRpcProvider extends provider_1.Provider {
|
|
|
2815
2822
|
}
|
|
2816
2823
|
catch (error) {
|
|
2817
2824
|
if (error.type === 'TimeoutError') {
|
|
2818
|
-
|
|
2825
|
+
if (!process.env['NEAR_NO_LOGS']) {
|
|
2826
|
+
console.warn(`Retrying request to ${method} as it has timed out`, params);
|
|
2827
|
+
}
|
|
2819
2828
|
return null;
|
|
2820
2829
|
}
|
|
2821
2830
|
throw error;
|
|
@@ -2834,8 +2843,8 @@ class JsonRpcProvider extends provider_1.Provider {
|
|
|
2834
2843
|
}
|
|
2835
2844
|
exports.JsonRpcProvider = JsonRpcProvider;
|
|
2836
2845
|
|
|
2837
|
-
}).call(this)}).call(this,require("buffer").Buffer)
|
|
2838
|
-
},{"../utils/errors":25,"../utils/exponential-backoff":26,"../utils/rpc_errors":30,"../utils/web":32,"./provider":20,"borsh":38,"buffer":41,"depd":47}],20:[function(require,module,exports){
|
|
2846
|
+
}).call(this)}).call(this,require('_process'),require("buffer").Buffer)
|
|
2847
|
+
},{"../utils/errors":25,"../utils/exponential-backoff":26,"../utils/rpc_errors":30,"../utils/web":32,"./provider":20,"_process":67,"borsh":38,"buffer":41,"depd":47}],20:[function(require,module,exports){
|
|
2839
2848
|
(function (Buffer){(function (){
|
|
2840
2849
|
"use strict";
|
|
2841
2850
|
/**
|
|
@@ -3336,7 +3345,7 @@ class ErrorContext {
|
|
|
3336
3345
|
}
|
|
3337
3346
|
exports.ErrorContext = ErrorContext;
|
|
3338
3347
|
function logWarning(...args) {
|
|
3339
|
-
if (!process.env[
|
|
3348
|
+
if (!process.env['NEAR_NO_LOGS']) {
|
|
3340
3349
|
console.warn(...args);
|
|
3341
3350
|
}
|
|
3342
3351
|
}
|
|
@@ -3567,6 +3576,12 @@ class PublicKey extends enums_1.Assignable {
|
|
|
3567
3576
|
toString() {
|
|
3568
3577
|
return `${key_type_to_str(this.keyType)}:${serialize_1.base_encode(this.data)}`;
|
|
3569
3578
|
}
|
|
3579
|
+
verify(message, signature) {
|
|
3580
|
+
switch (this.keyType) {
|
|
3581
|
+
case KeyType.ED25519: return tweetnacl_1.default.sign.detached.verify(message, signature, this.data);
|
|
3582
|
+
default: throw new Error(`Unknown key type ${this.keyType}`);
|
|
3583
|
+
}
|
|
3584
|
+
}
|
|
3570
3585
|
}
|
|
3571
3586
|
exports.PublicKey = PublicKey;
|
|
3572
3587
|
class KeyPair {
|
|
@@ -3632,7 +3647,7 @@ class KeyPairEd25519 extends KeyPair {
|
|
|
3632
3647
|
return { signature, publicKey: this.publicKey };
|
|
3633
3648
|
}
|
|
3634
3649
|
verify(message, signature) {
|
|
3635
|
-
return
|
|
3650
|
+
return this.publicKey.verify(message, signature);
|
|
3636
3651
|
}
|
|
3637
3652
|
toString() {
|
|
3638
3653
|
return `ed25519:${this.secretKey}`;
|
|
@@ -3793,24 +3808,24 @@ const errors_1 = require("./errors");
|
|
|
3793
3808
|
const START_WAIT_TIME_MS = 1000;
|
|
3794
3809
|
const BACKOFF_MULTIPLIER = 1.5;
|
|
3795
3810
|
const RETRY_NUMBER = 10;
|
|
3796
|
-
async function fetchJson(
|
|
3797
|
-
let
|
|
3798
|
-
if (typeof (
|
|
3799
|
-
url =
|
|
3811
|
+
async function fetchJson(connectionInfoOrUrl, json) {
|
|
3812
|
+
let connectionInfo = { url: null };
|
|
3813
|
+
if (typeof (connectionInfoOrUrl) === 'string') {
|
|
3814
|
+
connectionInfo.url = connectionInfoOrUrl;
|
|
3800
3815
|
}
|
|
3801
3816
|
else {
|
|
3802
|
-
|
|
3817
|
+
connectionInfo = connectionInfoOrUrl;
|
|
3803
3818
|
}
|
|
3804
3819
|
const response = await exponential_backoff_1.default(START_WAIT_TIME_MS, RETRY_NUMBER, BACKOFF_MULTIPLIER, async () => {
|
|
3805
3820
|
try {
|
|
3806
|
-
const response = await fetch(url, {
|
|
3821
|
+
const response = await fetch(connectionInfo.url, {
|
|
3807
3822
|
method: json ? 'POST' : 'GET',
|
|
3808
3823
|
body: json ? json : undefined,
|
|
3809
|
-
headers: { 'Content-Type': 'application/json
|
|
3824
|
+
headers: { ...connectionInfo.headers, 'Content-Type': 'application/json' }
|
|
3810
3825
|
});
|
|
3811
3826
|
if (!response.ok) {
|
|
3812
3827
|
if (response.status === 503) {
|
|
3813
|
-
errors_1.logWarning(`Retrying HTTP request for ${url} as it's not available now`);
|
|
3828
|
+
errors_1.logWarning(`Retrying HTTP request for ${connectionInfo.url} as it's not available now`);
|
|
3814
3829
|
return null;
|
|
3815
3830
|
}
|
|
3816
3831
|
throw http_errors_1.default(response.status, await response.text());
|
|
@@ -3819,14 +3834,14 @@ async function fetchJson(connection, json) {
|
|
|
3819
3834
|
}
|
|
3820
3835
|
catch (error) {
|
|
3821
3836
|
if (error.toString().includes('FetchError') || error.toString().includes('Failed to fetch')) {
|
|
3822
|
-
errors_1.logWarning(`Retrying HTTP request for ${url} because of error: ${error}`);
|
|
3837
|
+
errors_1.logWarning(`Retrying HTTP request for ${connectionInfo.url} because of error: ${error}`);
|
|
3823
3838
|
return null;
|
|
3824
3839
|
}
|
|
3825
3840
|
throw error;
|
|
3826
3841
|
}
|
|
3827
3842
|
});
|
|
3828
3843
|
if (!response) {
|
|
3829
|
-
throw new providers_1.TypedError(`Exceeded ${RETRY_NUMBER} attempts for ${url}.`, 'RetriesExceeded');
|
|
3844
|
+
throw new providers_1.TypedError(`Exceeded ${RETRY_NUMBER} attempts for ${connectionInfo.url}.`, 'RetriesExceeded');
|
|
3830
3845
|
}
|
|
3831
3846
|
return await response.json();
|
|
3832
3847
|
}
|
|
@@ -3840,12 +3855,27 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3840
3855
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3841
3856
|
exports.diffEpochValidators = exports.findSeatPrice = void 0;
|
|
3842
3857
|
const bn_js_1 = __importDefault(require("bn.js"));
|
|
3858
|
+
const depd_1 = __importDefault(require("depd"));
|
|
3843
3859
|
/** Finds seat price given validators stakes and number of seats.
|
|
3844
3860
|
* Calculation follow the spec: https://nomicon.io/Economics/README.html#validator-selection
|
|
3845
3861
|
* @params validators: current or next epoch validators.
|
|
3846
|
-
* @params
|
|
3862
|
+
* @params maxNumberOfSeats: maximum number of seats in the network.
|
|
3863
|
+
* @params minimumStakeRatio: minimum stake ratio
|
|
3864
|
+
* @params protocolVersion: version of the protocol from genesis config
|
|
3847
3865
|
*/
|
|
3848
|
-
function findSeatPrice(validators,
|
|
3866
|
+
function findSeatPrice(validators, maxNumberOfSeats, minimumStakeRatio, protocolVersion) {
|
|
3867
|
+
if (protocolVersion && protocolVersion < 49) {
|
|
3868
|
+
return findSeatPriceForProtocolBefore49(validators, maxNumberOfSeats);
|
|
3869
|
+
}
|
|
3870
|
+
if (!minimumStakeRatio) {
|
|
3871
|
+
const deprecate = depd_1.default('findSeatPrice(validators, maxNumberOfSeats)');
|
|
3872
|
+
deprecate('`use `findSeatPrice(validators, maxNumberOfSeats, minimumStakeRatio)` instead');
|
|
3873
|
+
minimumStakeRatio = [1, 6250]; // harcoded minimumStakeRation from 12/7/21
|
|
3874
|
+
}
|
|
3875
|
+
return findSeatPriceForProtocolAfter49(validators, maxNumberOfSeats, minimumStakeRatio);
|
|
3876
|
+
}
|
|
3877
|
+
exports.findSeatPrice = findSeatPrice;
|
|
3878
|
+
function findSeatPriceForProtocolBefore49(validators, numSeats) {
|
|
3849
3879
|
const stakes = validators.map(v => new bn_js_1.default(v.stake, 10)).sort((a, b) => a.cmp(b));
|
|
3850
3880
|
const num = new bn_js_1.default(numSeats);
|
|
3851
3881
|
const stakesSum = stakes.reduce((a, b) => a.add(b));
|
|
@@ -3872,7 +3902,20 @@ function findSeatPrice(validators, numSeats) {
|
|
|
3872
3902
|
}
|
|
3873
3903
|
return left;
|
|
3874
3904
|
}
|
|
3875
|
-
|
|
3905
|
+
// nearcore reference: https://github.com/near/nearcore/blob/5a8ae263ec07930cd34d0dcf5bcee250c67c02aa/chain/epoch_manager/src/validator_selection.rs#L308;L315
|
|
3906
|
+
function findSeatPriceForProtocolAfter49(validators, maxNumberOfSeats, minimumStakeRatio) {
|
|
3907
|
+
if (minimumStakeRatio.length != 2) {
|
|
3908
|
+
throw Error('minimumStakeRatio should have 2 elements');
|
|
3909
|
+
}
|
|
3910
|
+
const stakes = validators.map(v => new bn_js_1.default(v.stake, 10)).sort((a, b) => a.cmp(b));
|
|
3911
|
+
const stakesSum = stakes.reduce((a, b) => a.add(b));
|
|
3912
|
+
if (validators.length < maxNumberOfSeats) {
|
|
3913
|
+
return stakesSum.mul(new bn_js_1.default(minimumStakeRatio[0])).div(new bn_js_1.default(minimumStakeRatio[1]));
|
|
3914
|
+
}
|
|
3915
|
+
else {
|
|
3916
|
+
return stakes[0].add(new bn_js_1.default(1));
|
|
3917
|
+
}
|
|
3918
|
+
}
|
|
3876
3919
|
/** Diff validators between current and next epoch.
|
|
3877
3920
|
* Returns additions, subtractions and changes to validator set.
|
|
3878
3921
|
* @params currentValidators: list of current validators.
|
|
@@ -3891,7 +3934,7 @@ function diffEpochValidators(currentValidators, nextValidators) {
|
|
|
3891
3934
|
}
|
|
3892
3935
|
exports.diffEpochValidators = diffEpochValidators;
|
|
3893
3936
|
|
|
3894
|
-
},{"bn.js":37}],34:[function(require,module,exports){
|
|
3937
|
+
},{"bn.js":37,"depd":47}],34:[function(require,module,exports){
|
|
3895
3938
|
(function (Buffer){(function (){
|
|
3896
3939
|
"use strict";
|
|
3897
3940
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
@@ -4059,6 +4102,8 @@ class WalletConnection {
|
|
|
4059
4102
|
currentUrl.searchParams.delete('public_key');
|
|
4060
4103
|
currentUrl.searchParams.delete('all_keys');
|
|
4061
4104
|
currentUrl.searchParams.delete('account_id');
|
|
4105
|
+
currentUrl.searchParams.delete('meta');
|
|
4106
|
+
currentUrl.searchParams.delete('transactionHashes');
|
|
4062
4107
|
window.history.replaceState({}, document.title, currentUrl.toString());
|
|
4063
4108
|
}
|
|
4064
4109
|
/**
|
|
@@ -4279,8 +4324,6 @@ function base (ALPHABET) {
|
|
|
4279
4324
|
if (typeof source !== 'string') { throw new TypeError('Expected String') }
|
|
4280
4325
|
if (source.length === 0) { return _Buffer.alloc(0) }
|
|
4281
4326
|
var psz = 0
|
|
4282
|
-
// Skip leading spaces.
|
|
4283
|
-
if (source[psz] === ' ') { return }
|
|
4284
4327
|
// Skip and count leading '1's.
|
|
4285
4328
|
var zeroes = 0
|
|
4286
4329
|
var length = 0
|
|
@@ -4307,8 +4350,6 @@ function base (ALPHABET) {
|
|
|
4307
4350
|
length = i
|
|
4308
4351
|
psz++
|
|
4309
4352
|
}
|
|
4310
|
-
// Skip trailing spaces.
|
|
4311
|
-
if (source[psz] === ' ') { return }
|
|
4312
4353
|
// Skip leading zeroes in b256.
|
|
4313
4354
|
var it4 = size - length
|
|
4314
4355
|
while (it4 !== size && b256[it4] === 0) {
|
|
@@ -13788,6 +13829,8 @@ exports.TextDecoder = TextDecoder;
|
|
|
13788
13829
|
* MIT Licensed
|
|
13789
13830
|
*/
|
|
13790
13831
|
|
|
13832
|
+
'use strict'
|
|
13833
|
+
|
|
13791
13834
|
/**
|
|
13792
13835
|
* Module exports.
|
|
13793
13836
|
* @public
|
package/dist/near-api-js.min.js
CHANGED
|
@@ -5,7 +5,7 @@ window.nearApi=require("./lib/browser-index"),window.Buffer=Buffer;
|
|
|
5
5
|
}).call(this)}).call(this,require("buffer").Buffer)
|
|
6
6
|
},{"./lib/browser-index":6,"buffer":41}],2:[function(require,module,exports){
|
|
7
7
|
(function (process,Buffer){(function (){
|
|
8
|
-
"use strict";var __importDefault=this&&this.__importDefault||function(t){return t&&t.__esModule?t:{default:t}};Object.defineProperty(exports,"__esModule",{value:!0}),exports.Account=void 0;const bn_js_1=__importDefault(require("bn.js")),depd_1=__importDefault(require("depd")),transaction_1=require("./transaction"),providers_1=require("./providers"),borsh_1=require("borsh"),key_pair_1=require("./utils/key_pair"),errors_1=require("./utils/errors"),rpc_errors_1=require("./utils/rpc_errors"),constants_1=require("./constants"),exponential_backoff_1=__importDefault(require("./utils/exponential-backoff")),TX_NONCE_RETRY_NUMBER=12,TX_NONCE_RETRY_WAIT=500,TX_NONCE_RETRY_WAIT_BACKOFF=1.5;function parseJsonFromRawResponse(t){return JSON.parse(Buffer.from(t).toString())}function bytesJsonStringify(t){return Buffer.from(JSON.stringify(t))}class Account{constructor(t,e){this.accessKeyByPublicKeyCache={},this.connection=t,this.accountId=e}get ready(){return depd_1.default("Account.ready()")("not needed anymore, always ready"),Promise.resolve()}async fetchState(){depd_1.default("Account.fetchState()")("use `Account.state()` instead")}async state(){return this.connection.provider.query({request_type:"view_account",account_id:this.accountId,finality:"optimistic"})}printLogsAndFailures(t,e){if(!process.env.NEAR_NO_LOGS)for(const n of e)console.log(`Receipt${n.receiptIds.length>1?"s":""}: ${n.receiptIds.join(", ")}`),this.printLogs(t,n.logs,"\t"),n.failure&&console.warn(`\tFailure [${t}]: ${n.failure}`)}printLogs(t,e,n=""){if(!process.env.NEAR_NO_LOGS)for(const r of e)console.log(`${n}Log [${t}]: ${r}`)}async signTransaction(t,e){const n=await this.findAccessKey(t,e);if(!n)throw new providers_1.TypedError(`Can not sign transactions for account ${this.accountId} on network ${this.connection.networkId}, no matching key pair found in ${this.connection.signer}.`,"KeyNotFound");const{accessKey:r}=n,s=(await this.connection.provider.block({finality:"final"})).header.hash,i=++r.nonce;return await transaction_1.signTransaction(t,i,e,borsh_1.baseDecode(s),this.connection.signer,this.accountId,this.connection.networkId)}signAndSendTransaction(...t){return"string"==typeof t[0]?this.signAndSendTransactionV1(t[0],t[1]):this.signAndSendTransactionV2(t[0])}signAndSendTransactionV1(t,e){return depd_1.default("Account.signAndSendTransaction(receiverId, actions")("use `Account.signAndSendTransaction(SignAndSendTransactionOptions)` instead"),this.signAndSendTransactionV2({receiverId:t,actions:e})}async signAndSendTransactionV2({receiverId:t,actions:e}){let
|
|
8
|
+
"use strict";var __importDefault=this&&this.__importDefault||function(t){return t&&t.__esModule?t:{default:t}};Object.defineProperty(exports,"__esModule",{value:!0}),exports.Account=void 0;const bn_js_1=__importDefault(require("bn.js")),depd_1=__importDefault(require("depd")),transaction_1=require("./transaction"),providers_1=require("./providers"),borsh_1=require("borsh"),key_pair_1=require("./utils/key_pair"),errors_1=require("./utils/errors"),rpc_errors_1=require("./utils/rpc_errors"),constants_1=require("./constants"),exponential_backoff_1=__importDefault(require("./utils/exponential-backoff")),TX_NONCE_RETRY_NUMBER=12,TX_NONCE_RETRY_WAIT=500,TX_NONCE_RETRY_WAIT_BACKOFF=1.5;function parseJsonFromRawResponse(t){return JSON.parse(Buffer.from(t).toString())}function bytesJsonStringify(t){return Buffer.from(JSON.stringify(t))}class Account{constructor(t,e){this.accessKeyByPublicKeyCache={},this.connection=t,this.accountId=e}get ready(){return depd_1.default("Account.ready()")("not needed anymore, always ready"),Promise.resolve()}async fetchState(){depd_1.default("Account.fetchState()")("use `Account.state()` instead")}async state(){return this.connection.provider.query({request_type:"view_account",account_id:this.accountId,finality:"optimistic"})}printLogsAndFailures(t,e){if(!process.env.NEAR_NO_LOGS)for(const n of e)console.log(`Receipt${n.receiptIds.length>1?"s":""}: ${n.receiptIds.join(", ")}`),this.printLogs(t,n.logs,"\t"),n.failure&&console.warn(`\tFailure [${t}]: ${n.failure}`)}printLogs(t,e,n=""){if(!process.env.NEAR_NO_LOGS)for(const r of e)console.log(`${n}Log [${t}]: ${r}`)}async signTransaction(t,e){const n=await this.findAccessKey(t,e);if(!n)throw new providers_1.TypedError(`Can not sign transactions for account ${this.accountId} on network ${this.connection.networkId}, no matching key pair found in ${this.connection.signer}.`,"KeyNotFound");const{accessKey:r}=n,s=(await this.connection.provider.block({finality:"final"})).header.hash,i=++r.nonce;return await transaction_1.signTransaction(t,i,e,borsh_1.baseDecode(s),this.connection.signer,this.accountId,this.connection.networkId)}signAndSendTransaction(...t){return"string"==typeof t[0]?this.signAndSendTransactionV1(t[0],t[1]):this.signAndSendTransactionV2(t[0])}signAndSendTransactionV1(t,e){return depd_1.default("Account.signAndSendTransaction(receiverId, actions")("use `Account.signAndSendTransaction(SignAndSendTransactionOptions)` instead"),this.signAndSendTransactionV2({receiverId:t,actions:e})}async signAndSendTransactionV2({receiverId:t,actions:e,returnError:n}){let r,s;const i=await exponential_backoff_1.default(TX_NONCE_RETRY_WAIT,TX_NONCE_RETRY_NUMBER,TX_NONCE_RETRY_WAIT_BACKOFF,async()=>{[r,s]=await this.signTransaction(t,e);const n=s.transaction.publicKey;try{return await this.connection.provider.sendTransaction(s)}catch(e){if("InvalidNonce"===e.type)return errors_1.logWarning(`Retrying transaction ${t}:${borsh_1.baseEncode(r)} with new nonce.`),delete this.accessKeyByPublicKeyCache[n.toString()],null;if("Expired"===e.type)return errors_1.logWarning(`Retrying transaction ${t}:${borsh_1.baseEncode(r)} due to expired block hash`),null;throw e.context=new providers_1.ErrorContext(borsh_1.baseEncode(r)),e}});if(!i)throw new providers_1.TypedError("nonce retries exceeded for transaction. This usually means there are too many parallel requests with the same access key.","RetriesExceeded");const a=[i.transaction_outcome,...i.receipts_outcome].reduce((t,e)=>e.outcome.logs.length||"object"==typeof e.outcome.status&&"object"==typeof e.outcome.status.Failure?t.concat({receiptIds:e.outcome.receipt_ids,logs:e.outcome.logs,failure:void 0!==e.outcome.status.Failure?rpc_errors_1.parseRpcError(e.outcome.status.Failure):null}):t,[]);if(this.printLogsAndFailures(s.transaction.receiverId,a),!n&&"object"==typeof i.status&&"object"==typeof i.status.Failure)throw i.status.Failure.error_message&&i.status.Failure.error_type?new providers_1.TypedError(`Transaction ${i.transaction_outcome.id} failed. ${i.status.Failure.error_message}`,i.status.Failure.error_type):rpc_errors_1.parseResultError(i);return i}async findAccessKey(t,e){const n=await this.connection.signer.getPublicKey(this.accountId,this.connection.networkId);if(!n)return null;const r=this.accessKeyByPublicKeyCache[n.toString()];if(void 0!==r)return{publicKey:n,accessKey:r};try{const t=await this.connection.provider.query({request_type:"view_access_key",account_id:this.accountId,public_key:n.toString(),finality:"optimistic"});return this.accessKeyByPublicKeyCache[n.toString()]?{publicKey:n,accessKey:this.accessKeyByPublicKeyCache[n.toString()]}:(this.accessKeyByPublicKeyCache[n.toString()]=t,{publicKey:n,accessKey:t})}catch(t){if("AccessKeyDoesNotExist"==t.type)return null;throw t}}async createAndDeployContract(t,e,n,r){const s=transaction_1.fullAccessKey();return await this.signAndSendTransaction({receiverId:t,actions:[transaction_1.createAccount(),transaction_1.transfer(r),transaction_1.addKey(key_pair_1.PublicKey.from(e),s),transaction_1.deployContract(n)]}),new Account(this.connection,t)}async sendMoney(t,e){return this.signAndSendTransaction({receiverId:t,actions:[transaction_1.transfer(e)]})}async createAccount(t,e,n){const r=transaction_1.fullAccessKey();return this.signAndSendTransaction({receiverId:t,actions:[transaction_1.createAccount(),transaction_1.transfer(n),transaction_1.addKey(key_pair_1.PublicKey.from(e),r)]})}async deleteAccount(t){return this.signAndSendTransaction({receiverId:this.accountId,actions:[transaction_1.deleteAccount(t)]})}async deployContract(t){return this.signAndSendTransaction({receiverId:this.accountId,actions:[transaction_1.deployContract(t)]})}async functionCall(...t){return"string"==typeof t[0]?this.functionCallV1(t[0],t[1],t[2],t[3],t[4]):this.functionCallV2(t[0])}functionCallV1(t,e,n,r,s){return depd_1.default("Account.functionCall(contractId, methodName, args, gas, amount)")("use `Account.functionCall(FunctionCallOptions)` instead"),n=n||{},this.validateArgs(n),this.signAndSendTransaction({receiverId:t,actions:[transaction_1.functionCall(e,n,r||constants_1.DEFAULT_FUNCTION_CALL_GAS,s)]})}functionCallV2({contractId:t,methodName:e,args:n={},gas:r=constants_1.DEFAULT_FUNCTION_CALL_GAS,attachedDeposit:s,walletMeta:i,walletCallbackUrl:a,stringify:o}){this.validateArgs(n);const c=void 0===o?transaction_1.stringifyJsonOrBytes:o;return this.signAndSendTransaction({receiverId:t,actions:[transaction_1.functionCall(e,n,r,s,c)],walletMeta:i,walletCallbackUrl:a})}async addKey(t,e,n,r){let s;return n||(n=[]),Array.isArray(n)||(n=[n]),s=e?transaction_1.functionCallAccessKey(e,n,r):transaction_1.fullAccessKey(),this.signAndSendTransaction({receiverId:this.accountId,actions:[transaction_1.addKey(key_pair_1.PublicKey.from(t),s)]})}async deleteKey(t){return this.signAndSendTransaction({receiverId:this.accountId,actions:[transaction_1.deleteKey(key_pair_1.PublicKey.from(t))]})}async stake(t,e){return this.signAndSendTransaction({receiverId:this.accountId,actions:[transaction_1.stake(e,key_pair_1.PublicKey.from(t))]})}validateArgs(t){if(!(void 0!==t.byteLength&&t.byteLength===t.length)&&(Array.isArray(t)||"object"!=typeof t))throw new errors_1.PositionalArgsError}async viewFunction(t,e,n={},{parse:r=parseJsonFromRawResponse,stringify:s=bytesJsonStringify}={}){this.validateArgs(n);const i=s(n).toString("base64"),a=await this.connection.provider.query({request_type:"call_function",account_id:t,method_name:e,args_base64:i,finality:"optimistic"});return a.logs&&this.printLogs(t,a.logs),a.result&&a.result.length>0&&r(Buffer.from(a.result))}async viewState(t,e={finality:"optimistic"}){const{values:n}=await this.connection.provider.query({request_type:"view_state",...e,account_id:this.accountId,prefix_base64:Buffer.from(t).toString("base64")});return n.map(({key:t,value:e})=>({key:Buffer.from(t,"base64"),value:Buffer.from(e,"base64")}))}async getAccessKeys(){const t=await this.connection.provider.query({request_type:"view_access_key_list",account_id:this.accountId,finality:"optimistic"});return Array.isArray(t)?t:t.keys}async getAccountDetails(){return{authorizedApps:(await this.getAccessKeys()).filter(t=>"FullAccess"!==t.access_key.permission).map(t=>{const e=t.access_key.permission;return{contractId:e.FunctionCall.receiver_id,amount:e.FunctionCall.allowance,publicKey:t.public_key}})}}async getAccountBalance(){const t=await this.connection.provider.experimental_protocolConfig({finality:"final"}),e=await this.state(),n=new bn_js_1.default(t.runtime_config.storage_amount_per_byte),r=new bn_js_1.default(e.storage_usage).mul(n),s=new bn_js_1.default(e.locked),i=new bn_js_1.default(e.amount).add(s),a=i.sub(bn_js_1.default.max(s,r));return{total:i.toString(),stateStaked:r.toString(),staked:s.toString(),available:a.toString()}}}exports.Account=Account;
|
|
9
9
|
|
|
10
10
|
}).call(this)}).call(this,require('_process'),require("buffer").Buffer)
|
|
11
11
|
},{"./constants":9,"./providers":18,"./transaction":23,"./utils/errors":25,"./utils/exponential-backoff":26,"./utils/key_pair":29,"./utils/rpc_errors":30,"_process":67,"bn.js":37,"borsh":38,"buffer":41,"depd":47}],3:[function(require,module,exports){
|
|
@@ -26,7 +26,7 @@ window.nearApi=require("./lib/browser-index"),window.Buffer=Buffer;
|
|
|
26
26
|
"use strict";var __createBinding=this&&this.__createBinding||(Object.create?function(e,t,r,n){void 0===n&&(n=r),Object.defineProperty(e,n,{enumerable:!0,get:function(){return t[r]}})}:function(e,t,r,n){void 0===n&&(n=r),e[n]=t[r]}),__setModuleDefault=this&&this.__setModuleDefault||(Object.create?function(e,t){Object.defineProperty(e,"default",{enumerable:!0,value:t})}:function(e,t){e.default=t}),__importStar=this&&this.__importStar||function(e){if(e&&e.__esModule)return e;var t={};if(null!=e)for(var r in e)"default"!==r&&Object.hasOwnProperty.call(e,r)&&__createBinding(t,e,r);return __setModuleDefault(t,e),t};Object.defineProperty(exports,"__esModule",{value:!0}),exports.WalletConnection=exports.WalletAccount=exports.ConnectedWalletAccount=exports.Near=exports.KeyPair=exports.Signer=exports.InMemorySigner=exports.Contract=exports.Connection=exports.Account=exports.multisig=exports.validators=exports.transactions=exports.utils=exports.providers=exports.accountCreator=void 0;const providers=__importStar(require("./providers"));exports.providers=providers;const utils=__importStar(require("./utils"));exports.utils=utils;const transactions=__importStar(require("./transaction"));exports.transactions=transactions;const validators=__importStar(require("./validators"));exports.validators=validators;const account_1=require("./account");Object.defineProperty(exports,"Account",{enumerable:!0,get:function(){return account_1.Account}});const multisig=__importStar(require("./account_multisig"));exports.multisig=multisig;const accountCreator=__importStar(require("./account_creator"));exports.accountCreator=accountCreator;const connection_1=require("./connection");Object.defineProperty(exports,"Connection",{enumerable:!0,get:function(){return connection_1.Connection}});const signer_1=require("./signer");Object.defineProperty(exports,"Signer",{enumerable:!0,get:function(){return signer_1.Signer}}),Object.defineProperty(exports,"InMemorySigner",{enumerable:!0,get:function(){return signer_1.InMemorySigner}});const contract_1=require("./contract");Object.defineProperty(exports,"Contract",{enumerable:!0,get:function(){return contract_1.Contract}});const key_pair_1=require("./utils/key_pair");Object.defineProperty(exports,"KeyPair",{enumerable:!0,get:function(){return key_pair_1.KeyPair}});const near_1=require("./near");Object.defineProperty(exports,"Near",{enumerable:!0,get:function(){return near_1.Near}});const wallet_account_1=require("./wallet-account");Object.defineProperty(exports,"ConnectedWalletAccount",{enumerable:!0,get:function(){return wallet_account_1.ConnectedWalletAccount}}),Object.defineProperty(exports,"WalletAccount",{enumerable:!0,get:function(){return wallet_account_1.WalletAccount}}),Object.defineProperty(exports,"WalletConnection",{enumerable:!0,get:function(){return wallet_account_1.WalletConnection}});
|
|
27
27
|
|
|
28
28
|
},{"./account":2,"./account_creator":3,"./account_multisig":4,"./connection":8,"./contract":10,"./near":17,"./providers":18,"./signer":22,"./transaction":23,"./utils":28,"./utils/key_pair":29,"./validators":33,"./wallet-account":34}],8:[function(require,module,exports){
|
|
29
|
-
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.Connection=void 0;const providers_1=require("./providers"),signer_1=require("./signer");function getProvider(e){switch(e.type){case void 0:return e;case"JsonRpcProvider":return new providers_1.JsonRpcProvider(e.args
|
|
29
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.Connection=void 0;const providers_1=require("./providers"),signer_1=require("./signer");function getProvider(e){switch(e.type){case void 0:return e;case"JsonRpcProvider":return new providers_1.JsonRpcProvider({...e.args});default:throw new Error(`Unknown provider type ${e.type}`)}}function getSigner(e){switch(e.type){case void 0:return e;case"InMemorySigner":return new signer_1.InMemorySigner(e.keyStore);default:throw new Error(`Unknown signer type ${e.type}`)}}class Connection{constructor(e,r,n){this.networkId=e,this.provider=r,this.signer=n}static fromConfig(e){const r=getProvider(e.provider),n=getSigner(e.signer);return new Connection(e.networkId,r,n)}}exports.Connection=Connection;
|
|
30
30
|
|
|
31
31
|
},{"./providers":18,"./signer":22}],9:[function(require,module,exports){
|
|
32
32
|
"use strict";var __importDefault=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(exports,"__esModule",{value:!0}),exports.DEFAULT_FUNCTION_CALL_GAS=void 0;const bn_js_1=__importDefault(require("bn.js"));exports.DEFAULT_FUNCTION_CALL_GAS=new bn_js_1.default("30000000000000");
|
|
@@ -921,17 +921,17 @@ module.exports={
|
|
|
921
921
|
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.MergeKeyStore=void 0;const keystore_1=require("./keystore");class MergeKeyStore extends keystore_1.KeyStore{constructor(e,t={writeKeyStoreIndex:0}){super(),this.options=t,this.keyStores=e}async setKey(e,t,r){await this.keyStores[this.options.writeKeyStoreIndex].setKey(e,t,r)}async getKey(e,t){for(const r of this.keyStores){const o=await r.getKey(e,t);if(o)return o}return null}async removeKey(e,t){for(const r of this.keyStores)await r.removeKey(e,t)}async clear(){for(const e of this.keyStores)await e.clear()}async getNetworks(){const e=new Set;for(const t of this.keyStores)for(const r of await t.getNetworks())e.add(r);return Array.from(e)}async getAccounts(e){const t=new Set;for(const r of this.keyStores)for(const o of await r.getAccounts(e))t.add(o);return Array.from(t)}toString(){return`MergeKeyStore(${this.keyStores.join(", ")})`}}exports.MergeKeyStore=MergeKeyStore;
|
|
922
922
|
|
|
923
923
|
},{"./keystore":15}],17:[function(require,module,exports){
|
|
924
|
-
"use strict";var __importDefault=this&&this.__importDefault||function(n){return n&&n.__esModule?n:{default:n}};Object.defineProperty(exports,"__esModule",{value:!0}),exports.Near=void 0;const bn_js_1=__importDefault(require("bn.js")),account_1=require("./account"),connection_1=require("./connection"),contract_1=require("./contract"),account_creator_1=require("./account_creator");class Near{constructor(n){if(this.config=n,this.connection=connection_1.Connection.fromConfig({networkId:n.networkId,provider:{type:"JsonRpcProvider",args:{url:n.nodeUrl}},signer:n.signer||{type:"InMemorySigner",keyStore:n.keyStore||n.deps.keyStore}}),n.masterAccount){const t=n.initialBalance?new bn_js_1.default(n.initialBalance):new bn_js_1.default("500000000000000000000000000");this.accountCreator=new account_creator_1.LocalAccountCreator(new account_1.Account(this.connection,n.masterAccount),t)}else n.helperUrl?this.accountCreator=new account_creator_1.UrlAccountCreator(this.connection,n.helperUrl):this.accountCreator=null}async account(n){return new account_1.Account(this.connection,n)}async createAccount(n,t){if(!this.accountCreator)throw new Error("Must specify account creator, either via masterAccount or helperUrl configuration settings.");return await this.accountCreator.createAccount(n,t),new account_1.Account(this.connection,n)}async loadContract(n,t){const e=new account_1.Account(this.connection,t.sender);return new contract_1.Contract(e,n,t)}async sendTokens(n,t,e){console.warn("near.sendTokens is deprecated. Use `yourAccount.sendMoney` instead.");const c=new account_1.Account(this.connection,t);return(await c.sendMoney(e,n)).transaction_outcome.id}}exports.Near=Near;
|
|
924
|
+
"use strict";var __importDefault=this&&this.__importDefault||function(n){return n&&n.__esModule?n:{default:n}};Object.defineProperty(exports,"__esModule",{value:!0}),exports.Near=void 0;const bn_js_1=__importDefault(require("bn.js")),account_1=require("./account"),connection_1=require("./connection"),contract_1=require("./contract"),account_creator_1=require("./account_creator");class Near{constructor(n){if(this.config=n,this.connection=connection_1.Connection.fromConfig({networkId:n.networkId,provider:{type:"JsonRpcProvider",args:{url:n.nodeUrl,headers:n.headers}},signer:n.signer||{type:"InMemorySigner",keyStore:n.keyStore||n.deps.keyStore}}),n.masterAccount){const t=n.initialBalance?new bn_js_1.default(n.initialBalance):new bn_js_1.default("500000000000000000000000000");this.accountCreator=new account_creator_1.LocalAccountCreator(new account_1.Account(this.connection,n.masterAccount),t)}else n.helperUrl?this.accountCreator=new account_creator_1.UrlAccountCreator(this.connection,n.helperUrl):this.accountCreator=null}async account(n){return new account_1.Account(this.connection,n)}async createAccount(n,t){if(!this.accountCreator)throw new Error("Must specify account creator, either via masterAccount or helperUrl configuration settings.");return await this.accountCreator.createAccount(n,t),new account_1.Account(this.connection,n)}async loadContract(n,t){const e=new account_1.Account(this.connection,t.sender);return new contract_1.Contract(e,n,t)}async sendTokens(n,t,e){console.warn("near.sendTokens is deprecated. Use `yourAccount.sendMoney` instead.");const c=new account_1.Account(this.connection,t);return(await c.sendMoney(e,n)).transaction_outcome.id}}exports.Near=Near;
|
|
925
925
|
|
|
926
926
|
},{"./account":2,"./account_creator":3,"./connection":8,"./contract":10,"bn.js":37}],18:[function(require,module,exports){
|
|
927
927
|
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.ErrorContext=exports.TypedError=exports.getTransactionLastResult=exports.FinalExecutionStatusBasic=exports.JsonRpcProvider=exports.Provider=void 0;const provider_1=require("./provider");Object.defineProperty(exports,"Provider",{enumerable:!0,get:function(){return provider_1.Provider}}),Object.defineProperty(exports,"getTransactionLastResult",{enumerable:!0,get:function(){return provider_1.getTransactionLastResult}}),Object.defineProperty(exports,"FinalExecutionStatusBasic",{enumerable:!0,get:function(){return provider_1.FinalExecutionStatusBasic}});const json_rpc_provider_1=require("./json-rpc-provider");Object.defineProperty(exports,"JsonRpcProvider",{enumerable:!0,get:function(){return json_rpc_provider_1.JsonRpcProvider}}),Object.defineProperty(exports,"TypedError",{enumerable:!0,get:function(){return json_rpc_provider_1.TypedError}}),Object.defineProperty(exports,"ErrorContext",{enumerable:!0,get:function(){return json_rpc_provider_1.ErrorContext}});
|
|
928
928
|
|
|
929
929
|
},{"./json-rpc-provider":19,"./provider":20}],19:[function(require,module,exports){
|
|
930
|
-
(function (Buffer){(function (){
|
|
931
|
-
"use strict";var __importDefault=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(exports,"__esModule",{value:!0}),exports.JsonRpcProvider=exports.ErrorContext=exports.TypedError=void 0;const depd_1=__importDefault(require("depd")),provider_1=require("./provider"),web_1=require("../utils/web"),errors_1=require("../utils/errors");Object.defineProperty(exports,"TypedError",{enumerable:!0,get:function(){return errors_1.TypedError}}),Object.defineProperty(exports,"ErrorContext",{enumerable:!0,get:function(){return errors_1.ErrorContext}});const borsh_1=require("borsh"),exponential_backoff_1=__importDefault(require("../utils/exponential-backoff")),rpc_errors_1=require("../utils/rpc_errors"),REQUEST_RETRY_NUMBER=12,REQUEST_RETRY_WAIT=500,REQUEST_RETRY_WAIT_BACKOFF=1.5;let _nextId=123;class JsonRpcProvider extends provider_1.Provider{constructor(e){super(),this.connection={url:e}}async status(){return this.sendJsonRpc("status",[])}async sendTransaction(e){const r=e.encode();return this.sendJsonRpc("broadcast_tx_commit",[Buffer.from(r).toString("base64")])}async sendTransactionAsync(e){const r=e.encode();return this.sendJsonRpc("broadcast_tx_async",[Buffer.from(r).toString("base64")])}async txStatus(e,r){return"string"==typeof e?this.txStatusString(e,r):this.txStatusUint8Array(e,r)}async txStatusUint8Array(e,r){return this.sendJsonRpc("tx",[borsh_1.baseEncode(e),r])}async txStatusString(e,r){return this.sendJsonRpc("tx",[e,r])}async txStatusReceipts(e,r){return this.sendJsonRpc("EXPERIMENTAL_tx_status",[borsh_1.baseEncode(e),r])}async query(...e){let r;if(1===e.length)r=await this.sendJsonRpc("query",
|
|
930
|
+
(function (process,Buffer){(function (){
|
|
931
|
+
"use strict";var __importDefault=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(exports,"__esModule",{value:!0}),exports.JsonRpcProvider=exports.ErrorContext=exports.TypedError=void 0;const depd_1=__importDefault(require("depd")),provider_1=require("./provider"),web_1=require("../utils/web"),errors_1=require("../utils/errors");Object.defineProperty(exports,"TypedError",{enumerable:!0,get:function(){return errors_1.TypedError}}),Object.defineProperty(exports,"ErrorContext",{enumerable:!0,get:function(){return errors_1.ErrorContext}});const borsh_1=require("borsh"),exponential_backoff_1=__importDefault(require("../utils/exponential-backoff")),rpc_errors_1=require("../utils/rpc_errors"),REQUEST_RETRY_NUMBER=12,REQUEST_RETRY_WAIT=500,REQUEST_RETRY_WAIT_BACKOFF=1.5;let _nextId=123;class JsonRpcProvider extends provider_1.Provider{constructor(e){if(super(),null!=e&&"object"==typeof e)this.connection=e;else{depd_1.default("JsonRpcProvider(url?: string)")("use `JsonRpcProvider(connectionInfo: ConnectionInfo)` instead"),this.connection={url:e}}}async status(){return this.sendJsonRpc("status",[])}async sendTransaction(e){const r=e.encode();return this.sendJsonRpc("broadcast_tx_commit",[Buffer.from(r).toString("base64")])}async sendTransactionAsync(e){const r=e.encode();return this.sendJsonRpc("broadcast_tx_async",[Buffer.from(r).toString("base64")])}async txStatus(e,r){return"string"==typeof e?this.txStatusString(e,r):this.txStatusUint8Array(e,r)}async txStatusUint8Array(e,r){return this.sendJsonRpc("tx",[borsh_1.baseEncode(e),r])}async txStatusString(e,r){return this.sendJsonRpc("tx",[e,r])}async txStatusReceipts(e,r){return this.sendJsonRpc("EXPERIMENTAL_tx_status",[borsh_1.baseEncode(e),r])}async query(...e){let r;if(1===e.length)r=await this.sendJsonRpc("query",e[0]);else{const[t,n]=e;r=await this.sendJsonRpc("query",[t,n])}if(r&&r.error)throw new errors_1.TypedError(`Querying ${e} failed: ${r.error}.\n${JSON.stringify(r,null,2)}`,rpc_errors_1.getErrorTypeFromErrorMessage(r.error));return r}async block(e){const{finality:r}=e;let{blockId:t}=e;if("object"!=typeof e){depd_1.default("JsonRpcProvider.block(blockId)")("use `block({ blockId })` or `block({ finality })` instead"),t=e}return this.sendJsonRpc("block",{block_id:t,finality:r})}async blockChanges(e){const{finality:r}=e,{blockId:t}=e;return this.sendJsonRpc("EXPERIMENTAL_changes_in_block",{block_id:t,finality:r})}async chunk(e){return this.sendJsonRpc("chunk",[e])}async validators(e){return this.sendJsonRpc("validators",[e])}async experimental_genesisConfig(){return depd_1.default("JsonRpcProvider.experimental_protocolConfig()")("use `experimental_protocolConfig({ sync_checkpoint: 'genesis' })` to fetch the up-to-date or genesis protocol config explicitly"),await this.sendJsonRpc("EXPERIMENTAL_protocol_config",{sync_checkpoint:"genesis"})}async experimental_protocolConfig(e){return await this.sendJsonRpc("EXPERIMENTAL_protocol_config",e)}async experimental_lightClientProof(e){return depd_1.default("JsonRpcProvider.experimental_lightClientProof(request)")("use `lightClientProof` instead"),await this.lightClientProof(e)}async lightClientProof(e){return await this.sendJsonRpc("EXPERIMENTAL_light_client_proof",e)}async accessKeyChanges(e,r){const{finality:t}=r,{blockId:n}=r;return this.sendJsonRpc("EXPERIMENTAL_changes",{changes_type:"all_access_key_changes",account_ids:e,block_id:n,finality:t})}async singleAccessKeyChanges(e,r){const{finality:t}=r,{blockId:n}=r;return this.sendJsonRpc("EXPERIMENTAL_changes",{changes_type:"single_access_key_changes",keys:e,block_id:n,finality:t})}async accountChanges(e,r){const{finality:t}=r,{blockId:n}=r;return this.sendJsonRpc("EXPERIMENTAL_changes",{changes_type:"account_changes",account_ids:e,block_id:n,finality:t})}async contractStateChanges(e,r,t=""){const{finality:n}=r,{blockId:o}=r;return this.sendJsonRpc("EXPERIMENTAL_changes",{changes_type:"data_changes",account_ids:e,key_prefix_base64:t,block_id:o,finality:n})}async contractCodeChanges(e,r){const{finality:t}=r,{blockId:n}=r;return this.sendJsonRpc("EXPERIMENTAL_changes",{changes_type:"contract_code_changes",account_ids:e,block_id:n,finality:t})}async gasPrice(e){return await this.sendJsonRpc("gas_price",[e])}async sendJsonRpc(e,r){const t=await exponential_backoff_1.default(REQUEST_RETRY_WAIT,REQUEST_RETRY_NUMBER,REQUEST_RETRY_WAIT_BACKOFF,async()=>{try{const t={method:e,params:r,id:_nextId++,jsonrpc:"2.0"},n=await web_1.fetchJson(this.connection,JSON.stringify(t));if(n.error){if("object"==typeof n.error.data){if("string"==typeof n.error.data.error_message&&"string"==typeof n.error.data.error_type)throw new errors_1.TypedError(n.error.data.error_message,n.error.data.error_type);throw rpc_errors_1.parseRpcError(n.error.data)}{const e=`[${n.error.code}] ${n.error.message}: ${n.error.data}`;if("Timeout"===n.error.data||e.includes("Timeout error")||e.includes("query has timed out"))throw new errors_1.TypedError(e,"TimeoutError");throw new errors_1.TypedError(e,rpc_errors_1.getErrorTypeFromErrorMessage(n.error.data))}}return n}catch(t){if("TimeoutError"===t.type)return process.env.NEAR_NO_LOGS||console.warn(`Retrying request to ${e} as it has timed out`,r),null;throw t}}),{result:n}=t;if(void 0===n)throw new errors_1.TypedError(`Exceeded ${REQUEST_RETRY_NUMBER} attempts for request to ${e}.`,"RetriesExceeded");return n}}exports.JsonRpcProvider=JsonRpcProvider;
|
|
932
932
|
|
|
933
|
-
}).call(this)}).call(this,require("buffer").Buffer)
|
|
934
|
-
},{"../utils/errors":25,"../utils/exponential-backoff":26,"../utils/rpc_errors":30,"../utils/web":32,"./provider":20,"borsh":38,"buffer":41,"depd":47}],20:[function(require,module,exports){
|
|
933
|
+
}).call(this)}).call(this,require('_process'),require("buffer").Buffer)
|
|
934
|
+
},{"../utils/errors":25,"../utils/exponential-backoff":26,"../utils/rpc_errors":30,"../utils/web":32,"./provider":20,"_process":67,"borsh":38,"buffer":41,"depd":47}],20:[function(require,module,exports){
|
|
935
935
|
(function (Buffer){(function (){
|
|
936
936
|
"use strict";var ExecutionStatusBasic,FinalExecutionStatusBasic,IdType;Object.defineProperty(exports,"__esModule",{value:!0}),exports.getTransactionLastResult=exports.Provider=exports.IdType=exports.FinalExecutionStatusBasic=exports.ExecutionStatusBasic=void 0,function(t){t.Unknown="Unknown",t.Pending="Pending",t.Failure="Failure"}(ExecutionStatusBasic=exports.ExecutionStatusBasic||(exports.ExecutionStatusBasic={})),function(t){t.NotStarted="NotStarted",t.Started="Started",t.Failure="Failure"}(FinalExecutionStatusBasic=exports.FinalExecutionStatusBasic||(exports.FinalExecutionStatusBasic={})),function(t){t.Transaction="transaction",t.Receipt="receipt"}(IdType=exports.IdType||(exports.IdType={}));class Provider{}function getTransactionLastResult(t){if("object"==typeof t.status&&"string"==typeof t.status.SuccessValue){const e=Buffer.from(t.status.SuccessValue,"base64").toString();try{return JSON.parse(e)}catch(t){return e}}return null}exports.Provider=Provider,exports.getTransactionLastResult=getTransactionLastResult;
|
|
937
937
|
|
|
@@ -1030,7 +1030,7 @@ module.exports={
|
|
|
1030
1030
|
"use strict";var __createBinding=this&&this.__createBinding||(Object.create?function(e,r,t,i){void 0===i&&(i=t),Object.defineProperty(e,i,{enumerable:!0,get:function(){return r[t]}})}:function(e,r,t,i){void 0===i&&(i=t),e[i]=r[t]}),__setModuleDefault=this&&this.__setModuleDefault||(Object.create?function(e,r){Object.defineProperty(e,"default",{enumerable:!0,value:r})}:function(e,r){e.default=r}),__importStar=this&&this.__importStar||function(e){if(e&&e.__esModule)return e;var r={};if(null!=e)for(var t in e)"default"!==t&&Object.hasOwnProperty.call(e,t)&&__createBinding(r,e,t);return __setModuleDefault(r,e),r};Object.defineProperty(exports,"__esModule",{value:!0}),exports.logWarning=exports.rpc_errors=exports.KeyPairEd25519=exports.KeyPair=exports.PublicKey=exports.format=exports.enums=exports.web=exports.serialize=exports.key_pair=void 0;const key_pair=__importStar(require("./key_pair"));exports.key_pair=key_pair;const serialize=__importStar(require("./serialize"));exports.serialize=serialize;const web=__importStar(require("./web"));exports.web=web;const enums=__importStar(require("./enums"));exports.enums=enums;const format=__importStar(require("./format"));exports.format=format;const rpc_errors=__importStar(require("./rpc_errors"));exports.rpc_errors=rpc_errors;const key_pair_1=require("./key_pair");Object.defineProperty(exports,"PublicKey",{enumerable:!0,get:function(){return key_pair_1.PublicKey}}),Object.defineProperty(exports,"KeyPair",{enumerable:!0,get:function(){return key_pair_1.KeyPair}}),Object.defineProperty(exports,"KeyPairEd25519",{enumerable:!0,get:function(){return key_pair_1.KeyPairEd25519}});const errors_1=require("./errors");Object.defineProperty(exports,"logWarning",{enumerable:!0,get:function(){return errors_1.logWarning}});
|
|
1031
1031
|
|
|
1032
1032
|
},{"./enums":24,"./errors":25,"./format":27,"./key_pair":29,"./rpc_errors":30,"./serialize":31,"./web":32}],29:[function(require,module,exports){
|
|
1033
|
-
"use strict";var __importDefault=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(exports,"__esModule",{value:!0}),exports.KeyPairEd25519=exports.KeyPair=exports.PublicKey=exports.KeyType=void 0;const tweetnacl_1=__importDefault(require("tweetnacl")),serialize_1=require("./serialize"),enums_1=require("./enums");var KeyType;function key_type_to_str(e){switch(e){case KeyType.ED25519:return"ed25519";default:throw new Error(`Unknown key type ${e}`)}}function str_to_key_type(e){switch(e.toLowerCase()){case"ed25519":return KeyType.ED25519;default:throw new Error(`Unknown key type ${e}`)}}!function(e){e[e.ED25519=0]="ED25519"}(KeyType=exports.KeyType||(exports.KeyType={}));class PublicKey extends enums_1.Assignable{static from(e){return"string"==typeof e?PublicKey.fromString(e):e}static fromString(e){const t=e.split(":");if(1===t.length)return new PublicKey({keyType:KeyType.ED25519,data:serialize_1.base_decode(t[0])});if(2===t.length)return new PublicKey({keyType:str_to_key_type(t[0]),data:serialize_1.base_decode(t[1])});throw new Error("Invalid encoded key format, must be <curve>:<encoded key>")}toString(){return`${key_type_to_str(this.keyType)}:${serialize_1.base_encode(this.data)}`}}exports.PublicKey=PublicKey;class KeyPair{static fromRandom(e){switch(e.toUpperCase()){case"ED25519":return KeyPairEd25519.fromRandom();default:throw new Error(`Unknown curve ${e}`)}}static fromString(e){const t=e.split(":");if(1===t.length)return new KeyPairEd25519(t[0]);if(2!==t.length)throw new Error("Invalid encoded key format, must be <curve>:<encoded key>");switch(t[0].toUpperCase()){case"ED25519":return new KeyPairEd25519(t[1]);default:throw new Error(`Unknown curve: ${t[0]}`)}}}exports.KeyPair=KeyPair;class KeyPairEd25519 extends KeyPair{constructor(e){super();const t=tweetnacl_1.default.sign.keyPair.fromSecretKey(serialize_1.base_decode(e));this.publicKey=new PublicKey({keyType:KeyType.ED25519,data:t.publicKey}),this.secretKey=e}static fromRandom(){const e=tweetnacl_1.default.sign.keyPair();return new KeyPairEd25519(serialize_1.base_encode(e.secretKey))}sign(e){return{signature:tweetnacl_1.default.sign.detached(e,serialize_1.base_decode(this.secretKey)),publicKey:this.publicKey}}verify(e,t){return
|
|
1033
|
+
"use strict";var __importDefault=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(exports,"__esModule",{value:!0}),exports.KeyPairEd25519=exports.KeyPair=exports.PublicKey=exports.KeyType=void 0;const tweetnacl_1=__importDefault(require("tweetnacl")),serialize_1=require("./serialize"),enums_1=require("./enums");var KeyType;function key_type_to_str(e){switch(e){case KeyType.ED25519:return"ed25519";default:throw new Error(`Unknown key type ${e}`)}}function str_to_key_type(e){switch(e.toLowerCase()){case"ed25519":return KeyType.ED25519;default:throw new Error(`Unknown key type ${e}`)}}!function(e){e[e.ED25519=0]="ED25519"}(KeyType=exports.KeyType||(exports.KeyType={}));class PublicKey extends enums_1.Assignable{static from(e){return"string"==typeof e?PublicKey.fromString(e):e}static fromString(e){const t=e.split(":");if(1===t.length)return new PublicKey({keyType:KeyType.ED25519,data:serialize_1.base_decode(t[0])});if(2===t.length)return new PublicKey({keyType:str_to_key_type(t[0]),data:serialize_1.base_decode(t[1])});throw new Error("Invalid encoded key format, must be <curve>:<encoded key>")}toString(){return`${key_type_to_str(this.keyType)}:${serialize_1.base_encode(this.data)}`}verify(e,t){switch(this.keyType){case KeyType.ED25519:return tweetnacl_1.default.sign.detached.verify(e,t,this.data);default:throw new Error(`Unknown key type ${this.keyType}`)}}}exports.PublicKey=PublicKey;class KeyPair{static fromRandom(e){switch(e.toUpperCase()){case"ED25519":return KeyPairEd25519.fromRandom();default:throw new Error(`Unknown curve ${e}`)}}static fromString(e){const t=e.split(":");if(1===t.length)return new KeyPairEd25519(t[0]);if(2!==t.length)throw new Error("Invalid encoded key format, must be <curve>:<encoded key>");switch(t[0].toUpperCase()){case"ED25519":return new KeyPairEd25519(t[1]);default:throw new Error(`Unknown curve: ${t[0]}`)}}}exports.KeyPair=KeyPair;class KeyPairEd25519 extends KeyPair{constructor(e){super();const t=tweetnacl_1.default.sign.keyPair.fromSecretKey(serialize_1.base_decode(e));this.publicKey=new PublicKey({keyType:KeyType.ED25519,data:t.publicKey}),this.secretKey=e}static fromRandom(){const e=tweetnacl_1.default.sign.keyPair();return new KeyPairEd25519(serialize_1.base_encode(e.secretKey))}sign(e){return{signature:tweetnacl_1.default.sign.detached(e,serialize_1.base_decode(this.secretKey)),publicKey:this.publicKey}}verify(e,t){return this.publicKey.verify(e,t)}toString(){return`ed25519:${this.secretKey}`}getPublicKey(){return this.publicKey}}exports.KeyPairEd25519=KeyPairEd25519;
|
|
1034
1034
|
|
|
1035
1035
|
},{"./enums":24,"./serialize":31,"tweetnacl":74}],30:[function(require,module,exports){
|
|
1036
1036
|
"use strict";var __importDefault=this&&this.__importDefault||function(r){return r&&r.__esModule?r:{default:r}};Object.defineProperty(exports,"__esModule",{value:!0}),exports.getErrorTypeFromErrorMessage=exports.formatError=exports.parseResultError=exports.parseRpcError=exports.ServerError=void 0;const mustache_1=__importDefault(require("mustache")),rpc_error_schema_json_1=__importDefault(require("../generated/rpc_error_schema.json")),error_messages_json_1=__importDefault(require("../res/error_messages.json")),common_index_1=require("../common-index"),errors_1=require("../utils/errors"),mustacheHelpers={formatNear:()=>(r,e)=>common_index_1.utils.format.formatNearAmount(e(r))};class ServerError extends errors_1.TypedError{}exports.ServerError=ServerError;class ServerTransactionError extends ServerError{}function parseRpcError(r){const e={},t=walkSubtype(r,rpc_error_schema_json_1.default.schema,e,""),o=new ServerError(formatError(t,e),t);return Object.assign(o,e),o}function parseResultError(r){const e=parseRpcError(r.status.Failure),t=new ServerTransactionError;return Object.assign(t,e),t.type=e.type,t.message=e.message,t.transaction_outcome=r.transaction_outcome,t}function formatError(r,e){return"string"==typeof error_messages_json_1.default[r]?mustache_1.default.render(error_messages_json_1.default[r],{...e,...mustacheHelpers}):JSON.stringify(e)}function walkSubtype(r,e,t,o){let s,n,a;for(const t in e){if(isString(r[t]))return r[t];if(isObject(r[t]))s=r[t],n=e[t],a=t;else{if(!isObject(r.kind)||!isObject(r.kind[t]))continue;s=r.kind[t],n=e[t],a=t}}if(s&&n){for(const r of Object.keys(n.props))t[r]=s[r];return walkSubtype(s,e,t,a)}return t.kind=r,o}function getErrorTypeFromErrorMessage(r){switch(!0){case/^account .*? does not exist while viewing$/.test(r):case/^Account .*? doesn't exist$/.test(r):return"AccountDoesNotExist";case/^access key .*? does not exist while viewing$/.test(r):return"AccessKeyDoesNotExist";case/wasm execution failed with error: FunctionCallError\(CompilationError\(CodeDoesNotExist/.test(r):return"CodeDoesNotExist";case/Transaction nonce \d+ must be larger than nonce of the used access key \d+/.test(r):return"InvalidNonce";default:return"UntypedError"}}function isObject(r){return"[object Object]"===Object.prototype.toString.call(r)}function isString(r){return"[object String]"===Object.prototype.toString.call(r)}exports.parseRpcError=parseRpcError,exports.parseResultError=parseResultError,exports.formatError=formatError,exports.getErrorTypeFromErrorMessage=getErrorTypeFromErrorMessage;
|
|
@@ -1039,18 +1039,18 @@ module.exports={
|
|
|
1039
1039
|
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var borsh_1=require("borsh");Object.defineProperty(exports,"base_encode",{enumerable:!0,get:function(){return borsh_1.baseEncode}}),Object.defineProperty(exports,"base_decode",{enumerable:!0,get:function(){return borsh_1.baseDecode}}),Object.defineProperty(exports,"serialize",{enumerable:!0,get:function(){return borsh_1.serialize}}),Object.defineProperty(exports,"deserialize",{enumerable:!0,get:function(){return borsh_1.deserialize}}),Object.defineProperty(exports,"BorshError",{enumerable:!0,get:function(){return borsh_1.BorshError}}),Object.defineProperty(exports,"BinaryWriter",{enumerable:!0,get:function(){return borsh_1.BinaryWriter}}),Object.defineProperty(exports,"BinaryReader",{enumerable:!0,get:function(){return borsh_1.BinaryReader}});
|
|
1040
1040
|
|
|
1041
1041
|
},{"borsh":38}],32:[function(require,module,exports){
|
|
1042
|
-
"use strict";var __importDefault=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(exports,"__esModule",{value:!0}),exports.fetchJson=void 0;const http_errors_1=__importDefault(require("http-errors")),exponential_backoff_1=__importDefault(require("./exponential-backoff")),providers_1=require("../providers"),errors_1=require("./errors"),START_WAIT_TIME_MS=1e3,BACKOFF_MULTIPLIER=1.5,RETRY_NUMBER=10;async function fetchJson(e,r){let t=null;
|
|
1042
|
+
"use strict";var __importDefault=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(exports,"__esModule",{value:!0}),exports.fetchJson=void 0;const http_errors_1=__importDefault(require("http-errors")),exponential_backoff_1=__importDefault(require("./exponential-backoff")),providers_1=require("../providers"),errors_1=require("./errors"),START_WAIT_TIME_MS=1e3,BACKOFF_MULTIPLIER=1.5,RETRY_NUMBER=10;async function fetchJson(e,r){let t={url:null};"string"==typeof e?t.url=e:t=e;const o=await exponential_backoff_1.default(START_WAIT_TIME_MS,RETRY_NUMBER,BACKOFF_MULTIPLIER,async()=>{try{const e=await fetch(t.url,{method:r?"POST":"GET",body:r||void 0,headers:{...t.headers,"Content-Type":"application/json"}});if(!e.ok){if(503===e.status)return errors_1.logWarning(`Retrying HTTP request for ${t.url} as it's not available now`),null;throw http_errors_1.default(e.status,await e.text())}return e}catch(e){if(e.toString().includes("FetchError")||e.toString().includes("Failed to fetch"))return errors_1.logWarning(`Retrying HTTP request for ${t.url} because of error: ${e}`),null;throw e}});if(!o)throw new providers_1.TypedError(`Exceeded ${RETRY_NUMBER} attempts for ${t.url}.`,"RetriesExceeded");return await o.json()}exports.fetchJson=fetchJson;
|
|
1043
1043
|
|
|
1044
1044
|
},{"../providers":18,"./errors":25,"./exponential-backoff":26,"http-errors":57}],33:[function(require,module,exports){
|
|
1045
|
-
"use strict";var __importDefault=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(exports,"__esModule",{value:!0}),exports.diffEpochValidators=exports.findSeatPrice=void 0;const bn_js_1=__importDefault(require("bn.js"));function findSeatPrice(e,t){const a=e.map(e=>new bn_js_1.default(e.stake,10)).sort((e,t)=>e.cmp(t)),
|
|
1045
|
+
"use strict";var __importDefault=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(exports,"__esModule",{value:!0}),exports.diffEpochValidators=exports.findSeatPrice=void 0;const bn_js_1=__importDefault(require("bn.js")),depd_1=__importDefault(require("depd"));function findSeatPrice(e,t,a,r){if(r&&r<49)return findSeatPriceForProtocolBefore49(e,t);if(!a){depd_1.default("findSeatPrice(validators, maxNumberOfSeats)")("`use `findSeatPrice(validators, maxNumberOfSeats, minimumStakeRatio)` instead"),a=[1,6250]}return findSeatPriceForProtocolAfter49(e,t,a)}function findSeatPriceForProtocolBefore49(e,t){const a=e.map(e=>new bn_js_1.default(e.stake,10)).sort((e,t)=>e.cmp(t)),r=new bn_js_1.default(t),n=a.reduce((e,t)=>e.add(t));if(n.lt(r))throw new Error("Stakes are below seats");let o=new bn_js_1.default(1),d=n.add(new bn_js_1.default(1));for(;!o.eq(d.sub(new bn_js_1.default(1)));){const e=o.add(d).div(new bn_js_1.default(2));let t=!1,n=new bn_js_1.default(0);for(let d=0;d<a.length;++d)if((n=n.add(a[d].div(e))).gte(r)){o=e,t=!0;break}t||(d=e)}return o}function findSeatPriceForProtocolAfter49(e,t,a){if(2!=a.length)throw Error("minimumStakeRatio should have 2 elements");const r=e.map(e=>new bn_js_1.default(e.stake,10)).sort((e,t)=>e.cmp(t)),n=r.reduce((e,t)=>e.add(t));return e.length<t?n.mul(new bn_js_1.default(a[0])).div(new bn_js_1.default(a[1])):r[0].add(new bn_js_1.default(1))}function diffEpochValidators(e,t){const a=new Map;e.forEach(e=>a.set(e.account_id,e));const r=new Set(t.map(e=>e.account_id));return{newValidators:t.filter(e=>!a.has(e.account_id)),removedValidators:e.filter(e=>!r.has(e.account_id)),changedValidators:t.filter(e=>a.has(e.account_id)&&a.get(e.account_id).stake!=e.stake).map(e=>({current:a.get(e.account_id),next:e}))}}exports.findSeatPrice=findSeatPrice,exports.diffEpochValidators=diffEpochValidators;
|
|
1046
1046
|
|
|
1047
|
-
},{"bn.js":37}],34:[function(require,module,exports){
|
|
1047
|
+
},{"bn.js":37,"depd":47}],34:[function(require,module,exports){
|
|
1048
1048
|
(function (Buffer){(function (){
|
|
1049
|
-
"use strict";var __importDefault=this&&this.__importDefault||function(t){return t&&t.__esModule?t:{default:t}};Object.defineProperty(exports,"__esModule",{value:!0}),exports.ConnectedWalletAccount=exports.WalletAccount=exports.WalletConnection=void 0;const depd_1=__importDefault(require("depd")),account_1=require("./account"),transaction_1=require("./transaction"),utils_1=require("./utils"),borsh_1=require("borsh"),borsh_2=require("borsh"),LOGIN_WALLET_URL_SUFFIX="/login/",MULTISIG_HAS_METHOD="add_request_and_confirm",LOCAL_STORAGE_KEY_SUFFIX="_wallet_auth_key",PENDING_ACCESS_KEY_PREFIX="pending_key";class WalletConnection{constructor(t,e){this._near=t;const
|
|
1049
|
+
"use strict";var __importDefault=this&&this.__importDefault||function(t){return t&&t.__esModule?t:{default:t}};Object.defineProperty(exports,"__esModule",{value:!0}),exports.ConnectedWalletAccount=exports.WalletAccount=exports.WalletConnection=void 0;const depd_1=__importDefault(require("depd")),account_1=require("./account"),transaction_1=require("./transaction"),utils_1=require("./utils"),borsh_1=require("borsh"),borsh_2=require("borsh"),LOGIN_WALLET_URL_SUFFIX="/login/",MULTISIG_HAS_METHOD="add_request_and_confirm",LOCAL_STORAGE_KEY_SUFFIX="_wallet_auth_key",PENDING_ACCESS_KEY_PREFIX="pending_key";class WalletConnection{constructor(t,e){this._near=t;const a=e+LOCAL_STORAGE_KEY_SUFFIX,n=JSON.parse(window.localStorage.getItem(a));this._networkId=t.config.networkId,this._walletBaseUrl=t.config.walletUrl,e=e||t.config.contractName||"default",this._keyStore=t.connection.signer.keyStore,this._authData=n||{allKeys:[]},this._authDataKey=a,this.isSignedIn()||this._completeSignInWithAccessKey()}isSignedIn(){return!!this._authData.accountId}getAccountId(){return this._authData.accountId||""}async requestSignIn(t={},e,a,n){let s;if("string"==typeof t){depd_1.default("requestSignIn(contractId, title)")("`title` ignored; use `requestSignIn({ contractId, methodNames, successUrl, failureUrl })` instead"),s={contractId:t,successUrl:a,failureUrl:n}}else s=t;const c=new URL(window.location.href),i=new URL(this._walletBaseUrl+LOGIN_WALLET_URL_SUFFIX);if(i.searchParams.set("success_url",s.successUrl||c.href),i.searchParams.set("failure_url",s.failureUrl||c.href),s.contractId){const t=await this._near.account(s.contractId);await t.state(),i.searchParams.set("contract_id",s.contractId);const e=utils_1.KeyPair.fromRandom("ed25519");i.searchParams.set("public_key",e.getPublicKey().toString()),await this._keyStore.setKey(this._networkId,PENDING_ACCESS_KEY_PREFIX+e.getPublicKey(),e)}s.methodNames&&s.methodNames.forEach(t=>{i.searchParams.append("methodNames",t)}),window.location.assign(i.toString())}async requestSignTransactions(...t){if(Array.isArray(t[0])){return depd_1.default("WalletConnection.requestSignTransactions(transactions, callbackUrl, meta)")("use `WalletConnection.requestSignTransactions(RequestSignTransactionsOptions)` instead"),this._requestSignTransactions({transactions:t[0],callbackUrl:t[1],meta:t[2]})}return this._requestSignTransactions(t[0])}async _requestSignTransactions({transactions:t,meta:e,callbackUrl:a}){const n=new URL(window.location.href),s=new URL("sign",this._walletBaseUrl);s.searchParams.set("transactions",t.map(t=>borsh_2.serialize(transaction_1.SCHEMA,t)).map(t=>Buffer.from(t).toString("base64")).join(",")),s.searchParams.set("callbackUrl",a||n.href),e&&s.searchParams.set("meta",e),window.location.assign(s.toString())}async _completeSignInWithAccessKey(){const t=new URL(window.location.href),e=t.searchParams.get("public_key")||"",a=(t.searchParams.get("all_keys")||"").split(","),n=t.searchParams.get("account_id")||"";n&&(this._authData={accountId:n,allKeys:a},window.localStorage.setItem(this._authDataKey,JSON.stringify(this._authData)),e&&await this._moveKeyFromTempToPermanent(n,e)),t.searchParams.delete("public_key"),t.searchParams.delete("all_keys"),t.searchParams.delete("account_id"),t.searchParams.delete("meta"),t.searchParams.delete("transactionHashes"),window.history.replaceState({},document.title,t.toString())}async _moveKeyFromTempToPermanent(t,e){const a=await this._keyStore.getKey(this._networkId,PENDING_ACCESS_KEY_PREFIX+e);await this._keyStore.setKey(this._networkId,t,a),await this._keyStore.removeKey(this._networkId,PENDING_ACCESS_KEY_PREFIX+e)}signOut(){this._authData={},window.localStorage.removeItem(this._authDataKey)}account(){return this._connectedAccount||(this._connectedAccount=new ConnectedWalletAccount(this,this._near.connection,this._authData.accountId)),this._connectedAccount}}exports.WalletConnection=WalletConnection,exports.WalletAccount=WalletConnection;class ConnectedWalletAccount extends account_1.Account{constructor(t,e,a){super(e,a),this.walletConnection=t}signAndSendTransaction(...t){return"string"==typeof t[0]?this._signAndSendTransaction({receiverId:t[0],actions:t[1]}):this._signAndSendTransaction(t[0])}async _signAndSendTransaction({receiverId:t,actions:e,walletMeta:a,walletCallbackUrl:n=window.location.href}){const s=await this.connection.signer.getPublicKey(this.accountId,this.connection.networkId);let c=await this.accessKeyForTransaction(t,e,s);if(!c)throw new Error(`Cannot find matching key for transaction sent to ${t}`);if(s&&s.toString()===c.public_key)try{return await super.signAndSendTransaction({receiverId:t,actions:e})}catch(a){if("NotEnoughAllowance"!==a.type)throw a;c=await this.accessKeyForTransaction(t,e)}const i=await this.connection.provider.block({finality:"final"}),r=borsh_1.baseDecode(i.header.hash),o=utils_1.PublicKey.from(c.public_key),l=c.access_key.nonce+1,u=transaction_1.createTransaction(this.accountId,o,t,l,e,r);return await this.walletConnection.requestSignTransactions({transactions:[u],meta:a,callbackUrl:n}),new Promise((t,e)=>{setTimeout(()=>{e(new Error("Failed to redirect to sign transaction"))},1e3)})}async accessKeyMatchesTransaction(t,e,a){const{access_key:{permission:n}}=t;if("FullAccess"===n)return!0;if(n.FunctionCall){const{receiver_id:t,method_names:s}=n.FunctionCall;if(t===this.accountId&&s.includes(MULTISIG_HAS_METHOD))return!0;if(t===e){if(1!==a.length)return!1;const[{functionCall:t}]=a;return t&&(!t.deposit||"0"===t.deposit.toString())&&(0===s.length||s.includes(t.methodName))}}return!1}async accessKeyForTransaction(t,e,a){const n=await this.getAccessKeys();if(a){const s=n.find(t=>t.public_key.toString()===a.toString());if(s&&await this.accessKeyMatchesTransaction(s,t,e))return s}const s=this.walletConnection._authData.allKeys;for(const a of n)if(-1!==s.indexOf(a.public_key)&&await this.accessKeyMatchesTransaction(a,t,e))return a;return null}}exports.ConnectedWalletAccount=ConnectedWalletAccount;
|
|
1050
1050
|
|
|
1051
1051
|
}).call(this)}).call(this,require("buffer").Buffer)
|
|
1052
1052
|
},{"./account":2,"./transaction":23,"./utils":28,"borsh":38,"buffer":41,"depd":47}],35:[function(require,module,exports){
|
|
1053
|
-
"use strict";var _Buffer=require("safe-buffer").Buffer;function base(r){if(r.length>=255)throw new TypeError("Alphabet too long");for(var e=new Uint8Array(256),o=0;o<e.length;o++)e[o]=255;for(var
|
|
1053
|
+
"use strict";var _Buffer=require("safe-buffer").Buffer;function base(r){if(r.length>=255)throw new TypeError("Alphabet too long");for(var e=new Uint8Array(256),o=0;o<e.length;o++)e[o]=255;for(var t=0;t<r.length;t++){var f=r.charAt(t),a=f.charCodeAt(0);if(255!==e[a])throw new TypeError(f+" is ambiguous");e[a]=t}var n=r.length,i=r.charAt(0),h=Math.log(n)/Math.log(256),u=Math.log(256)/Math.log(n);function c(r){if("string"!=typeof r)throw new TypeError("Expected String");if(0===r.length)return _Buffer.alloc(0);for(var o=0,t=0,f=0;r[o]===i;)t++,o++;for(var a=(r.length-o)*h+1>>>0,u=new Uint8Array(a);r[o];){var c=e[r.charCodeAt(o)];if(255===c)return;for(var l=0,v=a-1;(0!==c||l<f)&&-1!==v;v--,l++)c+=n*u[v]>>>0,u[v]=c%256>>>0,c=c/256>>>0;if(0!==c)throw new Error("Non-zero carry");f=l,o++}for(var w=a-f;w!==a&&0===u[w];)w++;var g=_Buffer.allocUnsafe(t+(a-w));g.fill(0,0,t);for(var s=t;w!==a;)g[s++]=u[w++];return g}return{encode:function(e){if((Array.isArray(e)||e instanceof Uint8Array)&&(e=_Buffer.from(e)),!_Buffer.isBuffer(e))throw new TypeError("Expected Buffer");if(0===e.length)return"";for(var o=0,t=0,f=0,a=e.length;f!==a&&0===e[f];)f++,o++;for(var h=(a-f)*u+1>>>0,c=new Uint8Array(h);f!==a;){for(var l=e[f],v=0,w=h-1;(0!==l||v<t)&&-1!==w;w--,v++)l+=256*c[w]>>>0,c[w]=l%n>>>0,l=l/n>>>0;if(0!==l)throw new Error("Non-zero carry");t=v,f++}for(var g=h-t;g!==h&&0===c[g];)g++;for(var s=i.repeat(o);g<h;++g)s+=r.charAt(c[g]);return s},decodeUnsafe:c,decode:function(r){var e=c(r);if(e)return e;throw new Error("Non-base"+n+" character")}}}module.exports=base;
|
|
1054
1054
|
|
|
1055
1055
|
},{"safe-buffer":68}],36:[function(require,module,exports){
|
|
1056
1056
|
"use strict";exports.byteLength=byteLength,exports.toByteArray=toByteArray,exports.fromByteArray=fromByteArray;for(var lookup=[],revLookup=[],Arr="undefined"!=typeof Uint8Array?Uint8Array:Array,code="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",i=0,len=code.length;i<len;++i)lookup[i]=code[i],revLookup[code.charCodeAt(i)]=i;function getLens(o){var r=o.length;if(r%4>0)throw new Error("Invalid string. Length must be a multiple of 4");var e=o.indexOf("=");return-1===e&&(e=r),[e,e===r?0:4-e%4]}function byteLength(o){var r=getLens(o),e=r[0],t=r[1];return 3*(e+t)/4-t}function _byteLength(o,r,e){return 3*(r+e)/4-e}function toByteArray(o){var r,e,t=getLens(o),n=t[0],u=t[1],p=new Arr(_byteLength(o,n,u)),a=0,h=u>0?n-4:n;for(e=0;e<h;e+=4)r=revLookup[o.charCodeAt(e)]<<18|revLookup[o.charCodeAt(e+1)]<<12|revLookup[o.charCodeAt(e+2)]<<6|revLookup[o.charCodeAt(e+3)],p[a++]=r>>16&255,p[a++]=r>>8&255,p[a++]=255&r;return 2===u&&(r=revLookup[o.charCodeAt(e)]<<2|revLookup[o.charCodeAt(e+1)]>>4,p[a++]=255&r),1===u&&(r=revLookup[o.charCodeAt(e)]<<10|revLookup[o.charCodeAt(e+1)]<<4|revLookup[o.charCodeAt(e+2)]>>2,p[a++]=r>>8&255,p[a++]=255&r),p}function tripletToBase64(o){return lookup[o>>18&63]+lookup[o>>12&63]+lookup[o>>6&63]+lookup[63&o]}function encodeChunk(o,r,e){for(var t,n=[],u=r;u<e;u+=3)t=(o[u]<<16&16711680)+(o[u+1]<<8&65280)+(255&o[u+2]),n.push(tripletToBase64(t));return n.join("")}function fromByteArray(o){for(var r,e=o.length,t=e%3,n=[],u=0,p=e-t;u<p;u+=16383)n.push(encodeChunk(o,u,u+16383>p?p:u+16383));return 1===t?(r=o[e-1],n.push(lookup[r>>2]+lookup[r<<4&63]+"==")):2===t&&(r=(o[e-2]<<8)+o[e-1],n.push(lookup[r>>10]+lookup[r>>4&63]+lookup[r<<2&63]+"=")),n.join("")}revLookup["-".charCodeAt(0)]=62,revLookup["_".charCodeAt(0)]=63;
|
|
@@ -1234,7 +1234,7 @@ module.exports={
|
|
|
1234
1234
|
"use strict";function inRange(e,r,n){return r<=e&&e<=n}function ToDictionary(e){if(void 0===e)return{};if(e===Object(e))return e;throw TypeError("Could not convert argument to dictionary")}function stringToCodePoints(e){for(var r=String(e),n=r.length,t=0,i=[];t<n;){var o=r.charCodeAt(t);if(o<55296||o>57343)i.push(o);else if(56320<=o&&o<=57343)i.push(65533);else if(55296<=o&&o<=56319)if(t===n-1)i.push(65533);else{var s=e.charCodeAt(t+1);if(56320<=s&&s<=57343){var a=1023&o,f=1023&s;i.push(65536+(a<<10)+f),t+=1}else i.push(65533)}t+=1}return i}function codePointsToString(e){for(var r="",n=0;n<e.length;++n){var t=e[n];t<=65535?r+=String.fromCharCode(t):(t-=65536,r+=String.fromCharCode(55296+(t>>10),56320+(1023&t)))}return r}var end_of_stream=-1;function Stream(e){this.tokens=[].slice.call(e)}Stream.prototype={endOfStream:function(){return!this.tokens.length},read:function(){return this.tokens.length?this.tokens.shift():end_of_stream},prepend:function(e){if(Array.isArray(e))for(var r=e;r.length;)this.tokens.unshift(r.pop());else this.tokens.unshift(e)},push:function(e){if(Array.isArray(e))for(var r=e;r.length;)this.tokens.push(r.shift());else this.tokens.push(e)}};var finished=-1;function decoderError(e,r){if(e)throw TypeError("Decoder error");return r||65533}var DEFAULT_ENCODING="utf-8";function TextDecoder(e,r){if(!(this instanceof TextDecoder))return new TextDecoder(e,r);if((e=void 0!==e?String(e).toLowerCase():DEFAULT_ENCODING)!==DEFAULT_ENCODING)throw new Error("Encoding not supported. Only utf-8 is supported");r=ToDictionary(r),this._streaming=!1,this._BOMseen=!1,this._decoder=null,this._fatal=Boolean(r.fatal),this._ignoreBOM=Boolean(r.ignoreBOM),Object.defineProperty(this,"encoding",{value:"utf-8"}),Object.defineProperty(this,"fatal",{value:this._fatal}),Object.defineProperty(this,"ignoreBOM",{value:this._ignoreBOM})}function TextEncoder(e,r){if(!(this instanceof TextEncoder))return new TextEncoder(e,r);if((e=void 0!==e?String(e).toLowerCase():DEFAULT_ENCODING)!==DEFAULT_ENCODING)throw new Error("Encoding not supported. Only utf-8 is supported");r=ToDictionary(r),this._streaming=!1,this._encoder=null,this._options={fatal:Boolean(r.fatal)},Object.defineProperty(this,"encoding",{value:"utf-8"})}function UTF8Decoder(e){var r=e.fatal,n=0,t=0,i=0,o=128,s=191;this.handler=function(e,a){if(a===end_of_stream&&0!==i)return i=0,decoderError(r);if(a===end_of_stream)return finished;if(0===i){if(inRange(a,0,127))return a;if(inRange(a,194,223))i=1,n=a-192;else if(inRange(a,224,239))224===a&&(o=160),237===a&&(s=159),i=2,n=a-224;else{if(!inRange(a,240,244))return decoderError(r);240===a&&(o=144),244===a&&(s=143),i=3,n=a-240}return n<<=6*i,null}if(!inRange(a,o,s))return n=i=t=0,o=128,s=191,e.prepend(a),decoderError(r);if(o=128,s=191,n+=a-128<<6*(i-(t+=1)),t!==i)return null;var f=n;return n=i=t=0,f}}function UTF8Encoder(e){e.fatal;this.handler=function(e,r){if(r===end_of_stream)return finished;if(inRange(r,0,127))return r;var n,t;inRange(r,128,2047)?(n=1,t=192):inRange(r,2048,65535)?(n=2,t=224):inRange(r,65536,1114111)&&(n=3,t=240);for(var i=[(r>>6*n)+t];n>0;){var o=r>>6*(n-1);i.push(128|63&o),n-=1}return i}}TextDecoder.prototype={decode:function(e,r){var n;n="object"==typeof e&&e instanceof ArrayBuffer?new Uint8Array(e):"object"==typeof e&&"buffer"in e&&e.buffer instanceof ArrayBuffer?new Uint8Array(e.buffer,e.byteOffset,e.byteLength):new Uint8Array(0),r=ToDictionary(r),this._streaming||(this._decoder=new UTF8Decoder({fatal:this._fatal}),this._BOMseen=!1),this._streaming=Boolean(r.stream);for(var t,i=new Stream(n),o=[];!i.endOfStream()&&(t=this._decoder.handler(i,i.read()))!==finished;)null!==t&&(Array.isArray(t)?o.push.apply(o,t):o.push(t));if(!this._streaming){do{if((t=this._decoder.handler(i,i.read()))===finished)break;null!==t&&(Array.isArray(t)?o.push.apply(o,t):o.push(t))}while(!i.endOfStream());this._decoder=null}return o.length&&(-1===["utf-8"].indexOf(this.encoding)||this._ignoreBOM||this._BOMseen||(65279===o[0]?(this._BOMseen=!0,o.shift()):this._BOMseen=!0)),codePointsToString(o)}},TextEncoder.prototype={encode:function(e,r){e=e?String(e):"",r=ToDictionary(r),this._streaming||(this._encoder=new UTF8Encoder(this._options)),this._streaming=Boolean(r.stream);for(var n,t=[],i=new Stream(stringToCodePoints(e));!i.endOfStream()&&(n=this._encoder.handler(i,i.read()))!==finished;)Array.isArray(n)?t.push.apply(t,n):t.push(n);if(!this._streaming){for(;(n=this._encoder.handler(i,i.read()))!==finished;)Array.isArray(n)?t.push.apply(t,n):t.push(n);this._encoder=null}return new Uint8Array(t)}},exports.TextEncoder=TextEncoder,exports.TextDecoder=TextDecoder;
|
|
1235
1235
|
|
|
1236
1236
|
},{}],73:[function(require,module,exports){
|
|
1237
|
-
function toIdentifier(e){return e.split(" ").map(function(e){return e.slice(0,1).toUpperCase()+e.slice(1)}).join("").replace(/[^ _0-9a-z]/gi,"")}module.exports=toIdentifier;
|
|
1237
|
+
"use strict";function toIdentifier(e){return e.split(" ").map(function(e){return e.slice(0,1).toUpperCase()+e.slice(1)}).join("").replace(/[^ _0-9a-z]/gi,"")}module.exports=toIdentifier;
|
|
1238
1238
|
|
|
1239
1239
|
},{}],74:[function(require,module,exports){
|
|
1240
1240
|
!function(r){"use strict";var t=function(r){var t,n=new Float64Array(16);if(r)for(t=0;t<r.length;t++)n[t]=r[t];return n},n=function(){throw new Error("no PRNG")},e=new Uint8Array(16),o=new Uint8Array(32);o[0]=9;var i=t(),h=t([1]),a=t([56129,1]),f=t([30883,4953,19914,30187,55467,16705,2637,112,59544,30585,16505,36039,65139,11119,27886,20995]),s=t([61785,9906,39828,60374,45398,33411,5274,224,53552,61171,33010,6542,64743,22239,55772,9222]),u=t([54554,36645,11616,51542,42930,38181,51040,26924,56412,64982,57905,49316,21502,52590,14035,8553]),c=t([26200,26214,26214,26214,26214,26214,26214,26214,26214,26214,26214,26214,26214,26214,26214,26214]),y=t([41136,18958,6951,50414,58488,44335,6150,12099,55207,15867,153,11085,57099,20417,9344,11139]);function l(r,t,n,e){r[t]=n>>24&255,r[t+1]=n>>16&255,r[t+2]=n>>8&255,r[t+3]=255&n,r[t+4]=e>>24&255,r[t+5]=e>>16&255,r[t+6]=e>>8&255,r[t+7]=255&e}function w(r,t,n,e,o){var i,h=0;for(i=0;i<o;i++)h|=r[t+i]^n[e+i];return(1&h-1>>>8)-1}function v(r,t,n,e){return w(r,t,n,e,16)}function p(r,t,n,e){return w(r,t,n,e,32)}function b(r,t,n,e){!function(r,t,n,e){for(var o,i=255&e[0]|(255&e[1])<<8|(255&e[2])<<16|(255&e[3])<<24,h=255&n[0]|(255&n[1])<<8|(255&n[2])<<16|(255&n[3])<<24,a=255&n[4]|(255&n[5])<<8|(255&n[6])<<16|(255&n[7])<<24,f=255&n[8]|(255&n[9])<<8|(255&n[10])<<16|(255&n[11])<<24,s=255&n[12]|(255&n[13])<<8|(255&n[14])<<16|(255&n[15])<<24,u=255&e[4]|(255&e[5])<<8|(255&e[6])<<16|(255&e[7])<<24,c=255&t[0]|(255&t[1])<<8|(255&t[2])<<16|(255&t[3])<<24,y=255&t[4]|(255&t[5])<<8|(255&t[6])<<16|(255&t[7])<<24,l=255&t[8]|(255&t[9])<<8|(255&t[10])<<16|(255&t[11])<<24,w=255&t[12]|(255&t[13])<<8|(255&t[14])<<16|(255&t[15])<<24,v=255&e[8]|(255&e[9])<<8|(255&e[10])<<16|(255&e[11])<<24,p=255&n[16]|(255&n[17])<<8|(255&n[18])<<16|(255&n[19])<<24,b=255&n[20]|(255&n[21])<<8|(255&n[22])<<16|(255&n[23])<<24,g=255&n[24]|(255&n[25])<<8|(255&n[26])<<16|(255&n[27])<<24,A=255&n[28]|(255&n[29])<<8|(255&n[30])<<16|(255&n[31])<<24,_=255&e[12]|(255&e[13])<<8|(255&e[14])<<16|(255&e[15])<<24,U=i,d=h,E=a,x=f,M=s,m=u,B=c,S=y,k=l,K=w,Y=v,L=p,T=b,z=g,R=A,P=_,N=0;N<20;N+=2)U^=(o=(T^=(o=(k^=(o=(M^=(o=U+T|0)<<7|o>>>25)+U|0)<<9|o>>>23)+M|0)<<13|o>>>19)+k|0)<<18|o>>>14,m^=(o=(d^=(o=(z^=(o=(K^=(o=m+d|0)<<7|o>>>25)+m|0)<<9|o>>>23)+K|0)<<13|o>>>19)+z|0)<<18|o>>>14,Y^=(o=(B^=(o=(E^=(o=(R^=(o=Y+B|0)<<7|o>>>25)+Y|0)<<9|o>>>23)+R|0)<<13|o>>>19)+E|0)<<18|o>>>14,P^=(o=(L^=(o=(S^=(o=(x^=(o=P+L|0)<<7|o>>>25)+P|0)<<9|o>>>23)+x|0)<<13|o>>>19)+S|0)<<18|o>>>14,U^=(o=(x^=(o=(E^=(o=(d^=(o=U+x|0)<<7|o>>>25)+U|0)<<9|o>>>23)+d|0)<<13|o>>>19)+E|0)<<18|o>>>14,m^=(o=(M^=(o=(S^=(o=(B^=(o=m+M|0)<<7|o>>>25)+m|0)<<9|o>>>23)+B|0)<<13|o>>>19)+S|0)<<18|o>>>14,Y^=(o=(K^=(o=(k^=(o=(L^=(o=Y+K|0)<<7|o>>>25)+Y|0)<<9|o>>>23)+L|0)<<13|o>>>19)+k|0)<<18|o>>>14,P^=(o=(R^=(o=(z^=(o=(T^=(o=P+R|0)<<7|o>>>25)+P|0)<<9|o>>>23)+T|0)<<13|o>>>19)+z|0)<<18|o>>>14;U=U+i|0,d=d+h|0,E=E+a|0,x=x+f|0,M=M+s|0,m=m+u|0,B=B+c|0,S=S+y|0,k=k+l|0,K=K+w|0,Y=Y+v|0,L=L+p|0,T=T+b|0,z=z+g|0,R=R+A|0,P=P+_|0,r[0]=U>>>0&255,r[1]=U>>>8&255,r[2]=U>>>16&255,r[3]=U>>>24&255,r[4]=d>>>0&255,r[5]=d>>>8&255,r[6]=d>>>16&255,r[7]=d>>>24&255,r[8]=E>>>0&255,r[9]=E>>>8&255,r[10]=E>>>16&255,r[11]=E>>>24&255,r[12]=x>>>0&255,r[13]=x>>>8&255,r[14]=x>>>16&255,r[15]=x>>>24&255,r[16]=M>>>0&255,r[17]=M>>>8&255,r[18]=M>>>16&255,r[19]=M>>>24&255,r[20]=m>>>0&255,r[21]=m>>>8&255,r[22]=m>>>16&255,r[23]=m>>>24&255,r[24]=B>>>0&255,r[25]=B>>>8&255,r[26]=B>>>16&255,r[27]=B>>>24&255,r[28]=S>>>0&255,r[29]=S>>>8&255,r[30]=S>>>16&255,r[31]=S>>>24&255,r[32]=k>>>0&255,r[33]=k>>>8&255,r[34]=k>>>16&255,r[35]=k>>>24&255,r[36]=K>>>0&255,r[37]=K>>>8&255,r[38]=K>>>16&255,r[39]=K>>>24&255,r[40]=Y>>>0&255,r[41]=Y>>>8&255,r[42]=Y>>>16&255,r[43]=Y>>>24&255,r[44]=L>>>0&255,r[45]=L>>>8&255,r[46]=L>>>16&255,r[47]=L>>>24&255,r[48]=T>>>0&255,r[49]=T>>>8&255,r[50]=T>>>16&255,r[51]=T>>>24&255,r[52]=z>>>0&255,r[53]=z>>>8&255,r[54]=z>>>16&255,r[55]=z>>>24&255,r[56]=R>>>0&255,r[57]=R>>>8&255,r[58]=R>>>16&255,r[59]=R>>>24&255,r[60]=P>>>0&255,r[61]=P>>>8&255,r[62]=P>>>16&255,r[63]=P>>>24&255}(r,t,n,e)}function g(r,t,n,e){!function(r,t,n,e){for(var o,i=255&e[0]|(255&e[1])<<8|(255&e[2])<<16|(255&e[3])<<24,h=255&n[0]|(255&n[1])<<8|(255&n[2])<<16|(255&n[3])<<24,a=255&n[4]|(255&n[5])<<8|(255&n[6])<<16|(255&n[7])<<24,f=255&n[8]|(255&n[9])<<8|(255&n[10])<<16|(255&n[11])<<24,s=255&n[12]|(255&n[13])<<8|(255&n[14])<<16|(255&n[15])<<24,u=255&e[4]|(255&e[5])<<8|(255&e[6])<<16|(255&e[7])<<24,c=255&t[0]|(255&t[1])<<8|(255&t[2])<<16|(255&t[3])<<24,y=255&t[4]|(255&t[5])<<8|(255&t[6])<<16|(255&t[7])<<24,l=255&t[8]|(255&t[9])<<8|(255&t[10])<<16|(255&t[11])<<24,w=255&t[12]|(255&t[13])<<8|(255&t[14])<<16|(255&t[15])<<24,v=255&e[8]|(255&e[9])<<8|(255&e[10])<<16|(255&e[11])<<24,p=255&n[16]|(255&n[17])<<8|(255&n[18])<<16|(255&n[19])<<24,b=255&n[20]|(255&n[21])<<8|(255&n[22])<<16|(255&n[23])<<24,g=255&n[24]|(255&n[25])<<8|(255&n[26])<<16|(255&n[27])<<24,A=255&n[28]|(255&n[29])<<8|(255&n[30])<<16|(255&n[31])<<24,_=255&e[12]|(255&e[13])<<8|(255&e[14])<<16|(255&e[15])<<24,U=0;U<20;U+=2)i^=(o=(b^=(o=(l^=(o=(s^=(o=i+b|0)<<7|o>>>25)+i|0)<<9|o>>>23)+s|0)<<13|o>>>19)+l|0)<<18|o>>>14,u^=(o=(h^=(o=(g^=(o=(w^=(o=u+h|0)<<7|o>>>25)+u|0)<<9|o>>>23)+w|0)<<13|o>>>19)+g|0)<<18|o>>>14,v^=(o=(c^=(o=(a^=(o=(A^=(o=v+c|0)<<7|o>>>25)+v|0)<<9|o>>>23)+A|0)<<13|o>>>19)+a|0)<<18|o>>>14,_^=(o=(p^=(o=(y^=(o=(f^=(o=_+p|0)<<7|o>>>25)+_|0)<<9|o>>>23)+f|0)<<13|o>>>19)+y|0)<<18|o>>>14,i^=(o=(f^=(o=(a^=(o=(h^=(o=i+f|0)<<7|o>>>25)+i|0)<<9|o>>>23)+h|0)<<13|o>>>19)+a|0)<<18|o>>>14,u^=(o=(s^=(o=(y^=(o=(c^=(o=u+s|0)<<7|o>>>25)+u|0)<<9|o>>>23)+c|0)<<13|o>>>19)+y|0)<<18|o>>>14,v^=(o=(w^=(o=(l^=(o=(p^=(o=v+w|0)<<7|o>>>25)+v|0)<<9|o>>>23)+p|0)<<13|o>>>19)+l|0)<<18|o>>>14,_^=(o=(A^=(o=(g^=(o=(b^=(o=_+A|0)<<7|o>>>25)+_|0)<<9|o>>>23)+b|0)<<13|o>>>19)+g|0)<<18|o>>>14;r[0]=i>>>0&255,r[1]=i>>>8&255,r[2]=i>>>16&255,r[3]=i>>>24&255,r[4]=u>>>0&255,r[5]=u>>>8&255,r[6]=u>>>16&255,r[7]=u>>>24&255,r[8]=v>>>0&255,r[9]=v>>>8&255,r[10]=v>>>16&255,r[11]=v>>>24&255,r[12]=_>>>0&255,r[13]=_>>>8&255,r[14]=_>>>16&255,r[15]=_>>>24&255,r[16]=c>>>0&255,r[17]=c>>>8&255,r[18]=c>>>16&255,r[19]=c>>>24&255,r[20]=y>>>0&255,r[21]=y>>>8&255,r[22]=y>>>16&255,r[23]=y>>>24&255,r[24]=l>>>0&255,r[25]=l>>>8&255,r[26]=l>>>16&255,r[27]=l>>>24&255,r[28]=w>>>0&255,r[29]=w>>>8&255,r[30]=w>>>16&255,r[31]=w>>>24&255}(r,t,n,e)}var A=new Uint8Array([101,120,112,97,110,100,32,51,50,45,98,121,116,101,32,107]);function _(r,t,n,e,o,i,h){var a,f,s=new Uint8Array(16),u=new Uint8Array(64);for(f=0;f<16;f++)s[f]=0;for(f=0;f<8;f++)s[f]=i[f];for(;o>=64;){for(b(u,s,h,A),f=0;f<64;f++)r[t+f]=n[e+f]^u[f];for(a=1,f=8;f<16;f++)a=a+(255&s[f])|0,s[f]=255&a,a>>>=8;o-=64,t+=64,e+=64}if(o>0)for(b(u,s,h,A),f=0;f<o;f++)r[t+f]=n[e+f]^u[f];return 0}function U(r,t,n,e,o){var i,h,a=new Uint8Array(16),f=new Uint8Array(64);for(h=0;h<16;h++)a[h]=0;for(h=0;h<8;h++)a[h]=e[h];for(;n>=64;){for(b(f,a,o,A),h=0;h<64;h++)r[t+h]=f[h];for(i=1,h=8;h<16;h++)i=i+(255&a[h])|0,a[h]=255&i,i>>>=8;n-=64,t+=64}if(n>0)for(b(f,a,o,A),h=0;h<n;h++)r[t+h]=f[h];return 0}function d(r,t,n,e,o){var i=new Uint8Array(32);g(i,e,o,A);for(var h=new Uint8Array(8),a=0;a<8;a++)h[a]=e[a+16];return U(r,t,n,h,i)}function E(r,t,n,e,o,i,h){var a=new Uint8Array(32);g(a,i,h,A);for(var f=new Uint8Array(8),s=0;s<8;s++)f[s]=i[s+16];return _(r,t,n,e,o,f,a)}var x=function(r){var t,n,e,o,i,h,a,f;this.buffer=new Uint8Array(16),this.r=new Uint16Array(10),this.h=new Uint16Array(10),this.pad=new Uint16Array(8),this.leftover=0,this.fin=0,t=255&r[0]|(255&r[1])<<8,this.r[0]=8191&t,n=255&r[2]|(255&r[3])<<8,this.r[1]=8191&(t>>>13|n<<3),e=255&r[4]|(255&r[5])<<8,this.r[2]=7939&(n>>>10|e<<6),o=255&r[6]|(255&r[7])<<8,this.r[3]=8191&(e>>>7|o<<9),i=255&r[8]|(255&r[9])<<8,this.r[4]=255&(o>>>4|i<<12),this.r[5]=i>>>1&8190,h=255&r[10]|(255&r[11])<<8,this.r[6]=8191&(i>>>14|h<<2),a=255&r[12]|(255&r[13])<<8,this.r[7]=8065&(h>>>11|a<<5),f=255&r[14]|(255&r[15])<<8,this.r[8]=8191&(a>>>8|f<<8),this.r[9]=f>>>5&127,this.pad[0]=255&r[16]|(255&r[17])<<8,this.pad[1]=255&r[18]|(255&r[19])<<8,this.pad[2]=255&r[20]|(255&r[21])<<8,this.pad[3]=255&r[22]|(255&r[23])<<8,this.pad[4]=255&r[24]|(255&r[25])<<8,this.pad[5]=255&r[26]|(255&r[27])<<8,this.pad[6]=255&r[28]|(255&r[29])<<8,this.pad[7]=255&r[30]|(255&r[31])<<8};function M(r,t,n,e,o,i){var h=new x(i);return h.update(n,e,o),h.finish(r,t),0}function m(r,t,n,e,o,i){var h=new Uint8Array(16);return M(h,0,n,e,o,i),v(r,t,h,0)}function B(r,t,n,e,o){var i;if(n<32)return-1;for(E(r,0,t,0,n,e,o),M(r,16,r,32,n-32,r),i=0;i<16;i++)r[i]=0;return 0}function S(r,t,n,e,o){var i,h=new Uint8Array(32);if(n<32)return-1;if(d(h,0,32,e,o),0!==m(t,16,t,32,n-32,h))return-1;for(E(r,0,t,0,n,e,o),i=0;i<32;i++)r[i]=0;return 0}function k(r,t){var n;for(n=0;n<16;n++)r[n]=0|t[n]}function K(r){var t,n,e=1;for(t=0;t<16;t++)n=r[t]+e+65535,e=Math.floor(n/65536),r[t]=n-65536*e;r[0]+=e-1+37*(e-1)}function Y(r,t,n){for(var e,o=~(n-1),i=0;i<16;i++)e=o&(r[i]^t[i]),r[i]^=e,t[i]^=e}function L(r,n){var e,o,i,h=t(),a=t();for(e=0;e<16;e++)a[e]=n[e];for(K(a),K(a),K(a),o=0;o<2;o++){for(h[0]=a[0]-65517,e=1;e<15;e++)h[e]=a[e]-65535-(h[e-1]>>16&1),h[e-1]&=65535;h[15]=a[15]-32767-(h[14]>>16&1),i=h[15]>>16&1,h[14]&=65535,Y(a,h,1-i)}for(e=0;e<16;e++)r[2*e]=255&a[e],r[2*e+1]=a[e]>>8}function T(r,t){var n=new Uint8Array(32),e=new Uint8Array(32);return L(n,r),L(e,t),p(n,0,e,0)}function z(r){var t=new Uint8Array(32);return L(t,r),1&t[0]}function R(r,t){var n;for(n=0;n<16;n++)r[n]=t[2*n]+(t[2*n+1]<<8);r[15]&=32767}function P(r,t,n){for(var e=0;e<16;e++)r[e]=t[e]+n[e]}function N(r,t,n){for(var e=0;e<16;e++)r[e]=t[e]-n[e]}function O(r,t,n){var e,o,i=0,h=0,a=0,f=0,s=0,u=0,c=0,y=0,l=0,w=0,v=0,p=0,b=0,g=0,A=0,_=0,U=0,d=0,E=0,x=0,M=0,m=0,B=0,S=0,k=0,K=0,Y=0,L=0,T=0,z=0,R=0,P=n[0],N=n[1],O=n[2],C=n[3],F=n[4],I=n[5],Z=n[6],G=n[7],q=n[8],D=n[9],V=n[10],X=n[11],j=n[12],H=n[13],J=n[14],Q=n[15];i+=(e=t[0])*P,h+=e*N,a+=e*O,f+=e*C,s+=e*F,u+=e*I,c+=e*Z,y+=e*G,l+=e*q,w+=e*D,v+=e*V,p+=e*X,b+=e*j,g+=e*H,A+=e*J,_+=e*Q,h+=(e=t[1])*P,a+=e*N,f+=e*O,s+=e*C,u+=e*F,c+=e*I,y+=e*Z,l+=e*G,w+=e*q,v+=e*D,p+=e*V,b+=e*X,g+=e*j,A+=e*H,_+=e*J,U+=e*Q,a+=(e=t[2])*P,f+=e*N,s+=e*O,u+=e*C,c+=e*F,y+=e*I,l+=e*Z,w+=e*G,v+=e*q,p+=e*D,b+=e*V,g+=e*X,A+=e*j,_+=e*H,U+=e*J,d+=e*Q,f+=(e=t[3])*P,s+=e*N,u+=e*O,c+=e*C,y+=e*F,l+=e*I,w+=e*Z,v+=e*G,p+=e*q,b+=e*D,g+=e*V,A+=e*X,_+=e*j,U+=e*H,d+=e*J,E+=e*Q,s+=(e=t[4])*P,u+=e*N,c+=e*O,y+=e*C,l+=e*F,w+=e*I,v+=e*Z,p+=e*G,b+=e*q,g+=e*D,A+=e*V,_+=e*X,U+=e*j,d+=e*H,E+=e*J,x+=e*Q,u+=(e=t[5])*P,c+=e*N,y+=e*O,l+=e*C,w+=e*F,v+=e*I,p+=e*Z,b+=e*G,g+=e*q,A+=e*D,_+=e*V,U+=e*X,d+=e*j,E+=e*H,x+=e*J,M+=e*Q,c+=(e=t[6])*P,y+=e*N,l+=e*O,w+=e*C,v+=e*F,p+=e*I,b+=e*Z,g+=e*G,A+=e*q,_+=e*D,U+=e*V,d+=e*X,E+=e*j,x+=e*H,M+=e*J,m+=e*Q,y+=(e=t[7])*P,l+=e*N,w+=e*O,v+=e*C,p+=e*F,b+=e*I,g+=e*Z,A+=e*G,_+=e*q,U+=e*D,d+=e*V,E+=e*X,x+=e*j,M+=e*H,m+=e*J,B+=e*Q,l+=(e=t[8])*P,w+=e*N,v+=e*O,p+=e*C,b+=e*F,g+=e*I,A+=e*Z,_+=e*G,U+=e*q,d+=e*D,E+=e*V,x+=e*X,M+=e*j,m+=e*H,B+=e*J,S+=e*Q,w+=(e=t[9])*P,v+=e*N,p+=e*O,b+=e*C,g+=e*F,A+=e*I,_+=e*Z,U+=e*G,d+=e*q,E+=e*D,x+=e*V,M+=e*X,m+=e*j,B+=e*H,S+=e*J,k+=e*Q,v+=(e=t[10])*P,p+=e*N,b+=e*O,g+=e*C,A+=e*F,_+=e*I,U+=e*Z,d+=e*G,E+=e*q,x+=e*D,M+=e*V,m+=e*X,B+=e*j,S+=e*H,k+=e*J,K+=e*Q,p+=(e=t[11])*P,b+=e*N,g+=e*O,A+=e*C,_+=e*F,U+=e*I,d+=e*Z,E+=e*G,x+=e*q,M+=e*D,m+=e*V,B+=e*X,S+=e*j,k+=e*H,K+=e*J,Y+=e*Q,b+=(e=t[12])*P,g+=e*N,A+=e*O,_+=e*C,U+=e*F,d+=e*I,E+=e*Z,x+=e*G,M+=e*q,m+=e*D,B+=e*V,S+=e*X,k+=e*j,K+=e*H,Y+=e*J,L+=e*Q,g+=(e=t[13])*P,A+=e*N,_+=e*O,U+=e*C,d+=e*F,E+=e*I,x+=e*Z,M+=e*G,m+=e*q,B+=e*D,S+=e*V,k+=e*X,K+=e*j,Y+=e*H,L+=e*J,T+=e*Q,A+=(e=t[14])*P,_+=e*N,U+=e*O,d+=e*C,E+=e*F,x+=e*I,M+=e*Z,m+=e*G,B+=e*q,S+=e*D,k+=e*V,K+=e*X,Y+=e*j,L+=e*H,T+=e*J,z+=e*Q,_+=(e=t[15])*P,h+=38*(d+=e*O),a+=38*(E+=e*C),f+=38*(x+=e*F),s+=38*(M+=e*I),u+=38*(m+=e*Z),c+=38*(B+=e*G),y+=38*(S+=e*q),l+=38*(k+=e*D),w+=38*(K+=e*V),v+=38*(Y+=e*X),p+=38*(L+=e*j),b+=38*(T+=e*H),g+=38*(z+=e*J),A+=38*(R+=e*Q),i=(e=(i+=38*(U+=e*N))+(o=1)+65535)-65536*(o=Math.floor(e/65536)),h=(e=h+o+65535)-65536*(o=Math.floor(e/65536)),a=(e=a+o+65535)-65536*(o=Math.floor(e/65536)),f=(e=f+o+65535)-65536*(o=Math.floor(e/65536)),s=(e=s+o+65535)-65536*(o=Math.floor(e/65536)),u=(e=u+o+65535)-65536*(o=Math.floor(e/65536)),c=(e=c+o+65535)-65536*(o=Math.floor(e/65536)),y=(e=y+o+65535)-65536*(o=Math.floor(e/65536)),l=(e=l+o+65535)-65536*(o=Math.floor(e/65536)),w=(e=w+o+65535)-65536*(o=Math.floor(e/65536)),v=(e=v+o+65535)-65536*(o=Math.floor(e/65536)),p=(e=p+o+65535)-65536*(o=Math.floor(e/65536)),b=(e=b+o+65535)-65536*(o=Math.floor(e/65536)),g=(e=g+o+65535)-65536*(o=Math.floor(e/65536)),A=(e=A+o+65535)-65536*(o=Math.floor(e/65536)),_=(e=_+o+65535)-65536*(o=Math.floor(e/65536)),i=(e=(i+=o-1+37*(o-1))+(o=1)+65535)-65536*(o=Math.floor(e/65536)),h=(e=h+o+65535)-65536*(o=Math.floor(e/65536)),a=(e=a+o+65535)-65536*(o=Math.floor(e/65536)),f=(e=f+o+65535)-65536*(o=Math.floor(e/65536)),s=(e=s+o+65535)-65536*(o=Math.floor(e/65536)),u=(e=u+o+65535)-65536*(o=Math.floor(e/65536)),c=(e=c+o+65535)-65536*(o=Math.floor(e/65536)),y=(e=y+o+65535)-65536*(o=Math.floor(e/65536)),l=(e=l+o+65535)-65536*(o=Math.floor(e/65536)),w=(e=w+o+65535)-65536*(o=Math.floor(e/65536)),v=(e=v+o+65535)-65536*(o=Math.floor(e/65536)),p=(e=p+o+65535)-65536*(o=Math.floor(e/65536)),b=(e=b+o+65535)-65536*(o=Math.floor(e/65536)),g=(e=g+o+65535)-65536*(o=Math.floor(e/65536)),A=(e=A+o+65535)-65536*(o=Math.floor(e/65536)),_=(e=_+o+65535)-65536*(o=Math.floor(e/65536)),i+=o-1+37*(o-1),r[0]=i,r[1]=h,r[2]=a,r[3]=f,r[4]=s,r[5]=u,r[6]=c,r[7]=y,r[8]=l,r[9]=w,r[10]=v,r[11]=p,r[12]=b,r[13]=g,r[14]=A,r[15]=_}function C(r,t){O(r,t,t)}function F(r,n){var e,o=t();for(e=0;e<16;e++)o[e]=n[e];for(e=253;e>=0;e--)C(o,o),2!==e&&4!==e&&O(o,o,n);for(e=0;e<16;e++)r[e]=o[e]}function I(r,n){var e,o=t();for(e=0;e<16;e++)o[e]=n[e];for(e=250;e>=0;e--)C(o,o),1!==e&&O(o,o,n);for(e=0;e<16;e++)r[e]=o[e]}function Z(r,n,e){var o,i,h=new Uint8Array(32),f=new Float64Array(80),s=t(),u=t(),c=t(),y=t(),l=t(),w=t();for(i=0;i<31;i++)h[i]=n[i];for(h[31]=127&n[31]|64,h[0]&=248,R(f,e),i=0;i<16;i++)u[i]=f[i],y[i]=s[i]=c[i]=0;for(s[0]=y[0]=1,i=254;i>=0;--i)Y(s,u,o=h[i>>>3]>>>(7&i)&1),Y(c,y,o),P(l,s,c),N(s,s,c),P(c,u,y),N(u,u,y),C(y,l),C(w,s),O(s,c,s),O(c,u,l),P(l,s,c),N(s,s,c),C(u,s),N(c,y,w),O(s,c,a),P(s,s,y),O(c,c,s),O(s,y,w),O(y,u,f),C(u,l),Y(s,u,o),Y(c,y,o);for(i=0;i<16;i++)f[i+16]=s[i],f[i+32]=c[i],f[i+48]=u[i],f[i+64]=y[i];var v=f.subarray(32),p=f.subarray(16);return F(v,v),O(p,p,v),L(r,p),0}function G(r,t){return Z(r,t,o)}function q(r,t){return n(t,32),G(r,t)}function D(r,t,n){var o=new Uint8Array(32);return Z(o,n,t),g(r,e,o,A)}x.prototype.blocks=function(r,t,n){for(var e,o,i,h,a,f,s,u,c,y,l,w,v,p,b,g,A,_,U,d=this.fin?0:2048,E=this.h[0],x=this.h[1],M=this.h[2],m=this.h[3],B=this.h[4],S=this.h[5],k=this.h[6],K=this.h[7],Y=this.h[8],L=this.h[9],T=this.r[0],z=this.r[1],R=this.r[2],P=this.r[3],N=this.r[4],O=this.r[5],C=this.r[6],F=this.r[7],I=this.r[8],Z=this.r[9];n>=16;)y=c=0,y+=(E+=8191&(e=255&r[t+0]|(255&r[t+1])<<8))*T,y+=(x+=8191&(e>>>13|(o=255&r[t+2]|(255&r[t+3])<<8)<<3))*(5*Z),y+=(M+=8191&(o>>>10|(i=255&r[t+4]|(255&r[t+5])<<8)<<6))*(5*I),y+=(m+=8191&(i>>>7|(h=255&r[t+6]|(255&r[t+7])<<8)<<9))*(5*F),c=(y+=(B+=8191&(h>>>4|(a=255&r[t+8]|(255&r[t+9])<<8)<<12))*(5*C))>>>13,y&=8191,y+=(S+=a>>>1&8191)*(5*O),y+=(k+=8191&(a>>>14|(f=255&r[t+10]|(255&r[t+11])<<8)<<2))*(5*N),y+=(K+=8191&(f>>>11|(s=255&r[t+12]|(255&r[t+13])<<8)<<5))*(5*P),y+=(Y+=8191&(s>>>8|(u=255&r[t+14]|(255&r[t+15])<<8)<<8))*(5*R),l=c+=(y+=(L+=u>>>5|d)*(5*z))>>>13,l+=E*z,l+=x*T,l+=M*(5*Z),l+=m*(5*I),c=(l+=B*(5*F))>>>13,l&=8191,l+=S*(5*C),l+=k*(5*O),l+=K*(5*N),l+=Y*(5*P),c+=(l+=L*(5*R))>>>13,l&=8191,w=c,w+=E*R,w+=x*z,w+=M*T,w+=m*(5*Z),c=(w+=B*(5*I))>>>13,w&=8191,w+=S*(5*F),w+=k*(5*C),w+=K*(5*O),w+=Y*(5*N),v=c+=(w+=L*(5*P))>>>13,v+=E*P,v+=x*R,v+=M*z,v+=m*T,c=(v+=B*(5*Z))>>>13,v&=8191,v+=S*(5*I),v+=k*(5*F),v+=K*(5*C),v+=Y*(5*O),p=c+=(v+=L*(5*N))>>>13,p+=E*N,p+=x*P,p+=M*R,p+=m*z,c=(p+=B*T)>>>13,p&=8191,p+=S*(5*Z),p+=k*(5*I),p+=K*(5*F),p+=Y*(5*C),b=c+=(p+=L*(5*O))>>>13,b+=E*O,b+=x*N,b+=M*P,b+=m*R,c=(b+=B*z)>>>13,b&=8191,b+=S*T,b+=k*(5*Z),b+=K*(5*I),b+=Y*(5*F),g=c+=(b+=L*(5*C))>>>13,g+=E*C,g+=x*O,g+=M*N,g+=m*P,c=(g+=B*R)>>>13,g&=8191,g+=S*z,g+=k*T,g+=K*(5*Z),g+=Y*(5*I),A=c+=(g+=L*(5*F))>>>13,A+=E*F,A+=x*C,A+=M*O,A+=m*N,c=(A+=B*P)>>>13,A&=8191,A+=S*R,A+=k*z,A+=K*T,A+=Y*(5*Z),_=c+=(A+=L*(5*I))>>>13,_+=E*I,_+=x*F,_+=M*C,_+=m*O,c=(_+=B*N)>>>13,_&=8191,_+=S*P,_+=k*R,_+=K*z,_+=Y*T,U=c+=(_+=L*(5*Z))>>>13,U+=E*Z,U+=x*I,U+=M*F,U+=m*C,c=(U+=B*O)>>>13,U&=8191,U+=S*N,U+=k*P,U+=K*R,U+=Y*z,E=y=8191&(c=(c=((c+=(U+=L*T)>>>13)<<2)+c|0)+(y&=8191)|0),x=l+=c>>>=13,M=w&=8191,m=v&=8191,B=p&=8191,S=b&=8191,k=g&=8191,K=A&=8191,Y=_&=8191,L=U&=8191,t+=16,n-=16;this.h[0]=E,this.h[1]=x,this.h[2]=M,this.h[3]=m,this.h[4]=B,this.h[5]=S,this.h[6]=k,this.h[7]=K,this.h[8]=Y,this.h[9]=L},x.prototype.finish=function(r,t){var n,e,o,i,h=new Uint16Array(10);if(this.leftover){for(i=this.leftover,this.buffer[i++]=1;i<16;i++)this.buffer[i]=0;this.fin=1,this.blocks(this.buffer,0,16)}for(n=this.h[1]>>>13,this.h[1]&=8191,i=2;i<10;i++)this.h[i]+=n,n=this.h[i]>>>13,this.h[i]&=8191;for(this.h[0]+=5*n,n=this.h[0]>>>13,this.h[0]&=8191,this.h[1]+=n,n=this.h[1]>>>13,this.h[1]&=8191,this.h[2]+=n,h[0]=this.h[0]+5,n=h[0]>>>13,h[0]&=8191,i=1;i<10;i++)h[i]=this.h[i]+n,n=h[i]>>>13,h[i]&=8191;for(h[9]-=8192,e=(1^n)-1,i=0;i<10;i++)h[i]&=e;for(e=~e,i=0;i<10;i++)this.h[i]=this.h[i]&e|h[i];for(this.h[0]=65535&(this.h[0]|this.h[1]<<13),this.h[1]=65535&(this.h[1]>>>3|this.h[2]<<10),this.h[2]=65535&(this.h[2]>>>6|this.h[3]<<7),this.h[3]=65535&(this.h[3]>>>9|this.h[4]<<4),this.h[4]=65535&(this.h[4]>>>12|this.h[5]<<1|this.h[6]<<14),this.h[5]=65535&(this.h[6]>>>2|this.h[7]<<11),this.h[6]=65535&(this.h[7]>>>5|this.h[8]<<8),this.h[7]=65535&(this.h[8]>>>8|this.h[9]<<5),o=this.h[0]+this.pad[0],this.h[0]=65535&o,i=1;i<8;i++)o=(this.h[i]+this.pad[i]|0)+(o>>>16)|0,this.h[i]=65535&o;r[t+0]=this.h[0]>>>0&255,r[t+1]=this.h[0]>>>8&255,r[t+2]=this.h[1]>>>0&255,r[t+3]=this.h[1]>>>8&255,r[t+4]=this.h[2]>>>0&255,r[t+5]=this.h[2]>>>8&255,r[t+6]=this.h[3]>>>0&255,r[t+7]=this.h[3]>>>8&255,r[t+8]=this.h[4]>>>0&255,r[t+9]=this.h[4]>>>8&255,r[t+10]=this.h[5]>>>0&255,r[t+11]=this.h[5]>>>8&255,r[t+12]=this.h[6]>>>0&255,r[t+13]=this.h[6]>>>8&255,r[t+14]=this.h[7]>>>0&255,r[t+15]=this.h[7]>>>8&255},x.prototype.update=function(r,t,n){var e,o;if(this.leftover){for((o=16-this.leftover)>n&&(o=n),e=0;e<o;e++)this.buffer[this.leftover+e]=r[t+e];if(n-=o,t+=o,this.leftover+=o,this.leftover<16)return;this.blocks(this.buffer,0,16),this.leftover=0}if(n>=16&&(o=n-n%16,this.blocks(r,t,o),t+=o,n-=o),n){for(e=0;e<n;e++)this.buffer[this.leftover+e]=r[t+e];this.leftover+=n}};var V=B,X=S;var j=[1116352408,3609767458,1899447441,602891725,3049323471,3964484399,3921009573,2173295548,961987163,4081628472,1508970993,3053834265,2453635748,2937671579,2870763221,3664609560,3624381080,2734883394,310598401,1164996542,607225278,1323610764,1426881987,3590304994,1925078388,4068182383,2162078206,991336113,2614888103,633803317,3248222580,3479774868,3835390401,2666613458,4022224774,944711139,264347078,2341262773,604807628,2007800933,770255983,1495990901,1249150122,1856431235,1555081692,3175218132,1996064986,2198950837,2554220882,3999719339,2821834349,766784016,2952996808,2566594879,3210313671,3203337956,3336571891,1034457026,3584528711,2466948901,113926993,3758326383,338241895,168717936,666307205,1188179964,773529912,1546045734,1294757372,1522805485,1396182291,2643833823,1695183700,2343527390,1986661051,1014477480,2177026350,1206759142,2456956037,344077627,2730485921,1290863460,2820302411,3158454273,3259730800,3505952657,3345764771,106217008,3516065817,3606008344,3600352804,1432725776,4094571909,1467031594,275423344,851169720,430227734,3100823752,506948616,1363258195,659060556,3750685593,883997877,3785050280,958139571,3318307427,1322822218,3812723403,1537002063,2003034995,1747873779,3602036899,1955562222,1575990012,2024104815,1125592928,2227730452,2716904306,2361852424,442776044,2428436474,593698344,2756734187,3733110249,3204031479,2999351573,3329325298,3815920427,3391569614,3928383900,3515267271,566280711,3940187606,3454069534,4118630271,4000239992,116418474,1914138554,174292421,2731055270,289380356,3203993006,460393269,320620315,685471733,587496836,852142971,1086792851,1017036298,365543100,1126000580,2618297676,1288033470,3409855158,1501505948,4234509866,1607167915,987167468,1816402316,1246189591];function H(r,t,n,e){for(var o,i,h,a,f,s,u,c,y,l,w,v,p,b,g,A,_,U,d,E,x,M,m,B,S,k,K=new Int32Array(16),Y=new Int32Array(16),L=r[0],T=r[1],z=r[2],R=r[3],P=r[4],N=r[5],O=r[6],C=r[7],F=t[0],I=t[1],Z=t[2],G=t[3],q=t[4],D=t[5],V=t[6],X=t[7],H=0;e>=128;){for(d=0;d<16;d++)E=8*d+H,K[d]=n[E+0]<<24|n[E+1]<<16|n[E+2]<<8|n[E+3],Y[d]=n[E+4]<<24|n[E+5]<<16|n[E+6]<<8|n[E+7];for(d=0;d<80;d++)if(o=L,i=T,h=z,a=R,f=P,s=N,u=O,C,y=F,l=I,w=Z,v=G,p=q,b=D,g=V,X,m=65535&(M=X),B=M>>>16,S=65535&(x=C),k=x>>>16,m+=65535&(M=(q>>>14|P<<18)^(q>>>18|P<<14)^(P>>>9|q<<23)),B+=M>>>16,S+=65535&(x=(P>>>14|q<<18)^(P>>>18|q<<14)^(q>>>9|P<<23)),k+=x>>>16,m+=65535&(M=q&D^~q&V),B+=M>>>16,S+=65535&(x=P&N^~P&O),k+=x>>>16,x=j[2*d],m+=65535&(M=j[2*d+1]),B+=M>>>16,S+=65535&x,k+=x>>>16,x=K[d%16],B+=(M=Y[d%16])>>>16,S+=65535&x,k+=x>>>16,S+=(B+=(m+=65535&M)>>>16)>>>16,m=65535&(M=U=65535&m|B<<16),B=M>>>16,S=65535&(x=_=65535&S|(k+=S>>>16)<<16),k=x>>>16,m+=65535&(M=(F>>>28|L<<4)^(L>>>2|F<<30)^(L>>>7|F<<25)),B+=M>>>16,S+=65535&(x=(L>>>28|F<<4)^(F>>>2|L<<30)^(F>>>7|L<<25)),k+=x>>>16,B+=(M=F&I^F&Z^I&Z)>>>16,S+=65535&(x=L&T^L&z^T&z),k+=x>>>16,c=65535&(S+=(B+=(m+=65535&M)>>>16)>>>16)|(k+=S>>>16)<<16,A=65535&m|B<<16,m=65535&(M=v),B=M>>>16,S=65535&(x=a),k=x>>>16,B+=(M=U)>>>16,S+=65535&(x=_),k+=x>>>16,T=o,z=i,R=h,P=a=65535&(S+=(B+=(m+=65535&M)>>>16)>>>16)|(k+=S>>>16)<<16,N=f,O=s,C=u,L=c,I=y,Z=l,G=w,q=v=65535&m|B<<16,D=p,V=b,X=g,F=A,d%16==15)for(E=0;E<16;E++)x=K[E],m=65535&(M=Y[E]),B=M>>>16,S=65535&x,k=x>>>16,x=K[(E+9)%16],m+=65535&(M=Y[(E+9)%16]),B+=M>>>16,S+=65535&x,k+=x>>>16,_=K[(E+1)%16],m+=65535&(M=((U=Y[(E+1)%16])>>>1|_<<31)^(U>>>8|_<<24)^(U>>>7|_<<25)),B+=M>>>16,S+=65535&(x=(_>>>1|U<<31)^(_>>>8|U<<24)^_>>>7),k+=x>>>16,_=K[(E+14)%16],B+=(M=((U=Y[(E+14)%16])>>>19|_<<13)^(_>>>29|U<<3)^(U>>>6|_<<26))>>>16,S+=65535&(x=(_>>>19|U<<13)^(U>>>29|_<<3)^_>>>6),k+=x>>>16,k+=(S+=(B+=(m+=65535&M)>>>16)>>>16)>>>16,K[E]=65535&S|k<<16,Y[E]=65535&m|B<<16;m=65535&(M=F),B=M>>>16,S=65535&(x=L),k=x>>>16,x=r[0],B+=(M=t[0])>>>16,S+=65535&x,k+=x>>>16,k+=(S+=(B+=(m+=65535&M)>>>16)>>>16)>>>16,r[0]=L=65535&S|k<<16,t[0]=F=65535&m|B<<16,m=65535&(M=I),B=M>>>16,S=65535&(x=T),k=x>>>16,x=r[1],B+=(M=t[1])>>>16,S+=65535&x,k+=x>>>16,k+=(S+=(B+=(m+=65535&M)>>>16)>>>16)>>>16,r[1]=T=65535&S|k<<16,t[1]=I=65535&m|B<<16,m=65535&(M=Z),B=M>>>16,S=65535&(x=z),k=x>>>16,x=r[2],B+=(M=t[2])>>>16,S+=65535&x,k+=x>>>16,k+=(S+=(B+=(m+=65535&M)>>>16)>>>16)>>>16,r[2]=z=65535&S|k<<16,t[2]=Z=65535&m|B<<16,m=65535&(M=G),B=M>>>16,S=65535&(x=R),k=x>>>16,x=r[3],B+=(M=t[3])>>>16,S+=65535&x,k+=x>>>16,k+=(S+=(B+=(m+=65535&M)>>>16)>>>16)>>>16,r[3]=R=65535&S|k<<16,t[3]=G=65535&m|B<<16,m=65535&(M=q),B=M>>>16,S=65535&(x=P),k=x>>>16,x=r[4],B+=(M=t[4])>>>16,S+=65535&x,k+=x>>>16,k+=(S+=(B+=(m+=65535&M)>>>16)>>>16)>>>16,r[4]=P=65535&S|k<<16,t[4]=q=65535&m|B<<16,m=65535&(M=D),B=M>>>16,S=65535&(x=N),k=x>>>16,x=r[5],B+=(M=t[5])>>>16,S+=65535&x,k+=x>>>16,k+=(S+=(B+=(m+=65535&M)>>>16)>>>16)>>>16,r[5]=N=65535&S|k<<16,t[5]=D=65535&m|B<<16,m=65535&(M=V),B=M>>>16,S=65535&(x=O),k=x>>>16,x=r[6],B+=(M=t[6])>>>16,S+=65535&x,k+=x>>>16,k+=(S+=(B+=(m+=65535&M)>>>16)>>>16)>>>16,r[6]=O=65535&S|k<<16,t[6]=V=65535&m|B<<16,m=65535&(M=X),B=M>>>16,S=65535&(x=C),k=x>>>16,x=r[7],B+=(M=t[7])>>>16,S+=65535&x,k+=x>>>16,k+=(S+=(B+=(m+=65535&M)>>>16)>>>16)>>>16,r[7]=C=65535&S|k<<16,t[7]=X=65535&m|B<<16,H+=128,e-=128}return e}function J(r,t,n){var e,o=new Int32Array(8),i=new Int32Array(8),h=new Uint8Array(256),a=n;for(o[0]=1779033703,o[1]=3144134277,o[2]=1013904242,o[3]=2773480762,o[4]=1359893119,o[5]=2600822924,o[6]=528734635,o[7]=1541459225,i[0]=4089235720,i[1]=2227873595,i[2]=4271175723,i[3]=1595750129,i[4]=2917565137,i[5]=725511199,i[6]=4215389547,i[7]=327033209,H(o,i,t,n),n%=128,e=0;e<n;e++)h[e]=t[a-n+e];for(h[n]=128,h[(n=256-128*(n<112?1:0))-9]=0,l(h,n-8,a/536870912|0,a<<3),H(o,i,h,n),e=0;e<8;e++)l(r,8*e,o[e],i[e]);return 0}function Q(r,n){var e=t(),o=t(),i=t(),h=t(),a=t(),f=t(),u=t(),c=t(),y=t();N(e,r[1],r[0]),N(y,n[1],n[0]),O(e,e,y),P(o,r[0],r[1]),P(y,n[0],n[1]),O(o,o,y),O(i,r[3],n[3]),O(i,i,s),O(h,r[2],n[2]),P(h,h,h),N(a,o,e),N(f,h,i),P(u,h,i),P(c,o,e),O(r[0],a,f),O(r[1],c,u),O(r[2],u,f),O(r[3],a,c)}function W(r,t,n){var e;for(e=0;e<4;e++)Y(r[e],t[e],n)}function $(r,n){var e=t(),o=t(),i=t();F(i,n[2]),O(e,n[0],i),O(o,n[1],i),L(r,o),r[31]^=z(e)<<7}function rr(r,t,n){var e,o;for(k(r[0],i),k(r[1],h),k(r[2],h),k(r[3],i),o=255;o>=0;--o)W(r,t,e=n[o/8|0]>>(7&o)&1),Q(t,r),Q(r,r),W(r,t,e)}function tr(r,n){var e=[t(),t(),t(),t()];k(e[0],u),k(e[1],c),k(e[2],h),O(e[3],u,c),rr(r,e,n)}function nr(r,e,o){var i,h=new Uint8Array(64),a=[t(),t(),t(),t()];for(o||n(e,32),J(h,e,32),h[0]&=248,h[31]&=127,h[31]|=64,tr(a,h),$(r,a),i=0;i<32;i++)e[i+32]=r[i];return 0}var er=new Float64Array([237,211,245,92,26,99,18,88,214,156,247,162,222,249,222,20,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,16]);function or(r,t){var n,e,o,i;for(e=63;e>=32;--e){for(n=0,o=e-32,i=e-12;o<i;++o)t[o]+=n-16*t[e]*er[o-(e-32)],n=Math.floor((t[o]+128)/256),t[o]-=256*n;t[o]+=n,t[e]=0}for(n=0,o=0;o<32;o++)t[o]+=n-(t[31]>>4)*er[o],n=t[o]>>8,t[o]&=255;for(o=0;o<32;o++)t[o]-=n*er[o];for(e=0;e<32;e++)t[e+1]+=t[e]>>8,r[e]=255&t[e]}function ir(r){var t,n=new Float64Array(64);for(t=0;t<64;t++)n[t]=r[t];for(t=0;t<64;t++)r[t]=0;or(r,n)}function hr(r,n,e,o){var i,h,a=new Uint8Array(64),f=new Uint8Array(64),s=new Uint8Array(64),u=new Float64Array(64),c=[t(),t(),t(),t()];J(a,o,32),a[0]&=248,a[31]&=127,a[31]|=64;var y=e+64;for(i=0;i<e;i++)r[64+i]=n[i];for(i=0;i<32;i++)r[32+i]=a[32+i];for(J(s,r.subarray(32),e+32),ir(s),tr(c,s),$(r,c),i=32;i<64;i++)r[i]=o[i];for(J(f,r,e+64),ir(f),i=0;i<64;i++)u[i]=0;for(i=0;i<32;i++)u[i]=s[i];for(i=0;i<32;i++)for(h=0;h<32;h++)u[i+h]+=f[i]*a[h];return or(r.subarray(32),u),y}function ar(r,n,e,o){var a,s=new Uint8Array(32),u=new Uint8Array(64),c=[t(),t(),t(),t()],l=[t(),t(),t(),t()];if(e<64)return-1;if(function(r,n){var e=t(),o=t(),a=t(),s=t(),u=t(),c=t(),l=t();return k(r[2],h),R(r[1],n),C(a,r[1]),O(s,a,f),N(a,a,r[2]),P(s,r[2],s),C(u,s),C(c,u),O(l,c,u),O(e,l,a),O(e,e,s),I(e,e),O(e,e,a),O(e,e,s),O(e,e,s),O(r[0],e,s),C(o,r[0]),O(o,o,s),T(o,a)&&O(r[0],r[0],y),C(o,r[0]),O(o,o,s),T(o,a)?-1:(z(r[0])===n[31]>>7&&N(r[0],i,r[0]),O(r[3],r[0],r[1]),0)}(l,o))return-1;for(a=0;a<e;a++)r[a]=n[a];for(a=0;a<32;a++)r[a+32]=o[a];if(J(u,r,e),ir(u),rr(c,l,u),tr(l,n.subarray(32)),Q(c,l),$(s,c),e-=64,p(n,0,s,0)){for(a=0;a<e;a++)r[a]=0;return-1}for(a=0;a<e;a++)r[a]=n[a+64];return e}var fr=32,sr=24,ur=32,cr=32,yr=sr;function lr(r,t){if(r.length!==fr)throw new Error("bad key size");if(t.length!==sr)throw new Error("bad nonce size")}function wr(){for(var r=0;r<arguments.length;r++)if(!(arguments[r]instanceof Uint8Array))throw new TypeError("unexpected type, use Uint8Array")}function vr(r){for(var t=0;t<r.length;t++)r[t]=0}r.lowlevel={crypto_core_hsalsa20:g,crypto_stream_xor:E,crypto_stream:d,crypto_stream_salsa20_xor:_,crypto_stream_salsa20:U,crypto_onetimeauth:M,crypto_onetimeauth_verify:m,crypto_verify_16:v,crypto_verify_32:p,crypto_secretbox:B,crypto_secretbox_open:S,crypto_scalarmult:Z,crypto_scalarmult_base:G,crypto_box_beforenm:D,crypto_box_afternm:V,crypto_box:function(r,t,n,e,o,i){var h=new Uint8Array(32);return D(h,o,i),V(r,t,n,e,h)},crypto_box_open:function(r,t,n,e,o,i){var h=new Uint8Array(32);return D(h,o,i),X(r,t,n,e,h)},crypto_box_keypair:q,crypto_hash:J,crypto_sign:hr,crypto_sign_keypair:nr,crypto_sign_open:ar,crypto_secretbox_KEYBYTES:fr,crypto_secretbox_NONCEBYTES:sr,crypto_secretbox_ZEROBYTES:32,crypto_secretbox_BOXZEROBYTES:16,crypto_scalarmult_BYTES:32,crypto_scalarmult_SCALARBYTES:32,crypto_box_PUBLICKEYBYTES:ur,crypto_box_SECRETKEYBYTES:cr,crypto_box_BEFORENMBYTES:32,crypto_box_NONCEBYTES:yr,crypto_box_ZEROBYTES:32,crypto_box_BOXZEROBYTES:16,crypto_sign_BYTES:64,crypto_sign_PUBLICKEYBYTES:32,crypto_sign_SECRETKEYBYTES:64,crypto_sign_SEEDBYTES:32,crypto_hash_BYTES:64,gf:t,D:f,L:er,pack25519:L,unpack25519:R,M:O,A:P,S:C,Z:N,pow2523:I,add:Q,set25519:k,modL:or,scalarmult:rr,scalarbase:tr},r.randomBytes=function(r){var t=new Uint8Array(r);return n(t,r),t},r.secretbox=function(r,t,n){wr(r,t,n),lr(n,t);for(var e=new Uint8Array(32+r.length),o=new Uint8Array(e.length),i=0;i<r.length;i++)e[i+32]=r[i];return B(o,e,e.length,t,n),o.subarray(16)},r.secretbox.open=function(r,t,n){wr(r,t,n),lr(n,t);for(var e=new Uint8Array(16+r.length),o=new Uint8Array(e.length),i=0;i<r.length;i++)e[i+16]=r[i];return e.length<32?null:0!==S(o,e,e.length,t,n)?null:o.subarray(32)},r.secretbox.keyLength=fr,r.secretbox.nonceLength=sr,r.secretbox.overheadLength=16,r.scalarMult=function(r,t){if(wr(r,t),32!==r.length)throw new Error("bad n size");if(32!==t.length)throw new Error("bad p size");var n=new Uint8Array(32);return Z(n,r,t),n},r.scalarMult.base=function(r){if(wr(r),32!==r.length)throw new Error("bad n size");var t=new Uint8Array(32);return G(t,r),t},r.scalarMult.scalarLength=32,r.scalarMult.groupElementLength=32,r.box=function(t,n,e,o){var i=r.box.before(e,o);return r.secretbox(t,n,i)},r.box.before=function(r,t){wr(r,t),function(r,t){if(r.length!==ur)throw new Error("bad public key size");if(t.length!==cr)throw new Error("bad secret key size")}(r,t);var n=new Uint8Array(32);return D(n,r,t),n},r.box.after=r.secretbox,r.box.open=function(t,n,e,o){var i=r.box.before(e,o);return r.secretbox.open(t,n,i)},r.box.open.after=r.secretbox.open,r.box.keyPair=function(){var r=new Uint8Array(ur),t=new Uint8Array(cr);return q(r,t),{publicKey:r,secretKey:t}},r.box.keyPair.fromSecretKey=function(r){if(wr(r),r.length!==cr)throw new Error("bad secret key size");var t=new Uint8Array(ur);return G(t,r),{publicKey:t,secretKey:new Uint8Array(r)}},r.box.publicKeyLength=ur,r.box.secretKeyLength=cr,r.box.sharedKeyLength=32,r.box.nonceLength=yr,r.box.overheadLength=r.secretbox.overheadLength,r.sign=function(r,t){if(wr(r,t),64!==t.length)throw new Error("bad secret key size");var n=new Uint8Array(64+r.length);return hr(n,r,r.length,t),n},r.sign.open=function(r,t){if(wr(r,t),32!==t.length)throw new Error("bad public key size");var n=new Uint8Array(r.length),e=ar(n,r,r.length,t);if(e<0)return null;for(var o=new Uint8Array(e),i=0;i<o.length;i++)o[i]=n[i];return o},r.sign.detached=function(t,n){for(var e=r.sign(t,n),o=new Uint8Array(64),i=0;i<o.length;i++)o[i]=e[i];return o},r.sign.detached.verify=function(r,t,n){if(wr(r,t,n),64!==t.length)throw new Error("bad signature size");if(32!==n.length)throw new Error("bad public key size");var e,o=new Uint8Array(64+r.length),i=new Uint8Array(64+r.length);for(e=0;e<64;e++)o[e]=t[e];for(e=0;e<r.length;e++)o[e+64]=r[e];return ar(i,o,o.length,n)>=0},r.sign.keyPair=function(){var r=new Uint8Array(32),t=new Uint8Array(64);return nr(r,t),{publicKey:r,secretKey:t}},r.sign.keyPair.fromSecretKey=function(r){if(wr(r),64!==r.length)throw new Error("bad secret key size");for(var t=new Uint8Array(32),n=0;n<t.length;n++)t[n]=r[32+n];return{publicKey:t,secretKey:new Uint8Array(r)}},r.sign.keyPair.fromSeed=function(r){if(wr(r),32!==r.length)throw new Error("bad seed size");for(var t=new Uint8Array(32),n=new Uint8Array(64),e=0;e<32;e++)n[e]=r[e];return nr(t,n,!0),{publicKey:t,secretKey:n}},r.sign.publicKeyLength=32,r.sign.secretKeyLength=64,r.sign.seedLength=32,r.sign.signatureLength=64,r.hash=function(r){wr(r);var t=new Uint8Array(64);return J(t,r,r.length),t},r.hash.hashLength=64,r.verify=function(r,t){return wr(r,t),0!==r.length&&0!==t.length&&(r.length===t.length&&0===w(r,0,t,0,r.length))},r.setPRNG=function(r){n=r},function(){var t="undefined"!=typeof self?self.crypto||self.msCrypto:null;if(t&&t.getRandomValues){r.setPRNG(function(r,n){var e,o=new Uint8Array(n);for(e=0;e<n;e+=65536)t.getRandomValues(o.subarray(e,e+Math.min(n-e,65536)));for(e=0;e<n;e++)r[e]=o[e];vr(o)})}else"undefined"!=typeof require&&(t=require("crypto"))&&t.randomBytes&&r.setPRNG(function(r,n){var e,o=t.randomBytes(n);for(e=0;e<n;e++)r[e]=o[e];vr(o)})}()}("undefined"!=typeof module&&module.exports?module.exports:self.nacl=self.nacl||{});
|
package/lib/account.d.ts
CHANGED
package/lib/account.js
CHANGED
|
@@ -111,7 +111,7 @@ class Account {
|
|
|
111
111
|
deprecate('use `Account.signAndSendTransaction(SignAndSendTransactionOptions)` instead');
|
|
112
112
|
return this.signAndSendTransactionV2({ receiverId, actions });
|
|
113
113
|
}
|
|
114
|
-
async signAndSendTransactionV2({ receiverId, actions }) {
|
|
114
|
+
async signAndSendTransactionV2({ receiverId, actions, returnError }) {
|
|
115
115
|
let txHash, signedTx;
|
|
116
116
|
// TODO: TX_NONCE (different constants for different uses of exponentialBackoff?)
|
|
117
117
|
const result = await exponential_backoff_1.default(TX_NONCE_RETRY_WAIT, TX_NONCE_RETRY_NUMBER, TX_NONCE_RETRY_WAIT_BACKOFF, async () => {
|
|
@@ -151,7 +151,7 @@ class Account {
|
|
|
151
151
|
return acc;
|
|
152
152
|
}, []);
|
|
153
153
|
this.printLogsAndFailures(signedTx.transaction.receiverId, flatLogs);
|
|
154
|
-
if (typeof result.status === 'object' && typeof result.status.Failure === 'object') {
|
|
154
|
+
if (!returnError && typeof result.status === 'object' && typeof result.status.Failure === 'object') {
|
|
155
155
|
// if error data has error_message and error_type properties, we consider that node returned an error in the old format
|
|
156
156
|
if (result.status.Failure.error_message && result.status.Failure.error_type) {
|
|
157
157
|
throw new providers_1.TypedError(`Transaction ${result.transaction_outcome.id} failed. ${result.status.Failure.error_message}`, result.status.Failure.error_type);
|
package/lib/connection.js
CHANGED
|
@@ -11,7 +11,7 @@ function getProvider(config) {
|
|
|
11
11
|
switch (config.type) {
|
|
12
12
|
case undefined:
|
|
13
13
|
return config;
|
|
14
|
-
case 'JsonRpcProvider': return new providers_1.JsonRpcProvider(config.args
|
|
14
|
+
case 'JsonRpcProvider': return new providers_1.JsonRpcProvider({ ...config.args });
|
|
15
15
|
default: throw new Error(`Unknown provider type ${config.type}`);
|
|
16
16
|
}
|
|
17
17
|
}
|
|
@@ -90,7 +90,7 @@ class UnencryptedFileSystemKeyStore extends keystore_1.KeyStore {
|
|
|
90
90
|
async setKey(networkId, accountId, keyPair) {
|
|
91
91
|
await ensureDir(`${this.keyDir}/${networkId}`);
|
|
92
92
|
const content = { account_id: accountId, public_key: keyPair.getPublicKey().toString(), private_key: keyPair.toString() };
|
|
93
|
-
await writeFile(this.getKeyFilePath(networkId, accountId), JSON.stringify(content));
|
|
93
|
+
await writeFile(this.getKeyFilePath(networkId, accountId), JSON.stringify(content), { mode: 0o600 });
|
|
94
94
|
}
|
|
95
95
|
/**
|
|
96
96
|
* Gets a {@link KeyPair} from an unencrypted file
|
package/lib/near.d.ts
CHANGED
|
@@ -48,6 +48,13 @@ export interface NearConfig {
|
|
|
48
48
|
* @see {@link JsonRpcProvider.JsonRpcProvider | JsonRpcProvider}
|
|
49
49
|
*/
|
|
50
50
|
nodeUrl: string;
|
|
51
|
+
/**
|
|
52
|
+
* NEAR RPC API headers. Can be used to pass API KEY and other parameters.
|
|
53
|
+
* @see {@link JsonRpcProvider.JsonRpcProvider | JsonRpcProvider}
|
|
54
|
+
*/
|
|
55
|
+
headers: {
|
|
56
|
+
[key: string]: string | number;
|
|
57
|
+
};
|
|
51
58
|
/**
|
|
52
59
|
* NEAR wallet url used to redirect users to their wallet in browser applications.
|
|
53
60
|
* @see {@link https://docs.near.org/docs/tools/near-wallet}
|
package/lib/near.js
CHANGED
|
@@ -30,7 +30,7 @@ class Near {
|
|
|
30
30
|
this.config = config;
|
|
31
31
|
this.connection = connection_1.Connection.fromConfig({
|
|
32
32
|
networkId: config.networkId,
|
|
33
|
-
provider: { type: 'JsonRpcProvider', args: { url: config.nodeUrl } },
|
|
33
|
+
provider: { type: 'JsonRpcProvider', args: { url: config.nodeUrl, headers: config.headers } },
|
|
34
34
|
signer: config.signer || { type: 'InMemorySigner', keyStore: config.keyStore || config.deps.keyStore }
|
|
35
35
|
});
|
|
36
36
|
if (config.masterAccount) {
|
|
@@ -12,9 +12,9 @@ export declare class JsonRpcProvider extends Provider {
|
|
|
12
12
|
/** @hidden */
|
|
13
13
|
readonly connection: ConnectionInfo;
|
|
14
14
|
/**
|
|
15
|
-
* @param
|
|
15
|
+
* @param connectionInfoOrUrl ConnectionInfo or RPC API endpoint URL (deprecated)
|
|
16
16
|
*/
|
|
17
|
-
constructor(
|
|
17
|
+
constructor(connectionInfoOrUrl?: string | ConnectionInfo);
|
|
18
18
|
/**
|
|
19
19
|
* Gets the RPC's status
|
|
20
20
|
* @see {@link https://docs.near.org/docs/develop/front-end/rpc#general-validator-status}
|
|
@@ -32,11 +32,18 @@ let _nextId = 123;
|
|
|
32
32
|
*/
|
|
33
33
|
class JsonRpcProvider extends provider_1.Provider {
|
|
34
34
|
/**
|
|
35
|
-
* @param
|
|
35
|
+
* @param connectionInfoOrUrl ConnectionInfo or RPC API endpoint URL (deprecated)
|
|
36
36
|
*/
|
|
37
|
-
constructor(
|
|
37
|
+
constructor(connectionInfoOrUrl) {
|
|
38
38
|
super();
|
|
39
|
-
|
|
39
|
+
if (connectionInfoOrUrl != null && typeof connectionInfoOrUrl == 'object') {
|
|
40
|
+
this.connection = connectionInfoOrUrl;
|
|
41
|
+
}
|
|
42
|
+
else {
|
|
43
|
+
const deprecate = depd_1.default('JsonRpcProvider(url?: string)');
|
|
44
|
+
deprecate('use `JsonRpcProvider(connectionInfo: ConnectionInfo)` instead');
|
|
45
|
+
this.connection = { url: connectionInfoOrUrl };
|
|
46
|
+
}
|
|
40
47
|
}
|
|
41
48
|
/**
|
|
42
49
|
* Gets the RPC's status
|
|
@@ -106,7 +113,7 @@ class JsonRpcProvider extends provider_1.Provider {
|
|
|
106
113
|
async query(...args) {
|
|
107
114
|
let result;
|
|
108
115
|
if (args.length === 1) {
|
|
109
|
-
result = await this.sendJsonRpc('query',
|
|
116
|
+
result = await this.sendJsonRpc('query', args[0]);
|
|
110
117
|
}
|
|
111
118
|
else {
|
|
112
119
|
const [path, data] = args;
|
|
@@ -327,7 +334,9 @@ class JsonRpcProvider extends provider_1.Provider {
|
|
|
327
334
|
}
|
|
328
335
|
catch (error) {
|
|
329
336
|
if (error.type === 'TimeoutError') {
|
|
330
|
-
|
|
337
|
+
if (!process.env['NEAR_NO_LOGS']) {
|
|
338
|
+
console.warn(`Retrying request to ${method} as it has timed out`, params);
|
|
339
|
+
}
|
|
331
340
|
return null;
|
|
332
341
|
}
|
|
333
342
|
throw error;
|
package/lib/utils/errors.js
CHANGED
package/lib/utils/key_pair.d.ts
CHANGED
|
@@ -17,6 +17,7 @@ export declare class PublicKey extends Assignable {
|
|
|
17
17
|
static from(value: string | PublicKey): PublicKey;
|
|
18
18
|
static fromString(encodedKey: string): PublicKey;
|
|
19
19
|
toString(): string;
|
|
20
|
+
verify(message: Uint8Array, signature: Uint8Array): boolean;
|
|
20
21
|
}
|
|
21
22
|
export declare abstract class KeyPair {
|
|
22
23
|
abstract sign(message: Uint8Array): Signature;
|
package/lib/utils/key_pair.js
CHANGED
|
@@ -49,6 +49,12 @@ class PublicKey extends enums_1.Assignable {
|
|
|
49
49
|
toString() {
|
|
50
50
|
return `${key_type_to_str(this.keyType)}:${serialize_1.base_encode(this.data)}`;
|
|
51
51
|
}
|
|
52
|
+
verify(message, signature) {
|
|
53
|
+
switch (this.keyType) {
|
|
54
|
+
case KeyType.ED25519: return tweetnacl_1.default.sign.detached.verify(message, signature, this.data);
|
|
55
|
+
default: throw new Error(`Unknown key type ${this.keyType}`);
|
|
56
|
+
}
|
|
57
|
+
}
|
|
52
58
|
}
|
|
53
59
|
exports.PublicKey = PublicKey;
|
|
54
60
|
class KeyPair {
|
|
@@ -114,7 +120,7 @@ class KeyPairEd25519 extends KeyPair {
|
|
|
114
120
|
return { signature, publicKey: this.publicKey };
|
|
115
121
|
}
|
|
116
122
|
verify(message, signature) {
|
|
117
|
-
return
|
|
123
|
+
return this.publicKey.verify(message, signature);
|
|
118
124
|
}
|
|
119
125
|
toString() {
|
|
120
126
|
return `ed25519:${this.secretKey}`;
|
package/lib/utils/web.d.ts
CHANGED
|
@@ -8,4 +8,4 @@ export interface ConnectionInfo {
|
|
|
8
8
|
[key: string]: string | number;
|
|
9
9
|
};
|
|
10
10
|
}
|
|
11
|
-
export declare function fetchJson(
|
|
11
|
+
export declare function fetchJson(connectionInfoOrUrl: string | ConnectionInfo, json?: string): Promise<any>;
|
package/lib/utils/web.js
CHANGED
|
@@ -11,24 +11,24 @@ const errors_1 = require("./errors");
|
|
|
11
11
|
const START_WAIT_TIME_MS = 1000;
|
|
12
12
|
const BACKOFF_MULTIPLIER = 1.5;
|
|
13
13
|
const RETRY_NUMBER = 10;
|
|
14
|
-
async function fetchJson(
|
|
15
|
-
let
|
|
16
|
-
if (typeof (
|
|
17
|
-
url =
|
|
14
|
+
async function fetchJson(connectionInfoOrUrl, json) {
|
|
15
|
+
let connectionInfo = { url: null };
|
|
16
|
+
if (typeof (connectionInfoOrUrl) === 'string') {
|
|
17
|
+
connectionInfo.url = connectionInfoOrUrl;
|
|
18
18
|
}
|
|
19
19
|
else {
|
|
20
|
-
|
|
20
|
+
connectionInfo = connectionInfoOrUrl;
|
|
21
21
|
}
|
|
22
22
|
const response = await exponential_backoff_1.default(START_WAIT_TIME_MS, RETRY_NUMBER, BACKOFF_MULTIPLIER, async () => {
|
|
23
23
|
try {
|
|
24
|
-
const response = await fetch(url, {
|
|
24
|
+
const response = await fetch(connectionInfo.url, {
|
|
25
25
|
method: json ? 'POST' : 'GET',
|
|
26
26
|
body: json ? json : undefined,
|
|
27
|
-
headers: { 'Content-Type': 'application/json
|
|
27
|
+
headers: { ...connectionInfo.headers, 'Content-Type': 'application/json' }
|
|
28
28
|
});
|
|
29
29
|
if (!response.ok) {
|
|
30
30
|
if (response.status === 503) {
|
|
31
|
-
errors_1.logWarning(`Retrying HTTP request for ${url} as it's not available now`);
|
|
31
|
+
errors_1.logWarning(`Retrying HTTP request for ${connectionInfo.url} as it's not available now`);
|
|
32
32
|
return null;
|
|
33
33
|
}
|
|
34
34
|
throw http_errors_1.default(response.status, await response.text());
|
|
@@ -37,14 +37,14 @@ async function fetchJson(connection, json) {
|
|
|
37
37
|
}
|
|
38
38
|
catch (error) {
|
|
39
39
|
if (error.toString().includes('FetchError') || error.toString().includes('Failed to fetch')) {
|
|
40
|
-
errors_1.logWarning(`Retrying HTTP request for ${url} because of error: ${error}`);
|
|
40
|
+
errors_1.logWarning(`Retrying HTTP request for ${connectionInfo.url} because of error: ${error}`);
|
|
41
41
|
return null;
|
|
42
42
|
}
|
|
43
43
|
throw error;
|
|
44
44
|
}
|
|
45
45
|
});
|
|
46
46
|
if (!response) {
|
|
47
|
-
throw new providers_1.TypedError(`Exceeded ${RETRY_NUMBER} attempts for ${url}.`, 'RetriesExceeded');
|
|
47
|
+
throw new providers_1.TypedError(`Exceeded ${RETRY_NUMBER} attempts for ${connectionInfo.url}.`, 'RetriesExceeded');
|
|
48
48
|
}
|
|
49
49
|
return await response.json();
|
|
50
50
|
}
|
package/lib/validators.d.ts
CHANGED
|
@@ -3,9 +3,11 @@ import { CurrentEpochValidatorInfo, NextEpochValidatorInfo } from './providers/p
|
|
|
3
3
|
/** Finds seat price given validators stakes and number of seats.
|
|
4
4
|
* Calculation follow the spec: https://nomicon.io/Economics/README.html#validator-selection
|
|
5
5
|
* @params validators: current or next epoch validators.
|
|
6
|
-
* @params
|
|
6
|
+
* @params maxNumberOfSeats: maximum number of seats in the network.
|
|
7
|
+
* @params minimumStakeRatio: minimum stake ratio
|
|
8
|
+
* @params protocolVersion: version of the protocol from genesis config
|
|
7
9
|
*/
|
|
8
|
-
export declare function findSeatPrice(validators: (CurrentEpochValidatorInfo | NextEpochValidatorInfo)[],
|
|
10
|
+
export declare function findSeatPrice(validators: (CurrentEpochValidatorInfo | NextEpochValidatorInfo)[], maxNumberOfSeats: number, minimumStakeRatio: number[], protocolVersion?: number): BN;
|
|
9
11
|
export interface ChangedValidatorInfo {
|
|
10
12
|
current: CurrentEpochValidatorInfo;
|
|
11
13
|
next: NextEpochValidatorInfo;
|
package/lib/validators.js
CHANGED
|
@@ -5,12 +5,27 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.diffEpochValidators = exports.findSeatPrice = void 0;
|
|
7
7
|
const bn_js_1 = __importDefault(require("bn.js"));
|
|
8
|
+
const depd_1 = __importDefault(require("depd"));
|
|
8
9
|
/** Finds seat price given validators stakes and number of seats.
|
|
9
10
|
* Calculation follow the spec: https://nomicon.io/Economics/README.html#validator-selection
|
|
10
11
|
* @params validators: current or next epoch validators.
|
|
11
|
-
* @params
|
|
12
|
+
* @params maxNumberOfSeats: maximum number of seats in the network.
|
|
13
|
+
* @params minimumStakeRatio: minimum stake ratio
|
|
14
|
+
* @params protocolVersion: version of the protocol from genesis config
|
|
12
15
|
*/
|
|
13
|
-
function findSeatPrice(validators,
|
|
16
|
+
function findSeatPrice(validators, maxNumberOfSeats, minimumStakeRatio, protocolVersion) {
|
|
17
|
+
if (protocolVersion && protocolVersion < 49) {
|
|
18
|
+
return findSeatPriceForProtocolBefore49(validators, maxNumberOfSeats);
|
|
19
|
+
}
|
|
20
|
+
if (!minimumStakeRatio) {
|
|
21
|
+
const deprecate = depd_1.default('findSeatPrice(validators, maxNumberOfSeats)');
|
|
22
|
+
deprecate('`use `findSeatPrice(validators, maxNumberOfSeats, minimumStakeRatio)` instead');
|
|
23
|
+
minimumStakeRatio = [1, 6250]; // harcoded minimumStakeRation from 12/7/21
|
|
24
|
+
}
|
|
25
|
+
return findSeatPriceForProtocolAfter49(validators, maxNumberOfSeats, minimumStakeRatio);
|
|
26
|
+
}
|
|
27
|
+
exports.findSeatPrice = findSeatPrice;
|
|
28
|
+
function findSeatPriceForProtocolBefore49(validators, numSeats) {
|
|
14
29
|
const stakes = validators.map(v => new bn_js_1.default(v.stake, 10)).sort((a, b) => a.cmp(b));
|
|
15
30
|
const num = new bn_js_1.default(numSeats);
|
|
16
31
|
const stakesSum = stakes.reduce((a, b) => a.add(b));
|
|
@@ -37,7 +52,20 @@ function findSeatPrice(validators, numSeats) {
|
|
|
37
52
|
}
|
|
38
53
|
return left;
|
|
39
54
|
}
|
|
40
|
-
|
|
55
|
+
// nearcore reference: https://github.com/near/nearcore/blob/5a8ae263ec07930cd34d0dcf5bcee250c67c02aa/chain/epoch_manager/src/validator_selection.rs#L308;L315
|
|
56
|
+
function findSeatPriceForProtocolAfter49(validators, maxNumberOfSeats, minimumStakeRatio) {
|
|
57
|
+
if (minimumStakeRatio.length != 2) {
|
|
58
|
+
throw Error('minimumStakeRatio should have 2 elements');
|
|
59
|
+
}
|
|
60
|
+
const stakes = validators.map(v => new bn_js_1.default(v.stake, 10)).sort((a, b) => a.cmp(b));
|
|
61
|
+
const stakesSum = stakes.reduce((a, b) => a.add(b));
|
|
62
|
+
if (validators.length < maxNumberOfSeats) {
|
|
63
|
+
return stakesSum.mul(new bn_js_1.default(minimumStakeRatio[0])).div(new bn_js_1.default(minimumStakeRatio[1]));
|
|
64
|
+
}
|
|
65
|
+
else {
|
|
66
|
+
return stakes[0].add(new bn_js_1.default(1));
|
|
67
|
+
}
|
|
68
|
+
}
|
|
41
69
|
/** Diff validators between current and next epoch.
|
|
42
70
|
* Returns additions, subtractions and changes to validator set.
|
|
43
71
|
* @params currentValidators: list of current validators.
|
package/lib/wallet-account.js
CHANGED
|
@@ -164,6 +164,8 @@ class WalletConnection {
|
|
|
164
164
|
currentUrl.searchParams.delete('public_key');
|
|
165
165
|
currentUrl.searchParams.delete('all_keys');
|
|
166
166
|
currentUrl.searchParams.delete('account_id');
|
|
167
|
+
currentUrl.searchParams.delete('meta');
|
|
168
|
+
currentUrl.searchParams.delete('transactionHashes');
|
|
167
169
|
window.history.replaceState({}, document.title, currentUrl.toString());
|
|
168
170
|
}
|
|
169
171
|
/**
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "near-api-js",
|
|
3
3
|
"description": "JavaScript library to interact with NEAR Protocol via RPC API",
|
|
4
|
-
"version": "0.
|
|
4
|
+
"version": "0.44.2",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
7
7
|
"url": "git+https://github.com/near/near-api-js.git"
|
|
@@ -33,6 +33,7 @@
|
|
|
33
33
|
"danger": "^10.6.6",
|
|
34
34
|
"danger-plugin-yarn": "^1.3.2",
|
|
35
35
|
"eslint": "^6.5.1",
|
|
36
|
+
"husky": "^7.0.4",
|
|
36
37
|
"in-publish": "^2.0.0",
|
|
37
38
|
"jest": "^26.0.1",
|
|
38
39
|
"localstorage-memory": "^1.0.3",
|