@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 CHANGED
@@ -33,6 +33,7 @@ interface CheckResult {
33
33
  }
34
34
  declare function check(params: CheckParams): Promise<CheckResult>;
35
35
 
36
+ declare const BINDING_KIND = 30079;
36
37
  interface BindingInput {
37
38
  principal: string;
38
39
  btc: string;
@@ -57,6 +58,7 @@ interface BindingEnvelope {
57
58
  btc?: string;
58
59
  nostr?: string;
59
60
  message: string;
61
+ message_b64url?: string;
60
62
  btc_signature?: string;
61
63
  btc_scheme?: 'bip322' | 'legacy';
62
64
  nostr_event?: BindingNostrEvent;
@@ -76,6 +78,27 @@ type BindingVerifyResult = {
76
78
  declare function buildBindingMessage(input: BindingInput): string;
77
79
  declare function bindingId(message: string): string;
78
80
  declare function verifyBinding(envelope: BindingEnvelope): BindingVerifyResult;
81
+ declare function xOnlyHexToNpub(hex: string): string;
82
+ interface BindingEventTemplate {
83
+ kind: typeof BINDING_KIND;
84
+ pubkey: string;
85
+ created_at: number;
86
+ tags: string[][];
87
+ content: string;
88
+ }
89
+ declare function buildBindingEventTemplate(params: {
90
+ message: string;
91
+ btcSignature: string;
92
+ nostrPubkeyHex: string;
93
+ btc: string;
94
+ createdAt?: number;
95
+ }): BindingEventTemplate;
96
+ declare function assembleBindingEnvelope(params: {
97
+ message: string;
98
+ btcSignature: string;
99
+ btcScheme?: 'bip322' | 'legacy';
100
+ nostrEvent: BindingNostrEvent;
101
+ }): BindingEnvelope;
79
102
 
80
103
  declare function isNip07Available(): boolean;
81
104
  declare function getNostrPublicKey(): Promise<string | null>;
@@ -94,4 +117,4 @@ interface StatusMeta {
94
117
  }
95
118
  declare const STATUS_META: Record<StatusCode, StatusMeta>;
96
119
 
97
- export { type BindingEnvelope, type BindingInput, type BindingNostrEvent, type BindingStatus, type BindingVerifyResult, type CheckParams, type CheckResult, IdentityBinding, Network, NostrEvent, STATUS_META, type Severity, StatusCode, type StatusMeta, VerifyOptions, bindingId, buildBindingMessage, check, getNip07Info, getNostrPublicKey, isNip07Available, signNostrEvent, verifyBinding };
120
+ export { type BindingEnvelope, type BindingEventTemplate, type BindingInput, type BindingNostrEvent, type BindingStatus, type BindingVerifyResult, type CheckParams, type CheckResult, IdentityBinding, Network, NostrEvent, STATUS_META, type Severity, StatusCode, type StatusMeta, VerifyOptions, assembleBindingEnvelope, bindingId, buildBindingEventTemplate, buildBindingMessage, check, getNip07Info, getNostrPublicKey, isNip07Available, signNostrEvent, verifyBinding, xOnlyHexToNpub };
package/dist/index.d.ts CHANGED
@@ -33,6 +33,7 @@ interface CheckResult {
33
33
  }
34
34
  declare function check(params: CheckParams): Promise<CheckResult>;
35
35
 
36
+ declare const BINDING_KIND = 30079;
36
37
  interface BindingInput {
37
38
  principal: string;
38
39
  btc: string;
@@ -57,6 +58,7 @@ interface BindingEnvelope {
57
58
  btc?: string;
58
59
  nostr?: string;
59
60
  message: string;
61
+ message_b64url?: string;
60
62
  btc_signature?: string;
61
63
  btc_scheme?: 'bip322' | 'legacy';
62
64
  nostr_event?: BindingNostrEvent;
@@ -76,6 +78,27 @@ type BindingVerifyResult = {
76
78
  declare function buildBindingMessage(input: BindingInput): string;
77
79
  declare function bindingId(message: string): string;
78
80
  declare function verifyBinding(envelope: BindingEnvelope): BindingVerifyResult;
81
+ declare function xOnlyHexToNpub(hex: string): string;
82
+ interface BindingEventTemplate {
83
+ kind: typeof BINDING_KIND;
84
+ pubkey: string;
85
+ created_at: number;
86
+ tags: string[][];
87
+ content: string;
88
+ }
89
+ declare function buildBindingEventTemplate(params: {
90
+ message: string;
91
+ btcSignature: string;
92
+ nostrPubkeyHex: string;
93
+ btc: string;
94
+ createdAt?: number;
95
+ }): BindingEventTemplate;
96
+ declare function assembleBindingEnvelope(params: {
97
+ message: string;
98
+ btcSignature: string;
99
+ btcScheme?: 'bip322' | 'legacy';
100
+ nostrEvent: BindingNostrEvent;
101
+ }): BindingEnvelope;
79
102
 
80
103
  declare function isNip07Available(): boolean;
81
104
  declare function getNostrPublicKey(): Promise<string | null>;
@@ -94,4 +117,4 @@ interface StatusMeta {
94
117
  }
95
118
  declare const STATUS_META: Record<StatusCode, StatusMeta>;
96
119
 
97
- export { type BindingEnvelope, type BindingInput, type BindingNostrEvent, type BindingStatus, type BindingVerifyResult, type CheckParams, type CheckResult, IdentityBinding, Network, NostrEvent, STATUS_META, type Severity, StatusCode, type StatusMeta, VerifyOptions, bindingId, buildBindingMessage, check, getNip07Info, getNostrPublicKey, isNip07Available, signNostrEvent, verifyBinding };
120
+ export { type BindingEnvelope, type BindingEventTemplate, type BindingInput, type BindingNostrEvent, type BindingStatus, type BindingVerifyResult, type CheckParams, type CheckResult, IdentityBinding, Network, NostrEvent, STATUS_META, type Severity, StatusCode, type StatusMeta, VerifyOptions, assembleBindingEnvelope, bindingId, buildBindingEventTemplate, buildBindingMessage, check, getNip07Info, getNostrPublicKey, isNip07Available, signNostrEvent, verifyBinding, xOnlyHexToNpub };
package/dist/index.js CHANGED
@@ -1360,6 +1360,63 @@ function verifyBinding(envelope) {
1360
1360
  return fail("malformed");
1361
1361
  }
1362
1362
  }
1363
+ function xOnlyHexToNpub(hex) {
1364
+ const bytes = fromHex(hex);
1365
+ if (bytes.length !== 32) throw new Error("x-only Nostr key must be 32 bytes");
1366
+ return base.bech32.encode("npub", base.bech32.toWords(bytes), 90);
1367
+ }
1368
+ function buildBindingEventTemplate(params) {
1369
+ const id = bindingId(params.message);
1370
+ return {
1371
+ kind: BINDING_KIND,
1372
+ pubkey: params.nostrPubkeyHex.toLowerCase(),
1373
+ created_at: params.createdAt ?? Math.floor(Date.now() / 1e3),
1374
+ tags: [
1375
+ ["d", `oc-attest-binding:${id}`],
1376
+ ["btc", params.btc],
1377
+ ["oc", "binding-attestation"],
1378
+ ["v", "1"]
1379
+ ],
1380
+ content: JSON.stringify({ message: params.message, btc_signature: params.btcSignature })
1381
+ };
1382
+ }
1383
+ function parseBindingFields(message) {
1384
+ const body = message.split("\n");
1385
+ const at = (i, prefix) => {
1386
+ const line = body[i];
1387
+ if (typeof line !== "string" || !line.startsWith(prefix)) {
1388
+ throw new Error(`binding message line ${i + 1} is malformed`);
1389
+ }
1390
+ return line.slice(prefix.length);
1391
+ };
1392
+ return {
1393
+ principal: at(2, "principal: "),
1394
+ btc: at(3, "btc: "),
1395
+ nostr: at(4, "nostr: ")
1396
+ };
1397
+ }
1398
+ function toBase64Url(s) {
1399
+ const bytes = new TextEncoder().encode(s);
1400
+ let bin = "";
1401
+ for (const b of bytes) bin += String.fromCharCode(b);
1402
+ const b64 = typeof btoa !== "undefined" ? btoa(bin) : Buffer.from(bytes).toString("base64");
1403
+ return b64.replace(/\+/g, "-").replace(/\//g, "_").replace(/=+$/, "");
1404
+ }
1405
+ function assembleBindingEnvelope(params) {
1406
+ const { principal, btc, nostr } = parseBindingFields(params.message);
1407
+ return {
1408
+ binding_id: bindingId(params.message),
1409
+ v: 1,
1410
+ principal,
1411
+ btc,
1412
+ nostr,
1413
+ message: params.message,
1414
+ message_b64url: toBase64Url(params.message),
1415
+ btc_signature: params.btcSignature,
1416
+ btc_scheme: params.btcScheme ?? "bip322",
1417
+ nostr_event: params.nostrEvent
1418
+ };
1419
+ }
1363
1420
  var AUTH_HEADER = "orangecheck-auth";
1364
1421
  var AUTH_ACK = "I authorize this session under the OrangeCheck auth challenge.";
1365
1422
  function randomNonce() {
@@ -2297,7 +2354,9 @@ var STATUS_META = {
2297
2354
 
2298
2355
  exports.DEFAULT_RELAYS = DEFAULT_RELAYS;
2299
2356
  exports.STATUS_META = STATUS_META;
2357
+ exports.assembleBindingEnvelope = assembleBindingEnvelope;
2300
2358
  exports.bindingId = bindingId;
2359
+ exports.buildBindingEventTemplate = buildBindingEventTemplate;
2301
2360
  exports.buildBindingMessage = buildBindingMessage;
2302
2361
  exports.buildCanonicalMessage = buildCanonicalMessage;
2303
2362
  exports.check = check;
@@ -2357,5 +2416,6 @@ exports.verifyGitHubIdentity = verifyGitHubIdentity;
2357
2416
  exports.verifyIdentity = verifyIdentity;
2358
2417
  exports.verifyNostrIdentity = verifyNostrIdentity;
2359
2418
  exports.verifyTwitterIdentity = verifyTwitterIdentity;
2419
+ exports.xOnlyHexToNpub = xOnlyHexToNpub;
2360
2420
  //# sourceMappingURL=index.js.map
2361
2421
  //# sourceMappingURL=index.js.map