@orangecheck/sdk 0.1.2 → 0.1.4
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/README.md +7 -8
- package/dist/attestation.d.mts +1 -2
- package/dist/attestation.d.ts +1 -2
- package/dist/attestation.js +12 -52
- package/dist/attestation.js.map +1 -1
- package/dist/attestation.mjs +13 -52
- package/dist/attestation.mjs.map +1 -1
- package/dist/canonical.d.mts +6 -2
- package/dist/canonical.d.ts +6 -2
- package/dist/canonical.js +6 -3
- package/dist/canonical.js.map +1 -1
- package/dist/canonical.mjs +6 -3
- package/dist/canonical.mjs.map +1 -1
- package/dist/challenge.js +10 -6
- package/dist/challenge.js.map +1 -1
- package/dist/challenge.mjs +10 -6
- package/dist/challenge.mjs.map +1 -1
- package/dist/identity.js +4 -4
- package/dist/identity.js.map +1 -1
- package/dist/identity.mjs +2 -2
- package/dist/identity.mjs.map +1 -1
- package/dist/index.d.mts +2 -2
- package/dist/index.d.ts +2 -2
- package/dist/index.js +52 -24
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +47 -23
- package/dist/index.mjs.map +1 -1
- package/dist/nostr.js +5 -6
- package/dist/nostr.js.map +1 -1
- package/dist/nostr.mjs +5 -6
- package/dist/nostr.mjs.map +1 -1
- package/dist/verify.js +2 -5
- package/dist/verify.js.map +1 -1
- package/dist/verify.mjs +2 -5
- package/dist/verify.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { Buffer } from 'buffer';
|
|
2
2
|
import { Verifier } from 'bip322-js';
|
|
3
3
|
import * as bitcoinMessage from 'bitcoinjs-message';
|
|
4
|
-
import { schnorr } from '@noble/curves/secp256k1';
|
|
5
|
-
import { sha256 } from '@noble/hashes/sha2';
|
|
4
|
+
import { schnorr } from '@noble/curves/secp256k1.js';
|
|
5
|
+
import { sha256 } from '@noble/hashes/sha2.js';
|
|
6
6
|
import { bech32 } from '@scure/base';
|
|
7
7
|
|
|
8
8
|
// src/canonical.ts
|
|
@@ -67,9 +67,12 @@ function parseIdentities(identitiesStr) {
|
|
|
67
67
|
}
|
|
68
68
|
return bindings;
|
|
69
69
|
}
|
|
70
|
-
function buildCanonicalMessage({ address, identities }, extensions = {}) {
|
|
71
|
-
const nonce = randomNonce16BHexLower();
|
|
72
|
-
|
|
70
|
+
function buildCanonicalMessage({ address, identities }, extensions = {}, options = {}) {
|
|
71
|
+
const nonce = options.nonce ?? randomNonce16BHexLower();
|
|
72
|
+
if (!/^[0-9a-f]{32}$/.test(nonce)) {
|
|
73
|
+
throw new Error(`invalid nonce: must be 32 lowercase hex chars`);
|
|
74
|
+
}
|
|
75
|
+
const issuedAt = options.issuedAt ?? (/* @__PURE__ */ new Date()).toISOString();
|
|
73
76
|
const identitiesStr = formatIdentities(identities);
|
|
74
77
|
const core = [
|
|
75
78
|
"orangecheck",
|
|
@@ -233,16 +236,15 @@ async function publishToRelays(event, relays = DEFAULT_RELAYS) {
|
|
|
233
236
|
ws = new WebSocket(relayUrl);
|
|
234
237
|
const wsRef = ws;
|
|
235
238
|
await new Promise((resolve, reject) => {
|
|
236
|
-
const
|
|
239
|
+
const deadline = setTimeout(() => {
|
|
237
240
|
wsRef.close();
|
|
238
|
-
reject(new Error("
|
|
239
|
-
},
|
|
241
|
+
reject(new Error("Relay publish timeout"));
|
|
242
|
+
}, 1e4);
|
|
240
243
|
const cleanup = () => {
|
|
241
|
-
clearTimeout(
|
|
244
|
+
clearTimeout(deadline);
|
|
242
245
|
wsRef.close();
|
|
243
246
|
};
|
|
244
247
|
wsRef.onopen = () => {
|
|
245
|
-
clearTimeout(timeout);
|
|
246
248
|
wsRef.send(JSON.stringify(["EVENT", event]));
|
|
247
249
|
};
|
|
248
250
|
wsRef.onmessage = (msg) => {
|
|
@@ -280,7 +282,7 @@ async function publishToRelays(event, relays = DEFAULT_RELAYS) {
|
|
|
280
282
|
reject(err);
|
|
281
283
|
};
|
|
282
284
|
wsRef.onclose = () => {
|
|
283
|
-
clearTimeout(
|
|
285
|
+
clearTimeout(deadline);
|
|
284
286
|
};
|
|
285
287
|
});
|
|
286
288
|
} catch (err) {
|
|
@@ -658,6 +660,24 @@ async function getAttestationsForIdentity(protocol, identifier, relays = DEFAULT
|
|
|
658
660
|
log3.info({ protocol, identifier }, "Getting all attestations for identity");
|
|
659
661
|
return discoverAttestations({ identity: { protocol, identifier }, relays });
|
|
660
662
|
}
|
|
663
|
+
function formatIdentitiesForDisplay(identities) {
|
|
664
|
+
return identities.map((id) => `${id.protocol}:${id.identifier}`).join(", ");
|
|
665
|
+
}
|
|
666
|
+
function getVerificationUrl(attestationId, baseUrl = "https://ochk.io") {
|
|
667
|
+
return `${baseUrl}/attest/${attestationId}`;
|
|
668
|
+
}
|
|
669
|
+
function extractAttestationIdFromUrl(url) {
|
|
670
|
+
try {
|
|
671
|
+
const u = new URL(url);
|
|
672
|
+
const m = u.pathname.match(/^\/attest\/([0-9a-f]{64})\/?$/i);
|
|
673
|
+
if (m) return m[1].toLowerCase();
|
|
674
|
+
const q = u.searchParams.get("id");
|
|
675
|
+
if (q && /^[0-9a-f]{64}$/i.test(q)) return q.toLowerCase();
|
|
676
|
+
return null;
|
|
677
|
+
} catch {
|
|
678
|
+
return null;
|
|
679
|
+
}
|
|
680
|
+
}
|
|
661
681
|
|
|
662
682
|
// src/scoring.ts
|
|
663
683
|
function scoreV0(sats, days) {
|
|
@@ -681,12 +701,12 @@ function computeScore(sats, days, config) {
|
|
|
681
701
|
return null;
|
|
682
702
|
}
|
|
683
703
|
}
|
|
704
|
+
function computeAllScores(sats, days) {
|
|
705
|
+
return { v0: scoreV0(sats, days), tier: scoreTier(sats, days) };
|
|
706
|
+
}
|
|
684
707
|
|
|
685
708
|
// src/verify.ts
|
|
686
709
|
var log4 = createLogger("ocp/verify");
|
|
687
|
-
function scoreV02(sats, days) {
|
|
688
|
-
return computeScore(sats, days, { algorithm: "v0" });
|
|
689
|
-
}
|
|
690
710
|
function looksLikeHex(s) {
|
|
691
711
|
return /^[0-9a-fA-F]+$/.test(s) && s.length % 2 === 0;
|
|
692
712
|
}
|
|
@@ -950,7 +970,7 @@ async function verify2(input, opts = {}) {
|
|
|
950
970
|
const metrics = {
|
|
951
971
|
sats_bonded,
|
|
952
972
|
days_unspent,
|
|
953
|
-
score:
|
|
973
|
+
score: computeScore(sats_bonded, days_unspent, { algorithm: "v0" })
|
|
954
974
|
// ≈ 55.26
|
|
955
975
|
};
|
|
956
976
|
codes.push("sig_ok_bip322");
|
|
@@ -1046,7 +1066,7 @@ async function verify2(input, opts = {}) {
|
|
|
1046
1066
|
const metrics = {
|
|
1047
1067
|
sats_bonded,
|
|
1048
1068
|
days_unspent,
|
|
1049
|
-
score:
|
|
1069
|
+
score: computeScore(sats_bonded, days_unspent, { algorithm: "v0" })
|
|
1050
1070
|
};
|
|
1051
1071
|
return {
|
|
1052
1072
|
ok: true,
|
|
@@ -1184,16 +1204,20 @@ function parseChallenge(message) {
|
|
|
1184
1204
|
throw new Error("not an orangecheck-auth challenge");
|
|
1185
1205
|
}
|
|
1186
1206
|
const out = { extensions: [] };
|
|
1187
|
-
const coreKeys =
|
|
1188
|
-
|
|
1207
|
+
const coreKeys = ["address", "nonce", "issued_at", "expires_at", "ack"];
|
|
1208
|
+
const coreKeySet = new Set(coreKeys);
|
|
1209
|
+
const seenCore = /* @__PURE__ */ new Set();
|
|
1189
1210
|
for (let i = 1; i < lines.length; i++) {
|
|
1190
1211
|
const line = lines[i] ?? "";
|
|
1191
1212
|
const sep = line.indexOf(": ");
|
|
1192
1213
|
if (sep === -1) continue;
|
|
1193
1214
|
const key = line.slice(0, sep);
|
|
1194
1215
|
const val = line.slice(sep + 2);
|
|
1195
|
-
if (
|
|
1196
|
-
seenCore
|
|
1216
|
+
if (coreKeySet.has(key)) {
|
|
1217
|
+
if (seenCore.has(key)) {
|
|
1218
|
+
throw new Error(`duplicate core key in challenge: ${key}`);
|
|
1219
|
+
}
|
|
1220
|
+
seenCore.add(key);
|
|
1197
1221
|
if (key === "address") out.address = val;
|
|
1198
1222
|
else if (key === "nonce") out.nonce = val;
|
|
1199
1223
|
else if (key === "issued_at") out.issuedAt = new Date(val);
|
|
@@ -1205,8 +1229,8 @@ function parseChallenge(message) {
|
|
|
1205
1229
|
if (key === "purpose") out.purpose = val;
|
|
1206
1230
|
}
|
|
1207
1231
|
}
|
|
1208
|
-
if (seenCore !==
|
|
1209
|
-
throw new Error(`challenge missing core lines (${seenCore}
|
|
1232
|
+
if (seenCore.size !== coreKeys.length) {
|
|
1233
|
+
throw new Error(`challenge missing core lines (${seenCore.size}/${coreKeys.length})`);
|
|
1210
1234
|
}
|
|
1211
1235
|
return out;
|
|
1212
1236
|
}
|
|
@@ -2066,6 +2090,6 @@ var STATUS_META = {
|
|
|
2066
2090
|
}
|
|
2067
2091
|
};
|
|
2068
2092
|
|
|
2069
|
-
export { DEFAULT_RELAYS, STATUS_META, buildCanonicalMessage, check, computeScore, createAttestation, createAttestationEnvelope, createAttestationEvent, discoverAttestations, formatIdentities, generateAttestationId, generateGistTemplate, generateTweetText, generateWellKnownContent, getAttestationsForAddress, getAttestationsForIdentity, getDnsVerificationInstructions, getGistCreationUrl, getGitHubVerificationInstructions, getManualVerificationInstructions, getNip07Info, getNostrPublicKey, getNostrVerificationInstructions, getTweetUrl, getTwitterComposeUrl, getTwitterVerificationInstructions, getVerificationInstructions, getVerificationSummary, getWellKnownUrl, isDnsIdentityVerified, isGitHubIdentityVerified, isNip07Available, isNostrIdentityVerified, isValidDomain, isValidTweetUrl, issueChallenge, parseAttestationFromEvent, parseIdentities, publishAttestation, publishToRelays, queryByAddress, queryByAttestationId, queryByIdentity, requiresManualVerification, signNostrEvent, supportsAutomaticVerification, verify2 as verify, verifyAllIdentities, verifyAttestationById, verifyChallenge, verifyDnsIdentity, verifyGitHubIdentity, verifyIdentity, verifyNostrIdentity, verifyTwitterIdentity };
|
|
2093
|
+
export { DEFAULT_RELAYS, STATUS_META, 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, verifyChallenge, verifyDnsIdentity, verifyGitHubIdentity, verifyIdentity, verifyNostrIdentity, verifyTwitterIdentity };
|
|
2070
2094
|
//# sourceMappingURL=index.mjs.map
|
|
2071
2095
|
//# sourceMappingURL=index.mjs.map
|