@orangecheck/sdk 1.1.0 → 1.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.d.mts +24 -1
- package/dist/index.d.ts +24 -1
- package/dist/index.js +60 -0
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +61 -4
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Buffer } from 'buffer';
|
|
1
|
+
import { Buffer as Buffer$1 } from 'buffer';
|
|
2
2
|
import { Verifier } from 'bip322-js';
|
|
3
3
|
import * as bitcoinMessage from 'bitcoinjs-message';
|
|
4
4
|
import { schnorr } from '@noble/curves/secp256k1.js';
|
|
@@ -712,7 +712,7 @@ function looksLikeHex(s) {
|
|
|
712
712
|
}
|
|
713
713
|
function toBase64Maybe(sig) {
|
|
714
714
|
if (looksLikeHex(sig)) {
|
|
715
|
-
return Buffer.from(sig, "hex").toString("base64");
|
|
715
|
+
return Buffer$1.from(sig, "hex").toString("base64");
|
|
716
716
|
}
|
|
717
717
|
return sig;
|
|
718
718
|
}
|
|
@@ -1338,6 +1338,63 @@ function verifyBinding(envelope) {
|
|
|
1338
1338
|
return fail("malformed");
|
|
1339
1339
|
}
|
|
1340
1340
|
}
|
|
1341
|
+
function xOnlyHexToNpub(hex) {
|
|
1342
|
+
const bytes = fromHex(hex);
|
|
1343
|
+
if (bytes.length !== 32) throw new Error("x-only Nostr key must be 32 bytes");
|
|
1344
|
+
return bech32.encode("npub", bech32.toWords(bytes), 90);
|
|
1345
|
+
}
|
|
1346
|
+
function buildBindingEventTemplate(params) {
|
|
1347
|
+
const id = bindingId(params.message);
|
|
1348
|
+
return {
|
|
1349
|
+
kind: BINDING_KIND,
|
|
1350
|
+
pubkey: params.nostrPubkeyHex.toLowerCase(),
|
|
1351
|
+
created_at: params.createdAt ?? Math.floor(Date.now() / 1e3),
|
|
1352
|
+
tags: [
|
|
1353
|
+
["d", `oc-attest-binding:${id}`],
|
|
1354
|
+
["btc", params.btc],
|
|
1355
|
+
["oc", "binding-attestation"],
|
|
1356
|
+
["v", "1"]
|
|
1357
|
+
],
|
|
1358
|
+
content: JSON.stringify({ message: params.message, btc_signature: params.btcSignature })
|
|
1359
|
+
};
|
|
1360
|
+
}
|
|
1361
|
+
function parseBindingFields(message) {
|
|
1362
|
+
const body = message.split("\n");
|
|
1363
|
+
const at = (i, prefix) => {
|
|
1364
|
+
const line = body[i];
|
|
1365
|
+
if (typeof line !== "string" || !line.startsWith(prefix)) {
|
|
1366
|
+
throw new Error(`binding message line ${i + 1} is malformed`);
|
|
1367
|
+
}
|
|
1368
|
+
return line.slice(prefix.length);
|
|
1369
|
+
};
|
|
1370
|
+
return {
|
|
1371
|
+
principal: at(2, "principal: "),
|
|
1372
|
+
btc: at(3, "btc: "),
|
|
1373
|
+
nostr: at(4, "nostr: ")
|
|
1374
|
+
};
|
|
1375
|
+
}
|
|
1376
|
+
function toBase64Url(s) {
|
|
1377
|
+
const bytes = new TextEncoder().encode(s);
|
|
1378
|
+
let bin = "";
|
|
1379
|
+
for (const b of bytes) bin += String.fromCharCode(b);
|
|
1380
|
+
const b64 = typeof btoa !== "undefined" ? btoa(bin) : Buffer.from(bytes).toString("base64");
|
|
1381
|
+
return b64.replace(/\+/g, "-").replace(/\//g, "_").replace(/=+$/, "");
|
|
1382
|
+
}
|
|
1383
|
+
function assembleBindingEnvelope(params) {
|
|
1384
|
+
const { principal, btc, nostr } = parseBindingFields(params.message);
|
|
1385
|
+
return {
|
|
1386
|
+
binding_id: bindingId(params.message),
|
|
1387
|
+
v: 1,
|
|
1388
|
+
principal,
|
|
1389
|
+
btc,
|
|
1390
|
+
nostr,
|
|
1391
|
+
message: params.message,
|
|
1392
|
+
message_b64url: toBase64Url(params.message),
|
|
1393
|
+
btc_signature: params.btcSignature,
|
|
1394
|
+
btc_scheme: params.btcScheme ?? "bip322",
|
|
1395
|
+
nostr_event: params.nostrEvent
|
|
1396
|
+
};
|
|
1397
|
+
}
|
|
1341
1398
|
var AUTH_HEADER = "orangecheck-auth";
|
|
1342
1399
|
var AUTH_ACK = "I authorize this session under the OrangeCheck auth challenge.";
|
|
1343
1400
|
function randomNonce() {
|
|
@@ -1455,7 +1512,7 @@ async function verifyChallenge(opts) {
|
|
|
1455
1512
|
let sigValid = false;
|
|
1456
1513
|
try {
|
|
1457
1514
|
if (scheme === "bip322") {
|
|
1458
|
-
const sigBase64 = /^[0-9a-fA-F]+$/.test(opts.signature) && opts.signature.length % 2 === 0 ? Buffer.from(opts.signature, "hex").toString("base64") : opts.signature;
|
|
1515
|
+
const sigBase64 = /^[0-9a-fA-F]+$/.test(opts.signature) && opts.signature.length % 2 === 0 ? Buffer$1.from(opts.signature, "hex").toString("base64") : opts.signature;
|
|
1459
1516
|
sigValid = Verifier.verifySignature(address, opts.message, sigBase64);
|
|
1460
1517
|
} else if (scheme === "legacy") {
|
|
1461
1518
|
if (!/^[1m][a-km-zA-HJ-NP-Z1-9]{25,34}$/.test(address)) {
|
|
@@ -2273,6 +2330,6 @@ var STATUS_META = {
|
|
|
2273
2330
|
}
|
|
2274
2331
|
};
|
|
2275
2332
|
|
|
2276
|
-
export { DEFAULT_RELAYS, STATUS_META, bindingId, buildBindingMessage, buildCanonicalMessage, check, computeAllScores, computeScore, createAttestation, createAttestationEnvelope, createAttestationEvent, discoverAttestations, extractAttestationIdFromUrl, formatIdentities, formatIdentitiesForDisplay, generateAttestationId, generateGistTemplate, generateTweetText, generateWellKnownContent, getAttestationsForAddress, getAttestationsForIdentity, getDnsVerificationInstructions, getGistCreationUrl, getGitHubVerificationInstructions, getManualVerificationInstructions, getNip07Info, getNostrPublicKey, getNostrVerificationInstructions, getTweetUrl, getTwitterComposeUrl, getTwitterVerificationInstructions, getVerificationInstructions, getVerificationSummary, getVerificationUrl, getWellKnownUrl, isDnsIdentityVerified, isGitHubIdentityVerified, isNip07Available, isNostrIdentityVerified, isValidDomain, isValidTweetUrl, issueChallenge, parseAttestationFromEvent, parseIdentities, publishAttestation, publishToRelays, queryByAddress, queryByAttestationId, queryByIdentity, requiresManualVerification, signNostrEvent, supportsAutomaticVerification, verify2 as verify, verifyAllIdentities, verifyAttestationById, verifyBinding, verifyChallenge, verifyDnsIdentity, verifyGitHubIdentity, verifyIdentity, verifyNostrIdentity, verifyTwitterIdentity };
|
|
2333
|
+
export { DEFAULT_RELAYS, STATUS_META, assembleBindingEnvelope, bindingId, buildBindingEventTemplate, buildBindingMessage, buildCanonicalMessage, check, computeAllScores, computeScore, createAttestation, createAttestationEnvelope, createAttestationEvent, discoverAttestations, extractAttestationIdFromUrl, formatIdentities, formatIdentitiesForDisplay, generateAttestationId, generateGistTemplate, generateTweetText, generateWellKnownContent, getAttestationsForAddress, getAttestationsForIdentity, getDnsVerificationInstructions, getGistCreationUrl, getGitHubVerificationInstructions, getManualVerificationInstructions, getNip07Info, getNostrPublicKey, getNostrVerificationInstructions, getTweetUrl, getTwitterComposeUrl, getTwitterVerificationInstructions, getVerificationInstructions, getVerificationSummary, getVerificationUrl, getWellKnownUrl, isDnsIdentityVerified, isGitHubIdentityVerified, isNip07Available, isNostrIdentityVerified, isValidDomain, isValidTweetUrl, issueChallenge, parseAttestationFromEvent, parseIdentities, publishAttestation, publishToRelays, queryByAddress, queryByAttestationId, queryByIdentity, requiresManualVerification, signNostrEvent, supportsAutomaticVerification, verify2 as verify, verifyAllIdentities, verifyAttestationById, verifyBinding, verifyChallenge, verifyDnsIdentity, verifyGitHubIdentity, verifyIdentity, verifyNostrIdentity, verifyTwitterIdentity, xOnlyHexToNpub };
|
|
2277
2334
|
//# sourceMappingURL=index.mjs.map
|
|
2278
2335
|
//# sourceMappingURL=index.mjs.map
|