FRE-600: Fix code review blockers

- Consolidated duplicate UndoManagers to single instance
- Fixed connection promise to only resolve on 'connected' status
- Fixed WebSocketProvider import (WebsocketProvider)
- Added proper doc.destroy() cleanup
- Renamed isPresenceInitialized property to avoid conflict

Co-Authored-By: Paperclip <noreply@paperclip.ing>
This commit is contained in:
2026-04-25 00:08:01 -04:00
parent 65b552bb08
commit 7c684a42cc
48450 changed files with 5679671 additions and 383 deletions

202
node_modules/@solana/wallet-standard-util/LICENSE generated vendored Normal file
View File

@@ -0,0 +1,202 @@
Apache License
Version 2.0, January 2004
http://www.apache.org/licenses/
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
1. Definitions.
"License" shall mean the terms and conditions for use, reproduction,
and distribution as defined by Sections 1 through 9 of this document.
"Licensor" shall mean the copyright owner or entity authorized by
the copyright owner that is granting the License.
"Legal Entity" shall mean the union of the acting entity and all
other entities that control, are controlled by, or are under common
control with that entity. For the purposes of this definition,
"control" means (i) the power, direct or indirect, to cause the
direction or management of such entity, whether by contract or
otherwise, or (ii) ownership of fifty percent (50%) or more of the
outstanding shares, or (iii) beneficial ownership of such entity.
"You" (or "Your") shall mean an individual or Legal Entity
exercising permissions granted by this License.
"Source" form shall mean the preferred form for making modifications,
including but not limited to software source code, documentation
source, and configuration files.
"Object" form shall mean any form resulting from mechanical
transformation or translation of a Source form, including but
not limited to compiled object code, generated documentation,
and conversions to other media types.
"Work" shall mean the work of authorship, whether in Source or
Object form, made available under the License, as indicated by a
copyright notice that is included in or attached to the work
(an example is provided in the Appendix below).
"Derivative Works" shall mean any work, whether in Source or Object
form, that is based on (or derived from) the Work and for which the
editorial revisions, annotations, elaborations, or other modifications
represent, as a whole, an original work of authorship. For the purposes
of this License, Derivative Works shall not include works that remain
separable from, or merely link (or bind by name) to the interfaces of,
the Work and Derivative Works thereof.
"Contribution" shall mean any work of authorship, including
the original version of the Work and any modifications or additions
to that Work or Derivative Works thereof, that is intentionally
submitted to Licensor for inclusion in the Work by the copyright owner
or by an individual or Legal Entity authorized to submit on behalf of
the copyright owner. For the purposes of this definition, "submitted"
means any form of electronic, verbal, or written communication sent
to the Licensor or its representatives, including but not limited to
communication on electronic mailing lists, source code control systems,
and issue tracking systems that are managed by, or on behalf of, the
Licensor for the purpose of discussing and improving the Work, but
excluding communication that is conspicuously marked or otherwise
designated in writing by the copyright owner as "Not a Contribution."
"Contributor" shall mean Licensor and any individual or Legal Entity
on behalf of whom a Contribution has been received by Licensor and
subsequently incorporated within the Work.
2. Grant of Copyright License. Subject to the terms and conditions of
this License, each Contributor hereby grants to You a perpetual,
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
copyright license to reproduce, prepare Derivative Works of,
publicly display, publicly perform, sublicense, and distribute the
Work and such Derivative Works in Source or Object form.
3. Grant of Patent License. Subject to the terms and conditions of
this License, each Contributor hereby grants to You a perpetual,
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
(except as stated in this section) patent license to make, have made,
use, offer to sell, sell, import, and otherwise transfer the Work,
where such license applies only to those patent claims licensable
by such Contributor that are necessarily infringed by their
Contribution(s) alone or by combination of their Contribution(s)
with the Work to which such Contribution(s) was submitted. If You
institute patent litigation against any entity (including a
cross-claim or counterclaim in a lawsuit) alleging that the Work
or a Contribution incorporated within the Work constitutes direct
or contributory patent infringement, then any patent licenses
granted to You under this License for that Work shall terminate
as of the date such litigation is filed.
4. Redistribution. You may reproduce and distribute copies of the
Work or Derivative Works thereof in any medium, with or without
modifications, and in Source or Object form, provided that You
meet the following conditions:
(a) You must give any other recipients of the Work or
Derivative Works a copy of this License; and
(b) You must cause any modified files to carry prominent notices
stating that You changed the files; and
(c) You must retain, in the Source form of any Derivative Works
that You distribute, all copyright, patent, trademark, and
attribution notices from the Source form of the Work,
excluding those notices that do not pertain to any part of
the Derivative Works; and
(d) If the Work includes a "NOTICE" text file as part of its
distribution, then any Derivative Works that You distribute must
include a readable copy of the attribution notices contained
within such NOTICE file, excluding those notices that do not
pertain to any part of the Derivative Works, in at least one
of the following places: within a NOTICE text file distributed
as part of the Derivative Works; within the Source form or
documentation, if provided along with the Derivative Works; or,
within a display generated by the Derivative Works, if and
wherever such third-party notices normally appear. The contents
of the NOTICE file are for informational purposes only and
do not modify the License. You may add Your own attribution
notices within Derivative Works that You distribute, alongside
or as an addendum to the NOTICE text from the Work, provided
that such additional attribution notices cannot be construed
as modifying the License.
You may add Your own copyright statement to Your modifications and
may provide additional or different license terms and conditions
for use, reproduction, or distribution of Your modifications, or
for any such Derivative Works as a whole, provided Your use,
reproduction, and distribution of the Work otherwise complies with
the conditions stated in this License.
5. Submission of Contributions. Unless You explicitly state otherwise,
any Contribution intentionally submitted for inclusion in the Work
by You to the Licensor shall be under the terms and conditions of
this License, without any additional terms or conditions.
Notwithstanding the above, nothing herein shall supersede or modify
the terms of any separate license agreement you may have executed
with Licensor regarding such Contributions.
6. Trademarks. This License does not grant permission to use the trade
names, trademarks, service marks, or product names of the Licensor,
except as required for reasonable and customary use in describing the
origin of the Work and reproducing the content of the NOTICE file.
7. Disclaimer of Warranty. Unless required by applicable law or
agreed to in writing, Licensor provides the Work (and each
Contributor provides its Contributions) on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
implied, including, without limitation, any warranties or conditions
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
PARTICULAR PURPOSE. You are solely responsible for determining the
appropriateness of using or redistributing the Work and assume any
risks associated with Your exercise of permissions under this License.
8. Limitation of Liability. In no event and under no legal theory,
whether in tort (including negligence), contract, or otherwise,
unless required by applicable law (such as deliberate and grossly
negligent acts) or agreed to in writing, shall any Contributor be
liable to You for damages, including any direct, indirect, special,
incidental, or consequential damages of any character arising as a
result of this License or out of the use or inability to use the
Work (including but not limited to damages for loss of goodwill,
work stoppage, computer failure or malfunction, or any and all
other commercial damages or losses), even if such Contributor
has been advised of the possibility of such damages.
9. Accepting Warranty or Additional Liability. While redistributing
the Work or Derivative Works thereof, You may choose to offer,
and charge a fee for, acceptance of support, warranty, indemnity,
or other liability obligations and/or rights consistent with this
License. However, in accepting such obligations, You may act only
on Your own behalf and on Your sole responsibility, not on behalf
of any other Contributor, and only if You agree to indemnify,
defend, and hold each Contributor harmless for any liability
incurred by, or claims asserted against, such Contributor by reason
of your accepting any such warranty or additional liability.
END OF TERMS AND CONDITIONS
APPENDIX: How to apply the Apache License to your work.
To apply the Apache License to your work, attach the following
boilerplate notice, with the fields enclosed by brackets "[]"
replaced with your own identifying information. (Don't include
the brackets!) The text should be enclosed in the appropriate
comment syntax for the file format. We also recommend that a
file or class name and description of purpose be included on the
same "printed page" as the copyright notice for easier
identification within third-party archives.
Copyright [yyyy] [name of copyright owner]
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

0
node_modules/@solana/wallet-standard-util/README.md generated vendored Normal file
View File

View File

@@ -0,0 +1,26 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.getCommitment = getCommitment;
/**
* TODO: docs
*/
function getCommitment(commitment) {
switch (commitment) {
case 'processed':
case 'confirmed':
case 'finalized':
case undefined:
return commitment;
case 'recent':
return 'processed';
case 'single':
case 'singleGossip':
return 'confirmed';
case 'max':
case 'root':
return 'finalized';
default:
return undefined;
}
}
//# sourceMappingURL=commitment.js.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"commitment.js","sourceRoot":"","sources":["../../src/commitment.ts"],"names":[],"mappings":";;AAQA,sCAkBC;AArBD;;GAEG;AACH,SAAgB,aAAa,CAAC,UAAuB;IACjD,QAAQ,UAAU,EAAE,CAAC;QACjB,KAAK,WAAW,CAAC;QACjB,KAAK,WAAW,CAAC;QACjB,KAAK,WAAW,CAAC;QACjB,KAAK,SAAS;YACV,OAAO,UAAU,CAAC;QACtB,KAAK,QAAQ;YACT,OAAO,WAAW,CAAC;QACvB,KAAK,QAAQ,CAAC;QACd,KAAK,cAAc;YACf,OAAO,WAAW,CAAC;QACvB,KAAK,KAAK,CAAC;QACX,KAAK,MAAM;YACP,OAAO,WAAW,CAAC;QACvB;YACI,OAAO,SAAS,CAAC;IACzB,CAAC;AACL,CAAC"}

View File

@@ -0,0 +1,45 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.LOCALNET_ENDPOINT = exports.TESTNET_ENDPOINT = exports.DEVNET_ENDPOINT = exports.MAINNET_ENDPOINT = void 0;
exports.getChainForEndpoint = getChainForEndpoint;
exports.getEndpointForChain = getEndpointForChain;
const wallet_standard_chains_1 = require("@solana/wallet-standard-chains");
/** TODO: docs */
exports.MAINNET_ENDPOINT = 'https://api.mainnet-beta.solana.com';
/** TODO: docs */
exports.DEVNET_ENDPOINT = 'https://api.devnet.solana.com';
/** TODO: docs */
exports.TESTNET_ENDPOINT = 'https://api.testnet.solana.com';
/** TODO: docs */
exports.LOCALNET_ENDPOINT = 'http://localhost:8899';
/**
* TODO: docs
*/
function getChainForEndpoint(endpoint) {
if (endpoint.includes(exports.MAINNET_ENDPOINT))
return wallet_standard_chains_1.SOLANA_MAINNET_CHAIN;
if (/\bdevnet\b/i.test(endpoint))
return wallet_standard_chains_1.SOLANA_DEVNET_CHAIN;
if (/\btestnet\b/i.test(endpoint))
return wallet_standard_chains_1.SOLANA_TESTNET_CHAIN;
if (/\blocalhost\b/i.test(endpoint) || /\b127\.0\.0\.1\b/.test(endpoint))
return wallet_standard_chains_1.SOLANA_LOCALNET_CHAIN;
return wallet_standard_chains_1.SOLANA_MAINNET_CHAIN;
}
/**
* TODO: docs
*/
function getEndpointForChain(chain, endpoint) {
if (endpoint)
return endpoint;
if (chain === wallet_standard_chains_1.SOLANA_MAINNET_CHAIN)
return exports.MAINNET_ENDPOINT;
if (chain === wallet_standard_chains_1.SOLANA_DEVNET_CHAIN)
return exports.DEVNET_ENDPOINT;
if (chain === wallet_standard_chains_1.SOLANA_TESTNET_CHAIN)
return exports.TESTNET_ENDPOINT;
if (chain === wallet_standard_chains_1.SOLANA_LOCALNET_CHAIN)
return exports.LOCALNET_ENDPOINT;
return exports.MAINNET_ENDPOINT;
}
//# sourceMappingURL=endpoint.js.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"endpoint.js","sourceRoot":"","sources":["../../src/endpoint.ts"],"names":[],"mappings":";;;AAoBA,kDAMC;AAKD,kDAOC;AArCD,2EAKwC;AAExC,iBAAiB;AACJ,QAAA,gBAAgB,GAAG,qCAAqC,CAAC;AACtE,iBAAiB;AACJ,QAAA,eAAe,GAAG,+BAA+B,CAAC;AAC/D,iBAAiB;AACJ,QAAA,gBAAgB,GAAG,gCAAgC,CAAC;AACjE,iBAAiB;AACJ,QAAA,iBAAiB,GAAG,uBAAuB,CAAC;AAEzD;;GAEG;AACH,SAAgB,mBAAmB,CAAC,QAAgB;IAChD,IAAI,QAAQ,CAAC,QAAQ,CAAC,wBAAgB,CAAC;QAAE,OAAO,6CAAoB,CAAC;IACrE,IAAI,aAAa,CAAC,IAAI,CAAC,QAAQ,CAAC;QAAE,OAAO,4CAAmB,CAAC;IAC7D,IAAI,cAAc,CAAC,IAAI,CAAC,QAAQ,CAAC;QAAE,OAAO,6CAAoB,CAAC;IAC/D,IAAI,gBAAgB,CAAC,IAAI,CAAC,QAAQ,CAAC,IAAI,kBAAkB,CAAC,IAAI,CAAC,QAAQ,CAAC;QAAE,OAAO,8CAAqB,CAAC;IACvG,OAAO,6CAAoB,CAAC;AAChC,CAAC;AAED;;GAEG;AACH,SAAgB,mBAAmB,CAAC,KAAkB,EAAE,QAAiB;IACrE,IAAI,QAAQ;QAAE,OAAO,QAAQ,CAAC;IAC9B,IAAI,KAAK,KAAK,6CAAoB;QAAE,OAAO,wBAAgB,CAAC;IAC5D,IAAI,KAAK,KAAK,4CAAmB;QAAE,OAAO,uBAAe,CAAC;IAC1D,IAAI,KAAK,KAAK,6CAAoB;QAAE,OAAO,wBAAgB,CAAC;IAC5D,IAAI,KAAK,KAAK,8CAAqB;QAAE,OAAO,yBAAiB,CAAC;IAC9D,OAAO,wBAAgB,CAAC;AAC5B,CAAC"}

View File

@@ -0,0 +1,21 @@
"use strict";
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
var desc = Object.getOwnPropertyDescriptor(m, k);
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
desc = { enumerable: true, get: function() { return m[k]; } };
}
Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
}));
var __exportStar = (this && this.__exportStar) || function(m, exports) {
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
};
Object.defineProperty(exports, "__esModule", { value: true });
__exportStar(require("./commitment.js"), exports);
__exportStar(require("./endpoint.js"), exports);
__exportStar(require("./signIn.js"), exports);
__exportStar(require("./signMessage.js"), exports);
//# sourceMappingURL=index.js.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,kDAAgC;AAChC,gDAA8B;AAC9B,8CAA4B;AAC5B,mDAAiC"}

View File

@@ -0,0 +1 @@
{ "type": "commonjs" }

View File

@@ -0,0 +1,186 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.verifySignIn = verifySignIn;
exports.deriveSignInMessage = deriveSignInMessage;
exports.deriveSignInMessageText = deriveSignInMessageText;
exports.parseSignInMessage = parseSignInMessage;
exports.parseSignInMessageText = parseSignInMessageText;
exports.createSignInMessage = createSignInMessage;
exports.createSignInMessageText = createSignInMessageText;
const signMessage_js_1 = require("./signMessage.js");
const util_js_1 = require("./util.js");
/**
* TODO: docs
*/
function verifySignIn(input, output) {
const { signedMessage, signature, account: { publicKey }, } = output;
const message = deriveSignInMessage(input, output);
return (!!message && (0, signMessage_js_1.verifyMessageSignature)({ message, signedMessage, signature, publicKey: publicKey }));
}
/**
* TODO: docs
*/
function deriveSignInMessage(input, output) {
const text = deriveSignInMessageText(input, output);
if (!text)
return null;
return new TextEncoder().encode(text);
}
/**
* TODO: docs
*/
function deriveSignInMessageText(input, output) {
const parsed = parseSignInMessage(output.signedMessage);
if (!parsed)
return null;
if (input.domain && input.domain !== parsed.domain)
return null;
if (input.address && input.address !== parsed.address)
return null;
if (input.statement !== parsed.statement)
return null;
if (input.uri !== parsed.uri)
return null;
if (input.version !== parsed.version)
return null;
if (input.chainId !== parsed.chainId)
return null;
if (input.nonce !== parsed.nonce)
return null;
if (input.issuedAt !== parsed.issuedAt)
return null;
if (input.expirationTime !== parsed.expirationTime)
return null;
if (input.notBefore !== parsed.notBefore)
return null;
if (input.requestId !== parsed.requestId)
return null;
if (input.resources) {
if (!parsed.resources)
return null;
if (!(0, util_js_1.arraysEqual)(input.resources, parsed.resources))
return null;
}
else if (parsed.resources)
return null;
return createSignInMessageText(parsed);
}
/**
* TODO: docs
*/
function parseSignInMessage(message) {
const text = new TextDecoder().decode(message);
return parseSignInMessageText(text);
}
// TODO: implement https://github.com/solana-labs/solana/blob/master/docs/src/proposals/off-chain-message-signing.md
const DOMAIN = '(?<domain>[^\\n]+?) wants you to sign in with your Solana account:\\n';
const ADDRESS = '(?<address>[^\\n]+)(?:\\n|$)';
const STATEMENT = '(?:\\n(?<statement>[\\S\\s]*?)(?:\\n|$))??';
const URI = '(?:\\nURI: (?<uri>[^\\n]+))?';
const VERSION = '(?:\\nVersion: (?<version>[^\\n]+))?';
const CHAIN_ID = '(?:\\nChain ID: (?<chainId>[^\\n]+))?';
const NONCE = '(?:\\nNonce: (?<nonce>[^\\n]+))?';
const ISSUED_AT = '(?:\\nIssued At: (?<issuedAt>[^\\n]+))?';
const EXPIRATION_TIME = '(?:\\nExpiration Time: (?<expirationTime>[^\\n]+))?';
const NOT_BEFORE = '(?:\\nNot Before: (?<notBefore>[^\\n]+))?';
const REQUEST_ID = '(?:\\nRequest ID: (?<requestId>[^\\n]+))?';
const RESOURCES = '(?:\\nResources:(?<resources>(?:\\n- [^\\n]+)*))?';
const FIELDS = `${URI}${VERSION}${CHAIN_ID}${NONCE}${ISSUED_AT}${EXPIRATION_TIME}${NOT_BEFORE}${REQUEST_ID}${RESOURCES}`;
const MESSAGE = new RegExp(`^${DOMAIN}${ADDRESS}${STATEMENT}${FIELDS}\\n*$`);
/**
* TODO: docs
*/
function parseSignInMessageText(text) {
var _a;
const match = MESSAGE.exec(text);
if (!match)
return null;
const groups = match.groups;
if (!groups)
return null;
return {
domain: groups.domain,
address: groups.address,
statement: groups.statement,
uri: groups.uri,
version: groups.version,
nonce: groups.nonce,
chainId: groups.chainId,
issuedAt: groups.issuedAt,
expirationTime: groups.expirationTime,
notBefore: groups.notBefore,
requestId: groups.requestId,
resources: (_a = groups.resources) === null || _a === void 0 ? void 0 : _a.split('\n- ').slice(1),
};
}
/**
* TODO: docs
*/
function createSignInMessage(input) {
const text = createSignInMessageText(input);
return new TextEncoder().encode(text);
}
/**
* TODO: docs
*/
function createSignInMessageText(input) {
// ${domain} wants you to sign in with your Solana account:
// ${address}
//
// ${statement}
//
// URI: ${uri}
// Version: ${version}
// Chain ID: ${chain}
// Nonce: ${nonce}
// Issued At: ${issued-at}
// Expiration Time: ${expiration-time}
// Not Before: ${not-before}
// Request ID: ${request-id}
// Resources:
// - ${resources[0]}
// - ${resources[1]}
// ...
// - ${resources[n]}
let message = `${input.domain} wants you to sign in with your Solana account:\n`;
message += `${input.address}`;
if (input.statement) {
message += `\n\n${input.statement}`;
}
const fields = [];
if (input.uri) {
fields.push(`URI: ${input.uri}`);
}
if (input.version) {
fields.push(`Version: ${input.version}`);
}
if (input.chainId) {
fields.push(`Chain ID: ${input.chainId}`);
}
if (input.nonce) {
fields.push(`Nonce: ${input.nonce}`);
}
if (input.issuedAt) {
fields.push(`Issued At: ${input.issuedAt}`);
}
if (input.expirationTime) {
fields.push(`Expiration Time: ${input.expirationTime}`);
}
if (input.notBefore) {
fields.push(`Not Before: ${input.notBefore}`);
}
if (input.requestId) {
fields.push(`Request ID: ${input.requestId}`);
}
if (input.resources) {
fields.push(`Resources:`);
for (const resource of input.resources) {
fields.push(`- ${resource}`);
}
}
if (fields.length) {
message += `\n\n${fields.join('\n')}`;
}
return message;
}
//# sourceMappingURL=signIn.js.map

File diff suppressed because one or more lines are too long

View File

@@ -0,0 +1,22 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.verifyMessageSignature = verifyMessageSignature;
exports.verifySignMessage = verifySignMessage;
const ed25519_1 = require("@noble/curves/ed25519");
const util_js_1 = require("./util.js");
/**
* TODO: docs
*/
function verifyMessageSignature({ message, signedMessage, signature, publicKey, }) {
// TODO: implement https://github.com/solana-labs/solana/blob/master/docs/src/proposals/off-chain-message-signing.md
return (0, util_js_1.bytesEqual)(message, signedMessage) && ed25519_1.ed25519.verify(signature, signedMessage, publicKey);
}
/**
* TODO: docs
*/
function verifySignMessage(input, output) {
const { message, account: { publicKey }, } = input;
const { signedMessage, signature } = output;
return verifyMessageSignature({ message, signedMessage, signature, publicKey: publicKey });
}
//# sourceMappingURL=signMessage.js.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"signMessage.js","sourceRoot":"","sources":["../../src/signMessage.ts"],"names":[],"mappings":";;AAOA,wDAaC;AAKD,8CAOC;AAhCD,mDAAgD;AAEhD,uCAAuC;AAEvC;;GAEG;AACH,SAAgB,sBAAsB,CAAC,EACnC,OAAO,EACP,aAAa,EACb,SAAS,EACT,SAAS,GAMZ;IACG,oHAAoH;IACpH,OAAO,IAAA,oBAAU,EAAC,OAAO,EAAE,aAAa,CAAC,IAAI,iBAAO,CAAC,MAAM,CAAC,SAAS,EAAE,aAAa,EAAE,SAAS,CAAC,CAAC;AACrG,CAAC;AAED;;GAEG;AACH,SAAgB,iBAAiB,CAAC,KAA6B,EAAE,MAA+B;IAC5F,MAAM,EACF,OAAO,EACP,OAAO,EAAE,EAAE,SAAS,EAAE,GACzB,GAAG,KAAK,CAAC;IACV,MAAM,EAAE,aAAa,EAAE,SAAS,EAAE,GAAG,MAAM,CAAC;IAC5C,OAAO,sBAAsB,CAAC,EAAE,OAAO,EAAE,aAAa,EAAE,SAAS,EAAE,SAAS,EAAE,SAAuB,EAAE,CAAC,CAAC;AAC7G,CAAC"}

View File

@@ -0,0 +1 @@
{"root":["../../src/commitment.ts","../../src/endpoint.ts","../../src/index.ts","../../src/signIn.ts","../../src/signMessage.ts","../../src/util.ts"],"version":"5.7.3"}

View File

@@ -0,0 +1,44 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.arraysEqual = arraysEqual;
exports.bytesEqual = bytesEqual;
/**
* @internal
*
* Efficiently compare {@link Indexed} arrays (e.g. `Array` and `Uint8Array`).
*
* @param a An array.
* @param b Another array.
*
* @return `true` if the arrays have the same length and elements, `false` otherwise.
*
* @group Internal
*/
function arraysEqual(a, b) {
if (a === b)
return true;
const length = a.length;
if (length !== b.length)
return false;
for (let i = 0; i < length; i++) {
if (a[i] !== b[i])
return false;
}
return true;
}
/**
* @internal
*
* Efficiently compare byte arrays, using {@link arraysEqual}.
*
* @param a A byte array.
* @param b Another byte array.
*
* @return `true` if the byte arrays have the same length and bytes, `false` otherwise.
*
* @group Internal
*/
function bytesEqual(a, b) {
return arraysEqual(a, b);
}
//# sourceMappingURL=util.js.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"util.js","sourceRoot":"","sources":["../../src/util.ts"],"names":[],"mappings":";;AA0BA,kCAWC;AAcD,gCAEC;AAvCD;;;;;;;;;;;GAWG;AACH,SAAgB,WAAW,CAAI,CAAa,EAAE,CAAa;IACvD,IAAI,CAAC,KAAK,CAAC;QAAE,OAAO,IAAI,CAAC;IAEzB,MAAM,MAAM,GAAG,CAAC,CAAC,MAAM,CAAC;IACxB,IAAI,MAAM,KAAK,CAAC,CAAC,MAAM;QAAE,OAAO,KAAK,CAAC;IAEtC,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,MAAM,EAAE,CAAC,EAAE,EAAE,CAAC;QAC9B,IAAI,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;YAAE,OAAO,KAAK,CAAC;IACpC,CAAC;IAED,OAAO,IAAI,CAAC;AAChB,CAAC;AAED;;;;;;;;;;;GAWG;AACH,SAAgB,UAAU,CAAC,CAAa,EAAE,CAAa;IACnD,OAAO,WAAW,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC;AAC7B,CAAC"}

View File

@@ -0,0 +1,23 @@
/**
* TODO: docs
*/
export function getCommitment(commitment) {
switch (commitment) {
case 'processed':
case 'confirmed':
case 'finalized':
case undefined:
return commitment;
case 'recent':
return 'processed';
case 'single':
case 'singleGossip':
return 'confirmed';
case 'max':
case 'root':
return 'finalized';
default:
return undefined;
}
}
//# sourceMappingURL=commitment.js.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"commitment.js","sourceRoot":"","sources":["../../src/commitment.ts"],"names":[],"mappings":"AAKA;;GAEG;AACH,MAAM,UAAU,aAAa,CAAC,UAAuB;IACjD,QAAQ,UAAU,EAAE,CAAC;QACjB,KAAK,WAAW,CAAC;QACjB,KAAK,WAAW,CAAC;QACjB,KAAK,WAAW,CAAC;QACjB,KAAK,SAAS;YACV,OAAO,UAAU,CAAC;QACtB,KAAK,QAAQ;YACT,OAAO,WAAW,CAAC;QACvB,KAAK,QAAQ,CAAC;QACd,KAAK,cAAc;YACf,OAAO,WAAW,CAAC;QACvB,KAAK,KAAK,CAAC;QACX,KAAK,MAAM;YACP,OAAO,WAAW,CAAC;QACvB;YACI,OAAO,SAAS,CAAC;IACzB,CAAC;AACL,CAAC"}

View File

@@ -0,0 +1,40 @@
import { SOLANA_DEVNET_CHAIN, SOLANA_LOCALNET_CHAIN, SOLANA_MAINNET_CHAIN, SOLANA_TESTNET_CHAIN, } from '@solana/wallet-standard-chains';
/** TODO: docs */
export const MAINNET_ENDPOINT = 'https://api.mainnet-beta.solana.com';
/** TODO: docs */
export const DEVNET_ENDPOINT = 'https://api.devnet.solana.com';
/** TODO: docs */
export const TESTNET_ENDPOINT = 'https://api.testnet.solana.com';
/** TODO: docs */
export const LOCALNET_ENDPOINT = 'http://localhost:8899';
/**
* TODO: docs
*/
export function getChainForEndpoint(endpoint) {
if (endpoint.includes(MAINNET_ENDPOINT))
return SOLANA_MAINNET_CHAIN;
if (/\bdevnet\b/i.test(endpoint))
return SOLANA_DEVNET_CHAIN;
if (/\btestnet\b/i.test(endpoint))
return SOLANA_TESTNET_CHAIN;
if (/\blocalhost\b/i.test(endpoint) || /\b127\.0\.0\.1\b/.test(endpoint))
return SOLANA_LOCALNET_CHAIN;
return SOLANA_MAINNET_CHAIN;
}
/**
* TODO: docs
*/
export function getEndpointForChain(chain, endpoint) {
if (endpoint)
return endpoint;
if (chain === SOLANA_MAINNET_CHAIN)
return MAINNET_ENDPOINT;
if (chain === SOLANA_DEVNET_CHAIN)
return DEVNET_ENDPOINT;
if (chain === SOLANA_TESTNET_CHAIN)
return TESTNET_ENDPOINT;
if (chain === SOLANA_LOCALNET_CHAIN)
return LOCALNET_ENDPOINT;
return MAINNET_ENDPOINT;
}
//# sourceMappingURL=endpoint.js.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"endpoint.js","sourceRoot":"","sources":["../../src/endpoint.ts"],"names":[],"mappings":"AACA,OAAO,EACH,mBAAmB,EACnB,qBAAqB,EACrB,oBAAoB,EACpB,oBAAoB,GACvB,MAAM,gCAAgC,CAAC;AAExC,iBAAiB;AACjB,MAAM,CAAC,MAAM,gBAAgB,GAAG,qCAAqC,CAAC;AACtE,iBAAiB;AACjB,MAAM,CAAC,MAAM,eAAe,GAAG,+BAA+B,CAAC;AAC/D,iBAAiB;AACjB,MAAM,CAAC,MAAM,gBAAgB,GAAG,gCAAgC,CAAC;AACjE,iBAAiB;AACjB,MAAM,CAAC,MAAM,iBAAiB,GAAG,uBAAuB,CAAC;AAEzD;;GAEG;AACH,MAAM,UAAU,mBAAmB,CAAC,QAAgB;IAChD,IAAI,QAAQ,CAAC,QAAQ,CAAC,gBAAgB,CAAC;QAAE,OAAO,oBAAoB,CAAC;IACrE,IAAI,aAAa,CAAC,IAAI,CAAC,QAAQ,CAAC;QAAE,OAAO,mBAAmB,CAAC;IAC7D,IAAI,cAAc,CAAC,IAAI,CAAC,QAAQ,CAAC;QAAE,OAAO,oBAAoB,CAAC;IAC/D,IAAI,gBAAgB,CAAC,IAAI,CAAC,QAAQ,CAAC,IAAI,kBAAkB,CAAC,IAAI,CAAC,QAAQ,CAAC;QAAE,OAAO,qBAAqB,CAAC;IACvG,OAAO,oBAAoB,CAAC;AAChC,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,mBAAmB,CAAC,KAAkB,EAAE,QAAiB;IACrE,IAAI,QAAQ;QAAE,OAAO,QAAQ,CAAC;IAC9B,IAAI,KAAK,KAAK,oBAAoB;QAAE,OAAO,gBAAgB,CAAC;IAC5D,IAAI,KAAK,KAAK,mBAAmB;QAAE,OAAO,eAAe,CAAC;IAC1D,IAAI,KAAK,KAAK,oBAAoB;QAAE,OAAO,gBAAgB,CAAC;IAC5D,IAAI,KAAK,KAAK,qBAAqB;QAAE,OAAO,iBAAiB,CAAC;IAC9D,OAAO,gBAAgB,CAAC;AAC5B,CAAC"}

View File

@@ -0,0 +1,5 @@
export * from './commitment.js';
export * from './endpoint.js';
export * from './signIn.js';
export * from './signMessage.js';
//# sourceMappingURL=index.js.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,iBAAiB,CAAC;AAChC,cAAc,eAAe,CAAC;AAC9B,cAAc,aAAa,CAAC;AAC5B,cAAc,kBAAkB,CAAC"}

View File

@@ -0,0 +1,176 @@
import { verifyMessageSignature } from './signMessage.js';
import { arraysEqual } from './util.js';
/**
* TODO: docs
*/
export function verifySignIn(input, output) {
const { signedMessage, signature, account: { publicKey }, } = output;
const message = deriveSignInMessage(input, output);
return (!!message && verifyMessageSignature({ message, signedMessage, signature, publicKey: publicKey }));
}
/**
* TODO: docs
*/
export function deriveSignInMessage(input, output) {
const text = deriveSignInMessageText(input, output);
if (!text)
return null;
return new TextEncoder().encode(text);
}
/**
* TODO: docs
*/
export function deriveSignInMessageText(input, output) {
const parsed = parseSignInMessage(output.signedMessage);
if (!parsed)
return null;
if (input.domain && input.domain !== parsed.domain)
return null;
if (input.address && input.address !== parsed.address)
return null;
if (input.statement !== parsed.statement)
return null;
if (input.uri !== parsed.uri)
return null;
if (input.version !== parsed.version)
return null;
if (input.chainId !== parsed.chainId)
return null;
if (input.nonce !== parsed.nonce)
return null;
if (input.issuedAt !== parsed.issuedAt)
return null;
if (input.expirationTime !== parsed.expirationTime)
return null;
if (input.notBefore !== parsed.notBefore)
return null;
if (input.requestId !== parsed.requestId)
return null;
if (input.resources) {
if (!parsed.resources)
return null;
if (!arraysEqual(input.resources, parsed.resources))
return null;
}
else if (parsed.resources)
return null;
return createSignInMessageText(parsed);
}
/**
* TODO: docs
*/
export function parseSignInMessage(message) {
const text = new TextDecoder().decode(message);
return parseSignInMessageText(text);
}
// TODO: implement https://github.com/solana-labs/solana/blob/master/docs/src/proposals/off-chain-message-signing.md
const DOMAIN = '(?<domain>[^\\n]+?) wants you to sign in with your Solana account:\\n';
const ADDRESS = '(?<address>[^\\n]+)(?:\\n|$)';
const STATEMENT = '(?:\\n(?<statement>[\\S\\s]*?)(?:\\n|$))??';
const URI = '(?:\\nURI: (?<uri>[^\\n]+))?';
const VERSION = '(?:\\nVersion: (?<version>[^\\n]+))?';
const CHAIN_ID = '(?:\\nChain ID: (?<chainId>[^\\n]+))?';
const NONCE = '(?:\\nNonce: (?<nonce>[^\\n]+))?';
const ISSUED_AT = '(?:\\nIssued At: (?<issuedAt>[^\\n]+))?';
const EXPIRATION_TIME = '(?:\\nExpiration Time: (?<expirationTime>[^\\n]+))?';
const NOT_BEFORE = '(?:\\nNot Before: (?<notBefore>[^\\n]+))?';
const REQUEST_ID = '(?:\\nRequest ID: (?<requestId>[^\\n]+))?';
const RESOURCES = '(?:\\nResources:(?<resources>(?:\\n- [^\\n]+)*))?';
const FIELDS = `${URI}${VERSION}${CHAIN_ID}${NONCE}${ISSUED_AT}${EXPIRATION_TIME}${NOT_BEFORE}${REQUEST_ID}${RESOURCES}`;
const MESSAGE = new RegExp(`^${DOMAIN}${ADDRESS}${STATEMENT}${FIELDS}\\n*$`);
/**
* TODO: docs
*/
export function parseSignInMessageText(text) {
const match = MESSAGE.exec(text);
if (!match)
return null;
const groups = match.groups;
if (!groups)
return null;
return {
domain: groups.domain,
address: groups.address,
statement: groups.statement,
uri: groups.uri,
version: groups.version,
nonce: groups.nonce,
chainId: groups.chainId,
issuedAt: groups.issuedAt,
expirationTime: groups.expirationTime,
notBefore: groups.notBefore,
requestId: groups.requestId,
resources: groups.resources?.split('\n- ').slice(1),
};
}
/**
* TODO: docs
*/
export function createSignInMessage(input) {
const text = createSignInMessageText(input);
return new TextEncoder().encode(text);
}
/**
* TODO: docs
*/
export function createSignInMessageText(input) {
// ${domain} wants you to sign in with your Solana account:
// ${address}
//
// ${statement}
//
// URI: ${uri}
// Version: ${version}
// Chain ID: ${chain}
// Nonce: ${nonce}
// Issued At: ${issued-at}
// Expiration Time: ${expiration-time}
// Not Before: ${not-before}
// Request ID: ${request-id}
// Resources:
// - ${resources[0]}
// - ${resources[1]}
// ...
// - ${resources[n]}
let message = `${input.domain} wants you to sign in with your Solana account:\n`;
message += `${input.address}`;
if (input.statement) {
message += `\n\n${input.statement}`;
}
const fields = [];
if (input.uri) {
fields.push(`URI: ${input.uri}`);
}
if (input.version) {
fields.push(`Version: ${input.version}`);
}
if (input.chainId) {
fields.push(`Chain ID: ${input.chainId}`);
}
if (input.nonce) {
fields.push(`Nonce: ${input.nonce}`);
}
if (input.issuedAt) {
fields.push(`Issued At: ${input.issuedAt}`);
}
if (input.expirationTime) {
fields.push(`Expiration Time: ${input.expirationTime}`);
}
if (input.notBefore) {
fields.push(`Not Before: ${input.notBefore}`);
}
if (input.requestId) {
fields.push(`Request ID: ${input.requestId}`);
}
if (input.resources) {
fields.push(`Resources:`);
for (const resource of input.resources) {
fields.push(`- ${resource}`);
}
}
if (fields.length) {
message += `\n\n${fields.join('\n')}`;
}
return message;
}
//# sourceMappingURL=signIn.js.map

File diff suppressed because one or more lines are too long

View File

@@ -0,0 +1,18 @@
import { ed25519 } from '@noble/curves/ed25519';
import { bytesEqual } from './util.js';
/**
* TODO: docs
*/
export function verifyMessageSignature({ message, signedMessage, signature, publicKey, }) {
// TODO: implement https://github.com/solana-labs/solana/blob/master/docs/src/proposals/off-chain-message-signing.md
return bytesEqual(message, signedMessage) && ed25519.verify(signature, signedMessage, publicKey);
}
/**
* TODO: docs
*/
export function verifySignMessage(input, output) {
const { message, account: { publicKey }, } = input;
const { signedMessage, signature } = output;
return verifyMessageSignature({ message, signedMessage, signature, publicKey: publicKey });
}
//# sourceMappingURL=signMessage.js.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"signMessage.js","sourceRoot":"","sources":["../../src/signMessage.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,uBAAuB,CAAC;AAEhD,OAAO,EAAE,UAAU,EAAE,MAAM,WAAW,CAAC;AAEvC;;GAEG;AACH,MAAM,UAAU,sBAAsB,CAAC,EACnC,OAAO,EACP,aAAa,EACb,SAAS,EACT,SAAS,GAMZ;IACG,oHAAoH;IACpH,OAAO,UAAU,CAAC,OAAO,EAAE,aAAa,CAAC,IAAI,OAAO,CAAC,MAAM,CAAC,SAAS,EAAE,aAAa,EAAE,SAAS,CAAC,CAAC;AACrG,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,iBAAiB,CAAC,KAA6B,EAAE,MAA+B;IAC5F,MAAM,EACF,OAAO,EACP,OAAO,EAAE,EAAE,SAAS,EAAE,GACzB,GAAG,KAAK,CAAC;IACV,MAAM,EAAE,aAAa,EAAE,SAAS,EAAE,GAAG,MAAM,CAAC;IAC5C,OAAO,sBAAsB,CAAC,EAAE,OAAO,EAAE,aAAa,EAAE,SAAS,EAAE,SAAS,EAAE,SAAuB,EAAE,CAAC,CAAC;AAC7G,CAAC"}

View File

@@ -0,0 +1 @@
{"root":["../../src/commitment.ts","../../src/endpoint.ts","../../src/index.ts","../../src/signIn.ts","../../src/signMessage.ts","../../src/util.ts"],"version":"5.7.3"}

View File

@@ -0,0 +1,40 @@
/**
* @internal
*
* Efficiently compare {@link Indexed} arrays (e.g. `Array` and `Uint8Array`).
*
* @param a An array.
* @param b Another array.
*
* @return `true` if the arrays have the same length and elements, `false` otherwise.
*
* @group Internal
*/
export function arraysEqual(a, b) {
if (a === b)
return true;
const length = a.length;
if (length !== b.length)
return false;
for (let i = 0; i < length; i++) {
if (a[i] !== b[i])
return false;
}
return true;
}
/**
* @internal
*
* Efficiently compare byte arrays, using {@link arraysEqual}.
*
* @param a A byte array.
* @param b Another byte array.
*
* @return `true` if the byte arrays have the same length and bytes, `false` otherwise.
*
* @group Internal
*/
export function bytesEqual(a, b) {
return arraysEqual(a, b);
}
//# sourceMappingURL=util.js.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"util.js","sourceRoot":"","sources":["../../src/util.ts"],"names":[],"mappings":"AAcA;;;;;;;;;;;GAWG;AACH,MAAM,UAAU,WAAW,CAAI,CAAa,EAAE,CAAa;IACvD,IAAI,CAAC,KAAK,CAAC;QAAE,OAAO,IAAI,CAAC;IAEzB,MAAM,MAAM,GAAG,CAAC,CAAC,MAAM,CAAC;IACxB,IAAI,MAAM,KAAK,CAAC,CAAC,MAAM;QAAE,OAAO,KAAK,CAAC;IAEtC,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,MAAM,EAAE,CAAC,EAAE,EAAE,CAAC;QAC9B,IAAI,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;YAAE,OAAO,KAAK,CAAC;IACpC,CAAC;IAED,OAAO,IAAI,CAAC;AAChB,CAAC;AAED;;;;;;;;;;;GAWG;AACH,MAAM,UAAU,UAAU,CAAC,CAAa,EAAE,CAAa;IACnD,OAAO,WAAW,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC;AAC7B,CAAC"}

View File

@@ -0,0 +1,8 @@
import type { SolanaTransactionCommitment } from '@solana/wallet-standard-features';
type Commitment = 'processed' | 'confirmed' | 'finalized' | 'recent' | 'single' | 'singleGossip' | 'root' | 'max';
/**
* TODO: docs
*/
export declare function getCommitment(commitment?: Commitment): SolanaTransactionCommitment | undefined;
export {};
//# sourceMappingURL=commitment.d.ts.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"commitment.d.ts","sourceRoot":"","sources":["../../src/commitment.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,2BAA2B,EAAE,MAAM,kCAAkC,CAAC;AAGpF,KAAK,UAAU,GAAG,WAAW,GAAG,WAAW,GAAG,WAAW,GAAG,QAAQ,GAAG,QAAQ,GAAG,cAAc,GAAG,MAAM,GAAG,KAAK,CAAC;AAElH;;GAEG;AACH,wBAAgB,aAAa,CAAC,UAAU,CAAC,EAAE,UAAU,GAAG,2BAA2B,GAAG,SAAS,CAkB9F"}

View File

@@ -0,0 +1,18 @@
import type { SolanaChain } from '@solana/wallet-standard-chains';
/** TODO: docs */
export declare const MAINNET_ENDPOINT = "https://api.mainnet-beta.solana.com";
/** TODO: docs */
export declare const DEVNET_ENDPOINT = "https://api.devnet.solana.com";
/** TODO: docs */
export declare const TESTNET_ENDPOINT = "https://api.testnet.solana.com";
/** TODO: docs */
export declare const LOCALNET_ENDPOINT = "http://localhost:8899";
/**
* TODO: docs
*/
export declare function getChainForEndpoint(endpoint: string): SolanaChain;
/**
* TODO: docs
*/
export declare function getEndpointForChain(chain: SolanaChain, endpoint?: string): string;
//# sourceMappingURL=endpoint.d.ts.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"endpoint.d.ts","sourceRoot":"","sources":["../../src/endpoint.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,gCAAgC,CAAC;AAQlE,iBAAiB;AACjB,eAAO,MAAM,gBAAgB,wCAAwC,CAAC;AACtE,iBAAiB;AACjB,eAAO,MAAM,eAAe,kCAAkC,CAAC;AAC/D,iBAAiB;AACjB,eAAO,MAAM,gBAAgB,mCAAmC,CAAC;AACjE,iBAAiB;AACjB,eAAO,MAAM,iBAAiB,0BAA0B,CAAC;AAEzD;;GAEG;AACH,wBAAgB,mBAAmB,CAAC,QAAQ,EAAE,MAAM,GAAG,WAAW,CAMjE;AAED;;GAEG;AACH,wBAAgB,mBAAmB,CAAC,KAAK,EAAE,WAAW,EAAE,QAAQ,CAAC,EAAE,MAAM,GAAG,MAAM,CAOjF"}

View File

@@ -0,0 +1,5 @@
export * from './commitment.js';
export * from './endpoint.js';
export * from './signIn.js';
export * from './signMessage.js';
//# sourceMappingURL=index.d.ts.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,iBAAiB,CAAC;AAChC,cAAc,eAAe,CAAC;AAC9B,cAAc,aAAa,CAAC;AAC5B,cAAc,kBAAkB,CAAC"}

View File

@@ -0,0 +1,34 @@
import type { SolanaSignInInput, SolanaSignInOutput } from '@solana/wallet-standard-features';
/**
* TODO: docs
*/
export declare function verifySignIn(input: SolanaSignInInput, output: SolanaSignInOutput): boolean;
/**
* TODO: docs
*/
export declare function deriveSignInMessage(input: SolanaSignInInput, output: SolanaSignInOutput): Uint8Array | null;
/**
* TODO: docs
*/
export declare function deriveSignInMessageText(input: SolanaSignInInput, output: SolanaSignInOutput): string | null;
/**
* TODO: docs
*/
export type SolanaSignInInputWithRequiredFields = SolanaSignInInput & Required<Pick<SolanaSignInInput, 'domain' | 'address'>>;
/**
* TODO: docs
*/
export declare function parseSignInMessage(message: Uint8Array): SolanaSignInInputWithRequiredFields | null;
/**
* TODO: docs
*/
export declare function parseSignInMessageText(text: string): SolanaSignInInputWithRequiredFields | null;
/**
* TODO: docs
*/
export declare function createSignInMessage(input: SolanaSignInInputWithRequiredFields): Uint8Array;
/**
* TODO: docs
*/
export declare function createSignInMessageText(input: SolanaSignInInputWithRequiredFields): string;
//# sourceMappingURL=signIn.d.ts.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"signIn.d.ts","sourceRoot":"","sources":["../../src/signIn.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,iBAAiB,EAAE,kBAAkB,EAAE,MAAM,kCAAkC,CAAC;AAI9F;;GAEG;AACH,wBAAgB,YAAY,CAAC,KAAK,EAAE,iBAAiB,EAAE,MAAM,EAAE,kBAAkB,GAAG,OAAO,CAU1F;AAED;;GAEG;AACH,wBAAgB,mBAAmB,CAAC,KAAK,EAAE,iBAAiB,EAAE,MAAM,EAAE,kBAAkB,GAAG,UAAU,GAAG,IAAI,CAI3G;AAED;;GAEG;AACH,wBAAgB,uBAAuB,CAAC,KAAK,EAAE,iBAAiB,EAAE,MAAM,EAAE,kBAAkB,GAAG,MAAM,GAAG,IAAI,CAqB3G;AAED;;GAEG;AACH,MAAM,MAAM,mCAAmC,GAAG,iBAAiB,GAC/D,QAAQ,CAAC,IAAI,CAAC,iBAAiB,EAAE,QAAQ,GAAG,SAAS,CAAC,CAAC,CAAC;AAE5D;;GAEG;AACH,wBAAgB,kBAAkB,CAAC,OAAO,EAAE,UAAU,GAAG,mCAAmC,GAAG,IAAI,CAGlG;AAkBD;;GAEG;AACH,wBAAgB,sBAAsB,CAAC,IAAI,EAAE,MAAM,GAAG,mCAAmC,GAAG,IAAI,CAqB/F;AAED;;GAEG;AACH,wBAAgB,mBAAmB,CAAC,KAAK,EAAE,mCAAmC,GAAG,UAAU,CAG1F;AAED;;GAEG;AACH,wBAAgB,uBAAuB,CAAC,KAAK,EAAE,mCAAmC,GAAG,MAAM,CA+D1F"}

View File

@@ -0,0 +1,15 @@
import type { SolanaSignMessageInput, SolanaSignMessageOutput } from '@solana/wallet-standard-features';
/**
* TODO: docs
*/
export declare function verifyMessageSignature({ message, signedMessage, signature, publicKey, }: {
message: Uint8Array;
signedMessage: Uint8Array;
signature: Uint8Array;
publicKey: Uint8Array;
}): boolean;
/**
* TODO: docs
*/
export declare function verifySignMessage(input: SolanaSignMessageInput, output: SolanaSignMessageOutput): boolean;
//# sourceMappingURL=signMessage.d.ts.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"signMessage.d.ts","sourceRoot":"","sources":["../../src/signMessage.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,sBAAsB,EAAE,uBAAuB,EAAE,MAAM,kCAAkC,CAAC;AAGxG;;GAEG;AACH,wBAAgB,sBAAsB,CAAC,EACnC,OAAO,EACP,aAAa,EACb,SAAS,EACT,SAAS,GACZ,EAAE;IACC,OAAO,EAAE,UAAU,CAAC;IACpB,aAAa,EAAE,UAAU,CAAC;IAC1B,SAAS,EAAE,UAAU,CAAC;IACtB,SAAS,EAAE,UAAU,CAAC;CACzB,GAAG,OAAO,CAGV;AAED;;GAEG;AACH,wBAAgB,iBAAiB,CAAC,KAAK,EAAE,sBAAsB,EAAE,MAAM,EAAE,uBAAuB,GAAG,OAAO,CAOzG"}

View File

@@ -0,0 +1,2 @@
export {};
//# sourceMappingURL=util.d.ts.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"util.d.ts","sourceRoot":"","sources":["../../src/util.ts"],"names":[],"mappings":""}

44
node_modules/@solana/wallet-standard-util/package.json generated vendored Normal file
View File

@@ -0,0 +1,44 @@
{
"name": "@solana/wallet-standard-util",
"version": "1.1.2",
"author": "Solana Maintainers <maintainers@solana.foundation>",
"repository": "https://github.com/solana-labs/wallet-standard",
"license": "Apache-2.0",
"publishConfig": {
"access": "public"
},
"files": [
"lib",
"src",
"LICENSE"
],
"engines": {
"node": ">=16"
},
"type": "module",
"sideEffects": false,
"main": "./lib/cjs/index.js",
"module": "./lib/esm/index.js",
"types": "./lib/types/index.d.ts",
"exports": {
"require": "./lib/cjs/index.js",
"import": "./lib/esm/index.js",
"types": "./lib/types/index.d.ts"
},
"dependencies": {
"@noble/curves": "^1.8.0",
"@solana/wallet-standard-chains": "^1.1.1",
"@solana/wallet-standard-features": "^1.3.0"
},
"devDependencies": {
"@types/jest": "^29.5.14",
"jest": "^29.7.0",
"shx": "^0.3.4",
"ts-jest": "^29.2.5"
},
"scripts": {
"clean": "shx mkdir -p lib && shx rm -rf lib",
"package": "shx mkdir -p lib/cjs && shx echo '{ \"type\": \"commonjs\" }' > lib/cjs/package.json",
"test": "jest"
}
}

View File

@@ -0,0 +1,89 @@
import {
createSignInMessage,
createSignInMessageText,
deriveSignInMessage,
deriveSignInMessageText,
parseSignInMessage,
parseSignInMessageText,
verifySignIn,
} from '../signIn.js';
const signInMessageTests = {
'with `domain` and `address`': {
parsed: {
domain: 'solana.com',
address: 'A',
},
text: 'solana.com wants you to sign in with your Solana account:\nA',
},
'with `statement`': {
parsed: {
domain: 'solana.com',
address: 'A',
statement: 'S',
},
text: 'solana.com wants you to sign in with your Solana account:\nA\n\nS',
},
'with multi-line `statement`': {
parsed: {
domain: 'solana.com',
address: 'A',
statement: 'S\n\nS',
},
text: 'solana.com wants you to sign in with your Solana account:\nA\n\nS\n\nS',
},
'with fields': {
parsed: {
domain: 'solana.com',
address: 'A',
uri: 'https://solana.com',
},
text: 'solana.com wants you to sign in with your Solana account:\nA\n\nURI: https://solana.com',
},
'with `statement` and fields': {
parsed: {
domain: 'solana.com',
address: 'A',
statement: 'S',
uri: 'https://solana.com',
},
text: 'solana.com wants you to sign in with your Solana account:\nA\n\nS\n\nURI: https://solana.com',
},
'with multi-line `statement` and fields': {
parsed: {
domain: 'solana.com',
address: 'A',
statement: 'S\n\nS',
uri: 'https://solana.com',
},
text: 'solana.com wants you to sign in with your Solana account:\nA\n\nS\n\nS\n\nURI: https://solana.com',
},
};
describe.skip('verifySignIn()', () => {});
describe.skip('deriveSignInMessage()', () => {});
describe.skip('deriveSignInMessageText()', () => {});
describe.skip('parseSignInMessage()', () => {});
describe('parseSignInMessageText()', () => {
for (const [name, test] of Object.entries(signInMessageTests)) {
it(name, () => {
const parsed = parseSignInMessageText(test.text);
expect(parsed).toEqual(test.parsed);
});
}
});
describe.skip('createSignInMessage()', () => {});
describe('createSignInMessageText()', () => {
for (const [name, test] of Object.entries(signInMessageTests)) {
it(name, () => {
const text = createSignInMessageText(test.parsed);
expect(text).toBe(test.text);
});
}
});

View File

@@ -0,0 +1,27 @@
import type { SolanaTransactionCommitment } from '@solana/wallet-standard-features';
// Copied from @solana/web3.js
type Commitment = 'processed' | 'confirmed' | 'finalized' | 'recent' | 'single' | 'singleGossip' | 'root' | 'max';
/**
* TODO: docs
*/
export function getCommitment(commitment?: Commitment): SolanaTransactionCommitment | undefined {
switch (commitment) {
case 'processed':
case 'confirmed':
case 'finalized':
case undefined:
return commitment;
case 'recent':
return 'processed';
case 'single':
case 'singleGossip':
return 'confirmed';
case 'max':
case 'root':
return 'finalized';
default:
return undefined;
}
}

View File

@@ -0,0 +1,39 @@
import type { SolanaChain } from '@solana/wallet-standard-chains';
import {
SOLANA_DEVNET_CHAIN,
SOLANA_LOCALNET_CHAIN,
SOLANA_MAINNET_CHAIN,
SOLANA_TESTNET_CHAIN,
} from '@solana/wallet-standard-chains';
/** TODO: docs */
export const MAINNET_ENDPOINT = 'https://api.mainnet-beta.solana.com';
/** TODO: docs */
export const DEVNET_ENDPOINT = 'https://api.devnet.solana.com';
/** TODO: docs */
export const TESTNET_ENDPOINT = 'https://api.testnet.solana.com';
/** TODO: docs */
export const LOCALNET_ENDPOINT = 'http://localhost:8899';
/**
* TODO: docs
*/
export function getChainForEndpoint(endpoint: string): SolanaChain {
if (endpoint.includes(MAINNET_ENDPOINT)) return SOLANA_MAINNET_CHAIN;
if (/\bdevnet\b/i.test(endpoint)) return SOLANA_DEVNET_CHAIN;
if (/\btestnet\b/i.test(endpoint)) return SOLANA_TESTNET_CHAIN;
if (/\blocalhost\b/i.test(endpoint) || /\b127\.0\.0\.1\b/.test(endpoint)) return SOLANA_LOCALNET_CHAIN;
return SOLANA_MAINNET_CHAIN;
}
/**
* TODO: docs
*/
export function getEndpointForChain(chain: SolanaChain, endpoint?: string): string {
if (endpoint) return endpoint;
if (chain === SOLANA_MAINNET_CHAIN) return MAINNET_ENDPOINT;
if (chain === SOLANA_DEVNET_CHAIN) return DEVNET_ENDPOINT;
if (chain === SOLANA_TESTNET_CHAIN) return TESTNET_ENDPOINT;
if (chain === SOLANA_LOCALNET_CHAIN) return LOCALNET_ENDPOINT;
return MAINNET_ENDPOINT;
}

View File

@@ -0,0 +1,4 @@
export * from './commitment.js';
export * from './endpoint.js';
export * from './signIn.js';
export * from './signMessage.js';

185
node_modules/@solana/wallet-standard-util/src/signIn.ts generated vendored Normal file
View File

@@ -0,0 +1,185 @@
import type { SolanaSignInInput, SolanaSignInOutput } from '@solana/wallet-standard-features';
import { verifyMessageSignature } from './signMessage.js';
import { arraysEqual } from './util.js';
/**
* TODO: docs
*/
export function verifySignIn(input: SolanaSignInInput, output: SolanaSignInOutput): boolean {
const {
signedMessage,
signature,
account: { publicKey },
} = output;
const message = deriveSignInMessage(input, output);
return (
!!message && verifyMessageSignature({ message, signedMessage, signature, publicKey: publicKey as Uint8Array })
);
}
/**
* TODO: docs
*/
export function deriveSignInMessage(input: SolanaSignInInput, output: SolanaSignInOutput): Uint8Array | null {
const text = deriveSignInMessageText(input, output);
if (!text) return null;
return new TextEncoder().encode(text);
}
/**
* TODO: docs
*/
export function deriveSignInMessageText(input: SolanaSignInInput, output: SolanaSignInOutput): string | null {
const parsed = parseSignInMessage(output.signedMessage);
if (!parsed) return null;
if (input.domain && input.domain !== parsed.domain) return null;
if (input.address && input.address !== parsed.address) return null;
if (input.statement !== parsed.statement) return null;
if (input.uri !== parsed.uri) return null;
if (input.version !== parsed.version) return null;
if (input.chainId !== parsed.chainId) return null;
if (input.nonce !== parsed.nonce) return null;
if (input.issuedAt !== parsed.issuedAt) return null;
if (input.expirationTime !== parsed.expirationTime) return null;
if (input.notBefore !== parsed.notBefore) return null;
if (input.requestId !== parsed.requestId) return null;
if (input.resources) {
if (!parsed.resources) return null;
if (!arraysEqual(input.resources, parsed.resources)) return null;
} else if (parsed.resources) return null;
return createSignInMessageText(parsed);
}
/**
* TODO: docs
*/
export type SolanaSignInInputWithRequiredFields = SolanaSignInInput &
Required<Pick<SolanaSignInInput, 'domain' | 'address'>>;
/**
* TODO: docs
*/
export function parseSignInMessage(message: Uint8Array): SolanaSignInInputWithRequiredFields | null {
const text = new TextDecoder().decode(message);
return parseSignInMessageText(text);
}
// TODO: implement https://github.com/solana-labs/solana/blob/master/docs/src/proposals/off-chain-message-signing.md
const DOMAIN = '(?<domain>[^\\n]+?) wants you to sign in with your Solana account:\\n';
const ADDRESS = '(?<address>[^\\n]+)(?:\\n|$)';
const STATEMENT = '(?:\\n(?<statement>[\\S\\s]*?)(?:\\n|$))??';
const URI = '(?:\\nURI: (?<uri>[^\\n]+))?';
const VERSION = '(?:\\nVersion: (?<version>[^\\n]+))?';
const CHAIN_ID = '(?:\\nChain ID: (?<chainId>[^\\n]+))?';
const NONCE = '(?:\\nNonce: (?<nonce>[^\\n]+))?';
const ISSUED_AT = '(?:\\nIssued At: (?<issuedAt>[^\\n]+))?';
const EXPIRATION_TIME = '(?:\\nExpiration Time: (?<expirationTime>[^\\n]+))?';
const NOT_BEFORE = '(?:\\nNot Before: (?<notBefore>[^\\n]+))?';
const REQUEST_ID = '(?:\\nRequest ID: (?<requestId>[^\\n]+))?';
const RESOURCES = '(?:\\nResources:(?<resources>(?:\\n- [^\\n]+)*))?';
const FIELDS = `${URI}${VERSION}${CHAIN_ID}${NONCE}${ISSUED_AT}${EXPIRATION_TIME}${NOT_BEFORE}${REQUEST_ID}${RESOURCES}`;
const MESSAGE = new RegExp(`^${DOMAIN}${ADDRESS}${STATEMENT}${FIELDS}\\n*$`);
/**
* TODO: docs
*/
export function parseSignInMessageText(text: string): SolanaSignInInputWithRequiredFields | null {
const match = MESSAGE.exec(text);
if (!match) return null;
const groups = match.groups;
if (!groups) return null;
return {
domain: groups.domain!,
address: groups.address!,
statement: groups.statement,
uri: groups.uri,
version: groups.version,
nonce: groups.nonce,
chainId: groups.chainId,
issuedAt: groups.issuedAt,
expirationTime: groups.expirationTime,
notBefore: groups.notBefore,
requestId: groups.requestId,
resources: groups.resources?.split('\n- ').slice(1),
};
}
/**
* TODO: docs
*/
export function createSignInMessage(input: SolanaSignInInputWithRequiredFields): Uint8Array {
const text = createSignInMessageText(input);
return new TextEncoder().encode(text);
}
/**
* TODO: docs
*/
export function createSignInMessageText(input: SolanaSignInInputWithRequiredFields): string {
// ${domain} wants you to sign in with your Solana account:
// ${address}
//
// ${statement}
//
// URI: ${uri}
// Version: ${version}
// Chain ID: ${chain}
// Nonce: ${nonce}
// Issued At: ${issued-at}
// Expiration Time: ${expiration-time}
// Not Before: ${not-before}
// Request ID: ${request-id}
// Resources:
// - ${resources[0]}
// - ${resources[1]}
// ...
// - ${resources[n]}
let message = `${input.domain} wants you to sign in with your Solana account:\n`;
message += `${input.address}`;
if (input.statement) {
message += `\n\n${input.statement}`;
}
const fields: string[] = [];
if (input.uri) {
fields.push(`URI: ${input.uri}`);
}
if (input.version) {
fields.push(`Version: ${input.version}`);
}
if (input.chainId) {
fields.push(`Chain ID: ${input.chainId}`);
}
if (input.nonce) {
fields.push(`Nonce: ${input.nonce}`);
}
if (input.issuedAt) {
fields.push(`Issued At: ${input.issuedAt}`);
}
if (input.expirationTime) {
fields.push(`Expiration Time: ${input.expirationTime}`);
}
if (input.notBefore) {
fields.push(`Not Before: ${input.notBefore}`);
}
if (input.requestId) {
fields.push(`Request ID: ${input.requestId}`);
}
if (input.resources) {
fields.push(`Resources:`);
for (const resource of input.resources) {
fields.push(`- ${resource}`);
}
}
if (fields.length) {
message += `\n\n${fields.join('\n')}`;
}
return message;
}

View File

@@ -0,0 +1,33 @@
import { ed25519 } from '@noble/curves/ed25519';
import type { SolanaSignMessageInput, SolanaSignMessageOutput } from '@solana/wallet-standard-features';
import { bytesEqual } from './util.js';
/**
* TODO: docs
*/
export function verifyMessageSignature({
message,
signedMessage,
signature,
publicKey,
}: {
message: Uint8Array;
signedMessage: Uint8Array;
signature: Uint8Array;
publicKey: Uint8Array;
}): boolean {
// TODO: implement https://github.com/solana-labs/solana/blob/master/docs/src/proposals/off-chain-message-signing.md
return bytesEqual(message, signedMessage) && ed25519.verify(signature, signedMessage, publicKey);
}
/**
* TODO: docs
*/
export function verifySignMessage(input: SolanaSignMessageInput, output: SolanaSignMessageOutput): boolean {
const {
message,
account: { publicKey },
} = input;
const { signedMessage, signature } = output;
return verifyMessageSignature({ message, signedMessage, signature, publicKey: publicKey as Uint8Array });
}

54
node_modules/@solana/wallet-standard-util/src/util.ts generated vendored Normal file
View File

@@ -0,0 +1,54 @@
/**
* @internal
*
* Type with a numeric `length` and numerically indexed elements of a generic type `T`.
*
* For example, `Array<T>` and `Uint8Array`.
*
* @group Internal
*/
export interface Indexed<T> {
length: number;
[index: number]: T;
}
/**
* @internal
*
* Efficiently compare {@link Indexed} arrays (e.g. `Array` and `Uint8Array`).
*
* @param a An array.
* @param b Another array.
*
* @return `true` if the arrays have the same length and elements, `false` otherwise.
*
* @group Internal
*/
export function arraysEqual<T>(a: Indexed<T>, b: Indexed<T>): boolean {
if (a === b) return true;
const length = a.length;
if (length !== b.length) return false;
for (let i = 0; i < length; i++) {
if (a[i] !== b[i]) return false;
}
return true;
}
/**
* @internal
*
* Efficiently compare byte arrays, using {@link arraysEqual}.
*
* @param a A byte array.
* @param b Another byte array.
*
* @return `true` if the byte arrays have the same length and bytes, `false` otherwise.
*
* @group Internal
*/
export function bytesEqual(a: Uint8Array, b: Uint8Array): boolean {
return arraysEqual(a, b);
}