bsv-bap 0.1.12 → 0.1.13

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.
@@ -1,4 +1,4 @@
1
- import { type PublicKey, PrivateKey } from "@bsv/sdk";
1
+ import { PublicKey, PrivateKey } from "@bsv/sdk";
2
2
  import { BaseClass } from "./BaseClass";
3
3
  import type { IdentityAttributes, MemberIdentity } from "./interface";
4
4
  export declare class MemberID extends BaseClass {
@@ -33,6 +33,43 @@ export declare class MemberID extends BaseClass {
33
33
  * Get the public key for encrypting data for this identity
34
34
  */
35
35
  getEncryptionPublicKey(): string;
36
+ /**
37
+ * Get a derived encryption key using a seed string (Type42 derivation)
38
+ * This allows deriving unique encryption keys per friend/conversation
39
+ * @param seed - The seed string (e.g., friend's BAP ID)
40
+ * @returns The derived private key for this seed
41
+ */
42
+ private getEncryptionPrivateKeyWithSeed;
43
+ /**
44
+ * Get the encryption key pair for a specific seed
45
+ * @param seed - The seed string (e.g., friend's BAP ID)
46
+ */
47
+ getEncryptionKeyWithSeed(seed: string): {
48
+ privKey: PrivateKey;
49
+ pubKey: PublicKey;
50
+ };
51
+ /**
52
+ * Get the public key for encrypting data for a specific seed
53
+ * This is the public key to include in friend requests
54
+ * @param seed - The seed string (e.g., friend's BAP ID)
55
+ */
56
+ getEncryptionPublicKeyWithSeed(seed: string): string;
57
+ /**
58
+ * Encrypt data using a seed-derived key
59
+ * @param stringData - The data to encrypt
60
+ * @param seed - The seed string for key derivation (e.g., friend's BAP ID)
61
+ * @param counterPartyPublicKey - Optional public key of the recipient
62
+ * @returns Base64 encoded encrypted data
63
+ */
64
+ encryptWithSeed(stringData: string, seed: string, counterPartyPublicKey?: string): string;
65
+ /**
66
+ * Decrypt data using a seed-derived key
67
+ * @param ciphertext - Base64 encoded encrypted data
68
+ * @param seed - The seed string for key derivation (e.g., friend's BAP ID)
69
+ * @param counterPartyPublicKey - Optional public key of the sender
70
+ * @returns Decrypted string
71
+ */
72
+ decryptWithSeed(ciphertext: string, seed: string, counterPartyPublicKey?: string): string;
36
73
  /**
37
74
  * Export member data in bitcoin-backup compatible format
38
75
  * @param label Optional user-defined label
package/dist/index.cjs ADDED
@@ -0,0 +1,8 @@
1
+ // @bun @bun-cjs
2
+ (function(exports, require, module, __filename, __dirname) {var{defineProperty:g,getOwnPropertyNames:i,getOwnPropertyDescriptor:r}=Object,a=Object.prototype.hasOwnProperty;var K=new WeakMap,e=(j)=>{var $=K.get(j),J;if($)return $;if($=g({},"__esModule",{value:!0}),j&&typeof j==="object"||typeof j==="function")i(j).map((q)=>!a.call($,q)&&g($,q,{get:()=>j[q],enumerable:!(J=r(j,q))||J.enumerable}));return K.set(j,$),$};var t=(j,$)=>{for(var J in $)g(j,J,{get:$[J],enumerable:!0,configurable:!0,set:(q)=>$[J]=()=>q})};var Xj={};t(Xj,{MemberID:()=>_,MasterID:()=>V,BAP:()=>s});module.exports=e(Xj);var G=require("@bsv/sdk"),y=require("@bsv/sdk");var jj=async(j,$,J,q)=>{let z=`${J}${j}`;return(await fetch(z,{method:"post",headers:{"Content-type":"application/json; charset=utf-8",token:q,format:"json"},body:JSON.stringify($)})).json()},H=(j,$)=>async(J,q)=>{return jj(J,q,j,$)};var c=require("@bsv/sdk"),{toHex:m,toArray:b}=c.Utils,k="1BAPSuaPnfGnSBM3GLV9yhxUdYe4vGbdMT",p=m(b(k)),B="15PciHG22SNLQJXMoSUaWVi7WSqc7hCfva",Mj=m(b(B)),D="https://api.sigmaidentity.com/v1",M=2147483647,x="m/424150'/0'/0'",F=`m/424150'/${M}'/${M}'`;var Z=require("@bsv/sdk");var C={getRandomBytes(j=32){if(typeof globalThis<"u"&&globalThis.crypto&&globalThis.crypto.getRandomValues){let $=new Uint8Array(j);return globalThis.crypto.getRandomValues($),$}throw Error("Secure random number generation not available. crypto.getRandomValues() is required for cryptographic operations. This environment may not be suitable for secure key generation.")},getRandomString(j=32){let $=this.getRandomBytes(j);return Array.from($,(J)=>J.toString(16).padStart(2,"0")).join("")},getSigningPathFromHex(j,$=!0){let J="m",q=j.match(/.{1,8}/g);if(!q)throw Error("Invalid hex string");let z=2147483647;for(let Q of q){let L=Number(`0x${Q}`);if(L>z)L-=z;J+=`/${L}${$?"'":""}`}return J},getNextIdentityPath(j){let $=j.split("/"),J=$[$.length-2],q=!1;if(J.match("'"))q=!0;let z=(Number(J.replace(/[^0-9]/g,""))+1).toString();return $[$.length-2]=z+(q?"'":""),$[$.length-1]=`0${q?"'":""}`,$.join("/")},getNextPath(j){let $=j.split("/"),J=$[$.length-1],q=!1;if(J.match("'"))q=!0;let z=(Number(J.replace(/[^0-9]/g,""))+1).toString();return $[$.length-1]=z+(q?"'":""),$.join("/")}};var Y=require("@bsv/sdk");var f=require("@bsv/sdk");var{toArray:O,toUTF8:$j,toBase64:Jj}=f.Utils,{electrumDecrypt:qj,electrumEncrypt:zj}=f.ECIES;class N{identityAttributes={};encrypt(j,$){let{privKey:J,pubKey:q}=this.getEncryptionKey(),z=$?f.PublicKey.fromString($):q;return Jj(zj(O(j),z,J))}decrypt(j,$){let{privKey:J}=this.getEncryptionKey(),q;if($)q=f.PublicKey.fromString($);return $j(qj(O(j,"base64"),J,q))}signOpReturnWithAIP(j,$){let J=this.getAIPMessageBuffer(j),{address:q,signature:z}=this.signMessage(J.flat(),$);return this.formatAIPOutput(J,q,z)}getAttributes(){return this.identityAttributes}getAttribute(j){if(this.identityAttributes[j])return this.identityAttributes[j];return null}setAttribute(j,$){if(!$)return;if(this.identityAttributes[j])this.updateExistingAttribute(j,$);else this.createNewAttribute(j,$)}unsetAttribute(j){delete this.identityAttributes[j]}addAttribute(j,$,J=""){let q=J;if(!J)q=C.getRandomString();this.identityAttributes[j]={value:$,nonce:q}}getAttributeUrns(){let j="";for(let $ in this.identityAttributes){let J=this.getAttributeUrn($);if(J)j+=`${J}
3
+ `}return j}getAttributeUrn(j){let $=this.identityAttributes[j];if($)return`urn:bap:id:${j}:${$.value}:${$.nonce}`;return null}parseStringUrns(j){let $={},J=j.replace(/^\s+/g,"").replace(/\r/gm,"").split(`
4
+ `);for(let q of J){let Q=q.replace(/^\s+/g,"").replace(/\s+$/g,"").split(":");if(Q[0]==="urn"&&Q[1]==="bap"&&Q[2]==="id"&&Q[3]&&Q[4]&&Q[5])$[Q[3]]={value:Q[4],nonce:Q[5]}}return $}parseAttributes(j){if(typeof j==="string")return this.parseStringUrns(j);for(let $ in j)if(!j[$].value||!j[$].nonce)throw Error("Invalid identity attribute");return j||{}}updateExistingAttribute(j,$){if(typeof $==="string"){this.identityAttributes[j].value=$;return}if(this.identityAttributes[j].value=$.value||"",$.nonce)this.identityAttributes[j].nonce=$.nonce}createNewAttribute(j,$){if(typeof $==="string"){this.addAttribute(j,$);return}this.addAttribute(j,$.value||"",$.nonce)}getAIPMessageBuffer(j,$){let J=j.findIndex((z)=>z[0]===f.OP.OP_RETURN),q=[];if(J===-1)q.push([f.OP.OP_RETURN]),J=0;if($)for(let z of $)q.push(j[J+z]);else for(let z of j)q.push(z);return q}formatAIPOutput(j,$,J){let q=[O("|"),O(B),O("BITCOIN_ECDSA"),O($),O(J,"base64")];return[...j,...q]}}var{magicHash:Qj}=Y.BSM,{toArray:h,toUTF8:Zj,toBase64:Wj,toHex:Lj}=Y.Utils,{electrumDecrypt:wj,electrumEncrypt:Yj}=Y.ECIES;class _ extends N{key;idName;description;address;identityKey;constructor(j,$={}){super();this.key=j,this.address=j.toAddress(),this.idName="Member ID 1",this.description="",this.identityKey="",this.identityAttributes=this.parseAttributes($)}signMessage(j,$){let J=this.key,q=J.toAddress(),z=Y.BSM.sign(j,J,"raw"),Q=new Y.BigNumber(Qj(j)),L=z.CalculateRecoveryFactor(J.toPublicKey(),Q),w=Y.BSM.sign(j,J,"raw").toCompact(L,!0,"base64");return{address:q,signature:w}}signOpReturnWithAIP(j){let $=this.getAIPMessageBuffer(j),{address:J,signature:q}=this.signMessage($.flat());return this.formatAIPOutput($,J,q)}getPublicKey(){return this.key.toPublicKey().toString()}import(j){this.idName=j.name,this.description=j.description,this.key=Y.PrivateKey.fromWif(j.derivedPrivateKey),this.address=this.key.toAddress(),this.identityAttributes=j.identityAttributes||{},this.identityKey=j.identityKey}static fromMemberIdentity(j){let $=new _(Y.PrivateKey.fromWif(j.derivedPrivateKey));return $.import(j),$}static fromBackup(j){let $=new _(Y.PrivateKey.fromWif(j.wif)),J=JSON.parse($.decrypt(j.id));return $.import(J),$}export(){return{name:this.idName,description:this.description,derivedPrivateKey:this.key.toWif(),address:this.address,identityAttributes:this.getAttributes(),identityKey:this.identityKey}}getEncryptionKey(){return{privKey:this.key.deriveChild(this.key.toPublicKey(),F),pubKey:this.key.deriveChild(this.key.toPublicKey(),F).toPublicKey()}}getEncryptionPublicKey(){let{pubKey:j}=this.getEncryptionKey();return j.toString()}getEncryptionPrivateKeyWithSeed(j){let $=Lj(Y.Hash.sha256(j,"utf8"));return this.key.deriveChild(this.key.toPublicKey(),$)}getEncryptionKeyWithSeed(j){let $=this.getEncryptionPrivateKeyWithSeed(j);return{privKey:$,pubKey:$.toPublicKey()}}getEncryptionPublicKeyWithSeed(j){return this.getEncryptionPrivateKeyWithSeed(j).toPublicKey().toString()}encryptWithSeed(j,$,J){let q=this.getEncryptionPrivateKeyWithSeed($),z=q.toPublicKey(),Q=this.key.toPublicKey().constructor,L=J?Q.fromString(J):z;return Wj(Yj(h(j),L,q))}decryptWithSeed(j,$,J){let q=this.getEncryptionPrivateKeyWithSeed($),z;if(J)z=Y.PublicKey.fromString(J);return Zj(wj(h(j,"base64"),q,z))}exportForBackup(j){let $=this.export(),J=this.encrypt(JSON.stringify($));return{wif:this.key.toWif(),id:J,...j&&{label:j},createdAt:new Date().toISOString()}}}var{toArray:U,toHex:R,toBase58:Gj,toUTF8:o,toBase64:v}=Z.Utils,{electrumDecrypt:P,electrumEncrypt:A}=Z.ECIES,{magicHash:n}=Z.BSM;class V extends N{#$;#j;#J;#Q=D;#W="";#q;#Z;#z;#L;idName;description;rootAddress;identityKey;identityAttributes;getApiData;constructor(j,$={},J=""){super();if(j instanceof Z.HD)if(this.#J=!1,J){let z=R(Z.Hash.sha256(J,"utf8")),Q=C.getSigningPathFromHex(z);this.#$=j.derive(Q)}else this.#$=j;else if(this.#J=!0,this.#j=j.rootPk,J){let z=R(Z.Hash.sha256(J,"utf8"));this.#j=this.#j.deriveChild(this.#j.toPublicKey(),z)}if(this.#L=J,this.idName="ID 1",this.description="",this.#q=`${x}/0/0/0`,this.#Z=`${x}/0/0/0`,this.#z=`${x}/0/0/1`,this.#J){if(!this.#j)throw Error("Master private key not initialized");let z=this.#j.deriveChild(this.#j.toPublicKey(),this.#q);this.rootAddress=z.toPublicKey().toAddress()}else{if(!this.#$)throw Error("HD private key not initialized");let z=this.#$.derive(this.#q);this.rootAddress=z.privKey.toPublicKey().toAddress()}this.identityKey=this.deriveIdentityKey(this.rootAddress);let q={...$};this.identityAttributes=this.parseAttributes(q),this.getApiData=H(this.#Q,this.#W)}set BAP_SERVER(j){this.#Q=j}get BAP_SERVER(){return this.#Q}set BAP_TOKEN(j){this.#W=j}get BAP_TOKEN(){return this.#W}deriveIdentityKey(j){let $=R(Z.Hash.sha256(j,"utf8"));return Gj(Z.Hash.ripemd160($,"hex"))}parseAttributes(j){if(typeof j==="string")return this.parseStringUrns(j);for(let $ in j)if(!j[$].value||!j[$].nonce)throw Error("Invalid identity attribute");return j||{}}parseStringUrns(j){let $={},J=j.replace(/^\s+/g,"").replace(/\r/gm,"").split(`
5
+ `);for(let q of J){let Q=q.replace(/^\s+/g,"").replace(/\s+$/g,"").split(":");if(Q[0]==="urn"&&Q[1]==="bap"&&Q[2]==="id"&&Q[3]&&Q[4]&&Q[5])$[Q[3]]={value:Q[4],nonce:Q[5]}}return $}getIdentityKey(){return this.identityKey}set rootPath(j){if(this.#J){if(this.#q=j,!this.#j)throw Error("Master private key not initialized");let $=this.#j.deriveChild(this.#j.toPublicKey(),j);this.rootAddress=$.toPublicKey().toAddress(),this.#Z=j,this.#z=j}else{let $=j;if(j.split("/").length<5)$=`${x}${j}`;if(!this.validatePath($))throw Error(`invalid signing path given ${$}`);if(this.#q=$,!this.#$)throw Error("HD private key not initialized");let J=this.#$.derive($);this.rootAddress=J.pubKey.toAddress(),this.#Z=$,this.#z=$}this.identityKey=this.deriveIdentityKey(this.rootAddress)}get rootPath(){return this.#q}getRootPath(){return this.#q}set currentPath(j){if(this.#J)this.#Z=this.#z,this.#z=j;else{let $=j;if(j.split("/").length<5)$=`${x}${j}`;if(!this.validatePath($))throw Error("invalid signing path given");this.#Z=this.#z,this.#z=$}}get currentPath(){return this.#z}get previousPath(){return this.#Z}get idSeed(){return this.#L}incrementPath(){this.currentPath=C.getNextPath(this.currentPath)}validatePath(j){if(j.match(/\/[0-9]{1,10}'?\/[0-9]{1,10}'?\/[0-9]{1,10}'?\/[0-9]{1,10}'?\/[0-9]{1,10}'?\/[0-9]{1,10}'?/)){let $=j.split("/");if($.length===7&&Number($[1].replace("'",""))<=M&&Number($[2].replace("'",""))<=M&&Number($[3].replace("'",""))<=M&&Number($[4].replace("'",""))<=M&&Number($[5].replace("'",""))<=M&&Number($[6].replace("'",""))<=M)return!0}return!1}getInitialIdTransaction(){return this.getIdTransaction(this.#q)}getIdTransaction(j=""){if(this.#z===this.#q)throw Error("Current path equals rootPath. ID was probably not initialized properly");let $=[U(k),U("ID"),U(this.identityKey),U(this.getCurrentAddress())];return this.signOpReturnWithAIP($,j||this.#Z)}getAddress(j){if(this.#J){if(!this.#j)throw Error("Master private key not initialized");return this.#j.deriveChild(this.#j.toPublicKey(),j).toPublicKey().toAddress()}if(!this.#$)throw Error("HD private key not initialized");return this.#$.derive(j).privKey.toPublicKey().toAddress()}getCurrentAddress(){return this.getAddress(this.#z)}getEncryptionKey(){if(this.#J){if(!this.#j)throw Error("Master private key not initialized");let J=this.#j.deriveChild(this.#j.toPublicKey(),this.#q),q=J.deriveChild(J.toPublicKey(),F);return{privKey:q,pubKey:q.toPublicKey()}}if(!this.#$)throw Error("HD private key not initialized");let $=this.#$.derive(this.#q).derive(F).privKey;return{privKey:$,pubKey:$.toPublicKey()}}getEncryptionKeyType42(){if(this.#J)return this.getEncryptionKey();if(!this.#$)throw Error("HD private key not initialized");let j=this.#$.derive(this.#q),$=j.privKey.deriveChild(j.toPublic().pubKey,F);return{privKey:$,pubKey:$.toPublicKey()}}getEncryptionPublicKey(){let{pubKey:j}=this.getEncryptionKey();return j.toString()}getEncryptionPublicKeyWithSeed(j){return this.getEncryptionPrivateKeyWithSeed(j).toPublicKey().toString()}encrypt(j,$){let{privKey:J,pubKey:q}=this.getEncryptionKey(),z=$?Z.PublicKey.fromString($):q;return v(A(U(j),z,J))}decrypt(j,$){let{privKey:J}=this.getEncryptionKey(),q;if($)q=Z.PublicKey.fromString($);return o(P(U(j,"base64"),J,q))}encryptWithSeed(j,$,J){let q=this.getEncryptionPrivateKeyWithSeed($),z=q.toPublicKey(),Q=J?Z.PublicKey.fromString(J):z;return v(A(U(j),Q,q))}decryptWithSeed(j,$,J){let q=this.getEncryptionPrivateKeyWithSeed($),z;if(J)z=Z.PublicKey.fromString(J);return o(P(U(j,"base64"),q,z))}getEncryptionPrivateKeyWithSeed(j){let $=R(Z.Hash.sha256(j,"utf8"));if(this.#J){if(!this.#j)throw Error("Master private key not initialized");let z=this.#j.deriveChild(this.#j.toPublicKey(),this.#q);return z.deriveChild(z.toPublicKey(),$)}if(!this.#$)throw Error("HD private key not initialized");let J=C.getSigningPathFromHex($);return this.#$.derive(this.#q).derive(J).privKey}getAttestation(j){let $=Z.Hash.sha256(j,"utf8");return`bap:attest:${R($)}:${this.getIdentityKey()}`}getAttestationHash(j){let $=this.getAttributeUrn(j);if(!$)return null;let J=this.getAttestation($),q=Z.Hash.sha256(J,"utf8");return R(q)}signMessage(j,$){let J=$||this.#z,q;if(this.#J){if(!this.#j)throw Error("Master private key not initialized");q=this.#j.deriveChild(this.#j.toPublicKey(),J)}else{if(!this.#$)throw Error("HD private key not initialized");q=this.#$.derive(J).privKey}let z=q.toAddress(),Q=Z.BSM.sign(j,q,"raw"),L=new Z.BigNumber(n(j)),w=Q.CalculateRecoveryFactor(q.toPublicKey(),L),X=Z.BSM.sign(j,q,"raw").toCompact(w,!0,"base64");return{address:z,signature:X}}signMessageWithSeed(j,$){let J=R(Z.Hash.sha256($,"utf8")),q;if(this.#J){if(!this.#j)throw Error("Master private key not initialized");let S=this.#j.deriveChild(this.#j.toPublicKey(),this.#q);q=S.deriveChild(S.toPublicKey(),J)}else{if(!this.#$)throw Error("HD private key not initialized");let S=C.getSigningPathFromHex(J);q=this.#$.derive(this.#q).derive(S).privKey}let z=q.toPublicKey().toAddress(),Q=U(j,"utf8"),L=Z.BSM.sign(Q,q,"raw"),w=new Z.BigNumber(n(Q)),X=L.CalculateRecoveryFactor(q.toPublicKey(),w),T=Z.BSM.sign(Q,q,"raw").toCompact(X,!0,"base64");return{address:z,signature:T}}signOpReturnWithAIP(j,$=""){let J=this.getAIPMessageBuffer(j),{address:q,signature:z}=this.signMessage(J.flat(),$);return this.formatAIPOutput(j,q,z)}async getIdSigningKeys(){let j=await this.getApiData("/signing-keys",{idKey:this.identityKey});return console.log("getIdSigningKeys",j),j}async getAttributeAttestations(j){let $=this.getAttestationHash(j),J=await this.getApiData("/attestation/get",{hash:$});return console.log("getAttestations",j,$,J),J}import(j){this.idName=j.name,this.description=j.description||"",this.identityKey=j.identityKey,this.#q=j.rootPath,this.rootAddress=j.rootAddress,this.#Z=j.previousPath,this.#z=j.currentPath,this.#L=("idSeed"in j?j.idSeed:"")||"",this.identityAttributes=this.parseAttributes(j.identityAttributes)}export(){return{name:this.idName,description:this.description,identityKey:this.identityKey,rootPath:this.#q,rootAddress:this.rootAddress,previousPath:this.#Z,currentPath:this.#z,idSeed:this.#L,identityAttributes:this.getAttributes(),lastIdPath:""}}exportMemberBackup(){let j;if(this.#J){if(!this.#j)throw Error("Master private key not initialized");j=this.#j.deriveChild(this.#j.toPublicKey(),this.#z)}else{if(!this.#$)throw Error("HD private key not initialized");j=this.#$.derive(this.#z).privKey}return{name:this.idName,description:this.description,derivedPrivateKey:j.toWif(),address:j.toPublicKey().toAddress(),identityAttributes:this.getAttributes(),identityKey:this.identityKey}}newId(){this.incrementPath();let j;if(this.#J){if(!this.#j)throw Error("Master private key not initialized");j=this.#j.deriveChild(this.#j.toPublicKey(),this.#z)}else{if(!this.#$)throw Error("HD private key not initialized");j=this.#$.derive(this.#z).privKey}return new _(j)}exportMember(){let j=this.exportMemberBackup(),$;if(this.#J){if(!this.#j)throw Error("Master private key not initialized");$=this.#j.deriveChild(this.#j.toPublicKey(),this.#z)}else{if(!this.#$)throw Error("HD private key not initialized");$=this.#$.derive(this.#z).privKey}let J=v(A(U(JSON.stringify(j)),$.toPublicKey()));return{wif:j.derivedPrivateKey,encryptedData:J}}}var{toArray:W,toUTF8:E,toBase64:l,toHex:I}=y.Utils,{electrumEncrypt:u,electrumDecrypt:d}=G.ECIES;class s{#$;#j;#J;#Q={};#W=D;#q="";#Z="";#z=0;getApiData;constructor(j,$="",J=""){if(!j)throw Error("No key source given");if(typeof j==="string")this.#$=G.HD.fromString(j),this.#J=!1;else this.#j=G.PrivateKey.fromWif(j.rootPk),this.#J=!0;if($)this.#q=$;if(J)this.#W=J;this.getApiData=H(this.#W,this.#q)}get lastIdPath(){return this.#Z}getPublicKey(j=""){if(this.#J){if(!this.#j)throw Error("Master private key not initialized");if(j)return this.#j.deriveChild(this.#j.toPublicKey(),j).toPublicKey().toString();return this.#j.toPublicKey().toString()}if(!this.#$)throw Error("HD private key not initialized");if(j)return this.#$.derive(j).pubKey.toString();return this.#$.pubKey.toString()}getHdPublicKey(j=""){if(this.#J)throw Error("HD public keys are not available in Type 42 mode");if(!this.#$)throw Error("HD private key not initialized");if(j)return this.#$.derive(j).toPublic().toString();return this.#$.toPublic().toString()}set BAP_SERVER(j){this.#W=j;for(let $ in this.#Q)this.#Q[$].BAP_SERVER=j}get BAP_SERVER(){return this.#W}set BAP_TOKEN(j){this.#q=j;for(let $ in this.#Q)this.#Q[$].BAP_TOKEN=j}get BAP_TOKEN(){return this.#q}checkIdBelongs(j){let $;if(this.#J){if(!this.#j)throw Error("Master private key not initialized");$=this.#j.deriveChild(this.#j.toPublicKey(),j.rootPath).toPublicKey().toAddress()}else{if(!this.#$)throw Error("HD private key not initialized");$=this.#$.derive(j.rootPath).pubKey.toAddress()}if($!==j.rootAddress)throw Error("ID does not belong to this private key");return!0}listIds(){return Object.keys(this.#Q)}newId(j,$,J={},q=""){let z,Q,L;if(typeof j==="object"||j===void 0||typeof j==="string"&&j.startsWith("/"))Q=typeof j==="string"?j:void 0,L=typeof j==="object"?j:typeof $==="object"?$:{},z="Default Identity";else z=j,Q=typeof $==="string"?$:void 0,L=typeof $==="object"?$:J;let w;if(Q)w=Q;else if(this.#J)w=`bap:${this.#z}`,this.#z++;else w=this.getNextValidPath();let X;if(this.#J){if(!this.#j)throw Error("Type 42 parameters not initialized");X=new V({rootPk:this.#j},L,q)}else{if(!this.#$)throw Error("HD private key not initialized");X=new V(this.#$,L,q)}if(X.BAP_SERVER=this.#W,X.BAP_TOKEN=this.#q,X.idName=z,X.rootPath=w,this.#J)X.currentPath=w;else X.currentPath=C.getNextPath(w);let T=X.getIdentityKey();return this.#Q[T]=X,this.#Z=w,this.#Q[T]}removeId(j){delete this.#Q[j]}getNextValidPath(){if(this.#Z)return C.getNextIdentityPath(this.#Z);return`/0'/${Object.keys(this.#Q).length}'/0'`}newIdWithCounter(j,$=`Identity ${j}`){if(!this.#J)throw Error("newIdWithCounter only works in Type 42 mode");let J=`bap:${j}`;return this.newId($,J)}getId(j){return this.#Q[j]||null}setId(j){this.checkIdBelongs(j),this.#Q[j.getIdentityKey()]=j}importIds(j,$=!0){if($&&typeof j==="string"){this.importEncryptedIds(j);return}let J=j;if(!J.lastIdPath)throw Error("ID cannot be imported as it is not complete");if(!J.ids)throw Error(`ID data is not in the correct format: ${j}`);let q=j.lastIdPath;for(let z of J.ids){if(!z.identityKey||!z.identityAttributes||!z.rootAddress)throw Error("ID cannot be imported as it is not complete");let Q;if(this.#J){if(!this.#j)throw Error("Type 42 parameters not initialized");Q=new V({rootPk:this.#j},{},z.idSeed)}else{if(!this.#$)throw Error("HD private key not initialized");Q=new V(this.#$,{},z.idSeed)}if(Q.BAP_SERVER=this.#W,Q.BAP_TOKEN=this.#q,Q.import(z),q==="")q=Q.currentPath;if(this.checkIdBelongs(Q),this.#Q[Q.getIdentityKey()]=Q,this.#J&&Q.rootPath.startsWith("bap:")){let L=Q.rootPath.split(":");if(L.length>=2){let w=Number.parseInt(L[1],10);if(!Number.isNaN(w))this.#z=Math.max(this.#z,w+1)}}}this.#Z=q}importEncryptedIds(j){let $=this.decrypt(j),J=JSON.parse($);if(Array.isArray(J)){console.log(`Importing old format:
6
+ `,J),this.importOldIds(J);return}if(typeof J!=="object")throw Error("decrypted, but found unrecognized identities format");this.importIds(J,!1)}importOldIds(j){for(let $ of j){let J;if(this.#J){if(!this.#j)throw Error("Type 42 parameters not initialized");J=new V({rootPk:this.#j},{},$.idSeed??"")}else{if(!this.#$)throw Error("HD private key not initialized");J=new V(this.#$,{},$.idSeed??"")}J.BAP_SERVER=this.#W,J.BAP_TOKEN=this.#q,J.import($),this.checkIdBelongs(J),this.#Q[J.getIdentityKey()]=J,this.#Z=J.currentPath}}exportIds(j,$=!0){let J={lastIdPath:this.#Z,ids:[]},q=j||Object.keys(this.#Q);for(let z of q){if(!this.#Q[z])throw Error(`Identity ${z} not found`);J.ids.push(this.#Q[z].export())}if($)return this.encrypt(JSON.stringify(J));return J}exportId(j,$=!0){let J={lastIdPath:this.#Z,ids:[]};if(J.ids.push(this.#Q[j].export()),$)return this.encrypt(JSON.stringify(J));return J}encrypt(j){if(this.#J){if(!this.#j)throw Error("Master private key not initialized");let J=this.#j.deriveChild(this.#j.toPublicKey(),F);return l(u(W(j),J.toPublicKey(),null))}if(!this.#$)throw Error("HD private key not initialized");let $=this.#$.derive(F);return l(u(W(j),$.pubKey,null))}decrypt(j){if(this.#J){if(!this.#j)throw Error("Master private key not initialized");let J=this.#j.deriveChild(this.#j.toPublicKey(),F);return E(d(W(j,"base64"),J))}if(!this.#$)throw Error("HD private key not initialized");let $=this.#$.derive(F);return E(d(W(j,"base64"),$.privKey))}signAttestationWithAIP(j,$,J=0,q=""){let z=this.getId($);if(!z)throw Error("Could not find identity to attest with");let Q=this.getAttestationBuffer(j,J,q),{address:L,signature:w}=z.signMessage(Q);return this.createAttestationTransaction(j,J,L,w,q)}verifyAttestationWithAIP(j){if(!j.every((q)=>Array.isArray(q))||j[0][0]!==G.OP.OP_RETURN||I(j[1])!==p)throw Error("Not a valid BAP transaction");let $=I(j[7])==="44415441"?5:0,J={type:E(j[2]),hash:I(j[3]),sequence:E(j[4]),signingProtocol:E(j[7+$]),signingAddress:E(j[8+$]),signature:l(j[9+$])};if($&&j[3]===j[8])J.data=I(j[9]);console.log({attestation:J});try{let q=[];for(let z=0;z<6+$;z++)q.push(j[z]);J.verified=this.verifySignature(q.flat(),J.signingAddress,J.signature)}catch{J.verified=!1}return J}createAttestationTransaction(j,$,J,q,z=""){let Q=[[G.OP.OP_RETURN],W(k),W("ATTEST"),W(j),W(`${$}`),W("|")];if(z)Q.push(W(k),W("DATA"),W(j),W(z),W("|"));return Q.push(W(B),W("BITCOIN_ECDSA"),W(J),W(q,"base64")),console.log({elements:Q}),Q}getAttestationBuffer(j,$=0,J=""){let q=[[G.OP.OP_RETURN],W(k),W("ATTEST"),W(j),W(`${$}`),W("|")];if(J)q.push(W(k),W("DATA"),W(j),W(J),W("|"));return q.flat()}verifySignature(j,$,J){let q;if(Array.isArray(j))q=j;else if(Buffer.isBuffer(j))q=[...j];else q=W(j,"utf8");let z=G.Signature.fromCompact(J,"base64"),Q;for(let L=0;L<4;L++)try{if(Q=z.RecoverPublicKey(L,new G.BigNumber(G.BSM.magicHash(q))),G.BSM.verify(q,z,Q)&&Q.toAddress()===$)return!0}catch{}return!1}async verifyChallengeSignature(j,$,J,q){if(!this.verifySignature(J,$,q))return!1;try{let Q=await this.getApiData("/attestation/valid",{idKey:j,address:$,challenge:J,signature:q});if(Q?.status==="success"&&Q?.result?.valid===!0)return!0;return!1}catch(Q){return console.error("API call failed:",Q),!1}}async isValidAttestationTransaction(j){if(this.verifyAttestationWithAIP(j))return this.getApiData("/attestation/valid",{tx:j});return!1}async getIdentityFromAddress(j){return this.getApiData("/identity/from-address",{address:j})}async getIdentity(j){return this.getApiData("/identity/get",{idKey:j})}async getAttestationsForHash(j){return this.getApiData("/attestations",{hash:j})}exportForBackup(j,$,J){let z={ids:this.exportIds(),...j&&{label:j},createdAt:new Date().toISOString()};if(this.#J){if(!this.#j)throw Error("Type 42 parameters not initialized");return{...z,rootPk:this.#j.toWif()}}if(!this.#$)throw Error("HD private key not initialized");return{...z,xprv:$||this.#$.toString(),mnemonic:J||""}}exportMemberForBackup(j,$){let J=this.#Q[j];if(!J)throw Error(`Identity ${j} not found`);let q=J.exportMember();return{wif:q.wif,id:q.encryptedData,...$&&{label:$},createdAt:new Date().toISOString()}}}})
7
+
8
+ //# debugId=38F34D7DB4E839A964756E2164756E21
@@ -1,8 +1,8 @@
1
1
  // @bun
2
- import{BSM as l,BigNumber as wj,ECIES as Yj,HD as Gj,OP as K,Signature as Xj,PrivateKey as Fj}from"@bsv/sdk";import{Utils as Cj}from"@bsv/sdk";var i=async(j,$,J,q)=>{let z=`${J}${j}`;return(await fetch(z,{method:"post",headers:{"Content-type":"application/json; charset=utf-8",token:q,format:"json"},body:JSON.stringify($)})).json()},T=(j,$)=>async(J,q)=>{return i(J,q,j,$)};import{Utils as r}from"@bsv/sdk";var{toHex:b,toArray:m}=r,C="1BAPSuaPnfGnSBM3GLV9yhxUdYe4vGbdMT",p=b(m(C)),R="15PciHG22SNLQJXMoSUaWVi7WSqc7hCfva",Oj=b(m(R)),S="https://api.sigmaidentity.com/v1",F=2147483647,k="m/424150'/0'/0'",Y=`m/424150'/${F}'/${F}'`;import{BSM as E,Utils as Qj,ECIES as Zj,Hash as U,PublicKey as H,BigNumber as o,HD as Wj}from"@bsv/sdk";var G={getRandomBytes(j=32){if(typeof globalThis!=="undefined"&&globalThis.crypto&&globalThis.crypto.getRandomValues){let $=new Uint8Array(j);return globalThis.crypto.getRandomValues($),$}throw new Error("Secure random number generation not available. crypto.getRandomValues() is required for cryptographic operations. This environment may not be suitable for secure key generation.")},getRandomString(j=32){let $=this.getRandomBytes(j);return Array.from($,(J)=>J.toString(16).padStart(2,"0")).join("")},getSigningPathFromHex(j,$=!0){let J="m",q=j.match(/.{1,8}/g);if(!q)throw new Error("Invalid hex string");let z=2147483647;for(let Q of q){let W=Number(`0x${Q}`);if(W>z)W-=z;J+=`/${W}${$?"'":""}`}return J},getNextIdentityPath(j){let $=j.split("/"),J=$[$.length-2],q=!1;if(J.match("'"))q=!0;let z=(Number(J.replace(/[^0-9]/g,""))+1).toString();return $[$.length-2]=z+(q?"'":""),$[$.length-1]=`0${q?"'":""}`,$.join("/")},getNextPath(j){let $=j.split("/"),J=$[$.length-1],q=!1;if(J.match("'"))q=!0;let z=(Number(J.replace(/[^0-9]/g,""))+1).toString();return $[$.length-1]=z+(q?"'":""),$.join("/")}};import{BSM as g,PrivateKey as I,BigNumber as qj}from"@bsv/sdk";import{ECIES as a,Utils as e,OP as h,PublicKey as P}from"@bsv/sdk";var{toArray:M,toUTF8:t,toBase64:jj}=e,{electrumDecrypt:$j,electrumEncrypt:Jj}=a;class x{identityAttributes={};encrypt(j,$){let{privKey:J,pubKey:q}=this.getEncryptionKey(),z=$?P.fromString($):q;return jj(Jj(M(j),z,J))}decrypt(j,$){let{privKey:J}=this.getEncryptionKey(),q;if($)q=P.fromString($);return t($j(M(j,"base64"),J,q))}signOpReturnWithAIP(j,$){let J=this.getAIPMessageBuffer(j),{address:q,signature:z}=this.signMessage(J.flat(),$);return this.formatAIPOutput(J,q,z)}getAttributes(){return this.identityAttributes}getAttribute(j){if(this.identityAttributes[j])return this.identityAttributes[j];return null}setAttribute(j,$){if(!$)return;if(this.identityAttributes[j])this.updateExistingAttribute(j,$);else this.createNewAttribute(j,$)}unsetAttribute(j){delete this.identityAttributes[j]}addAttribute(j,$,J=""){let q=J;if(!J)q=G.getRandomString();this.identityAttributes[j]={value:$,nonce:q}}getAttributeUrns(){let j="";for(let $ in this.identityAttributes){let J=this.getAttributeUrn($);if(J)j+=`${J}
2
+ import{BSM as l,BigNumber as kj,ECIES as Oj,HD as _j,OP as K,Signature as Rj,PrivateKey as xj}from"@bsv/sdk";import{Utils as Ej}from"@bsv/sdk";var r=async(j,$,J,q)=>{let z=`${J}${j}`;return(await fetch(z,{method:"post",headers:{"Content-type":"application/json; charset=utf-8",token:q,format:"json"},body:JSON.stringify($)})).json()},T=(j,$)=>async(J,q)=>{return r(J,q,j,$)};import{Utils as a}from"@bsv/sdk";var{toHex:m,toArray:b}=a,C="1BAPSuaPnfGnSBM3GLV9yhxUdYe4vGbdMT",p=m(b(C)),R="15PciHG22SNLQJXMoSUaWVi7WSqc7hCfva",Dj=m(b(R)),S="https://api.sigmaidentity.com/v1",F=2147483647,k="m/424150'/0'/0'",Y=`m/424150'/${F}'/${F}'`;import{BSM as E,Utils as fj,ECIES as Uj,Hash as f,PublicKey as H,BigNumber as n,HD as Mj}from"@bsv/sdk";var G={getRandomBytes(j=32){if(typeof globalThis<"u"&&globalThis.crypto&&globalThis.crypto.getRandomValues){let $=new Uint8Array(j);return globalThis.crypto.getRandomValues($),$}throw Error("Secure random number generation not available. crypto.getRandomValues() is required for cryptographic operations. This environment may not be suitable for secure key generation.")},getRandomString(j=32){let $=this.getRandomBytes(j);return Array.from($,(J)=>J.toString(16).padStart(2,"0")).join("")},getSigningPathFromHex(j,$=!0){let J="m",q=j.match(/.{1,8}/g);if(!q)throw Error("Invalid hex string");let z=2147483647;for(let Q of q){let W=Number(`0x${Q}`);if(W>z)W-=z;J+=`/${W}${$?"'":""}`}return J},getNextIdentityPath(j){let $=j.split("/"),J=$[$.length-2],q=!1;if(J.match("'"))q=!0;let z=(Number(J.replace(/[^0-9]/g,""))+1).toString();return $[$.length-2]=z+(q?"'":""),$[$.length-1]=`0${q?"'":""}`,$.join("/")},getNextPath(j){let $=j.split("/"),J=$[$.length-1],q=!1;if(J.match("'"))q=!0;let z=(Number(J.replace(/[^0-9]/g,""))+1).toString();return $[$.length-1]=z+(q?"'":""),$.join("/")}};import{BSM as g,PublicKey as zj,PrivateKey as I,BigNumber as Qj,Hash as Zj,Utils as Wj,ECIES as Lj}from"@bsv/sdk";import{ECIES as e,Utils as t,OP as h,PublicKey as o}from"@bsv/sdk";var{toArray:M,toUTF8:jj,toBase64:$j}=t,{electrumDecrypt:Jj,electrumEncrypt:qj}=e;class x{identityAttributes={};encrypt(j,$){let{privKey:J,pubKey:q}=this.getEncryptionKey(),z=$?o.fromString($):q;return $j(qj(M(j),z,J))}decrypt(j,$){let{privKey:J}=this.getEncryptionKey(),q;if($)q=o.fromString($);return jj(Jj(M(j,"base64"),J,q))}signOpReturnWithAIP(j,$){let J=this.getAIPMessageBuffer(j),{address:q,signature:z}=this.signMessage(J.flat(),$);return this.formatAIPOutput(J,q,z)}getAttributes(){return this.identityAttributes}getAttribute(j){if(this.identityAttributes[j])return this.identityAttributes[j];return null}setAttribute(j,$){if(!$)return;if(this.identityAttributes[j])this.updateExistingAttribute(j,$);else this.createNewAttribute(j,$)}unsetAttribute(j){delete this.identityAttributes[j]}addAttribute(j,$,J=""){let q=J;if(!J)q=G.getRandomString();this.identityAttributes[j]={value:$,nonce:q}}getAttributeUrns(){let j="";for(let $ in this.identityAttributes){let J=this.getAttributeUrn($);if(J)j+=`${J}
3
3
  `}return j}getAttributeUrn(j){let $=this.identityAttributes[j];if($)return`urn:bap:id:${j}:${$.value}:${$.nonce}`;return null}parseStringUrns(j){let $={},J=j.replace(/^\s+/g,"").replace(/\r/gm,"").split(`
4
- `);for(let q of J){let Q=q.replace(/^\s+/g,"").replace(/\s+$/g,"").split(":");if(Q[0]==="urn"&&Q[1]==="bap"&&Q[2]==="id"&&Q[3]&&Q[4]&&Q[5])$[Q[3]]={value:Q[4],nonce:Q[5]}}return $}parseAttributes(j){if(typeof j==="string")return this.parseStringUrns(j);for(let $ in j)if(!j[$].value||!j[$].nonce)throw new Error("Invalid identity attribute");return j||{}}updateExistingAttribute(j,$){if(typeof $==="string"){this.identityAttributes[j].value=$;return}if(this.identityAttributes[j].value=$.value||"",$.nonce)this.identityAttributes[j].nonce=$.nonce}createNewAttribute(j,$){if(typeof $==="string"){this.addAttribute(j,$);return}this.addAttribute(j,$.value||"",$.nonce)}getAIPMessageBuffer(j,$){let J=j.findIndex((z)=>z[0]===h.OP_RETURN),q=[];if(J===-1)q.push([h.OP_RETURN]),J=0;if($)for(let z of $)q.push(j[J+z]);else for(let z of j)q.push(z);return q}formatAIPOutput(j,$,J){let q=[M("|"),M(R),M("BITCOIN_ECDSA"),M($),M(J,"base64")];return[...j,...q]}}var{magicHash:zj}=g;class O extends x{key;idName;description;address;identityKey;constructor(j,$={}){super();this.key=j,this.address=j.toAddress(),this.idName="Member ID 1",this.description="",this.identityKey="",this.identityAttributes=this.parseAttributes($)}signMessage(j,$){let J=this.key,q=J.toAddress(),z=g.sign(j,J,"raw"),Q=new qj(zj(j)),W=z.CalculateRecoveryFactor(J.toPublicKey(),Q),L=g.sign(j,J,"raw").toCompact(W,!0,"base64");return{address:q,signature:L}}signOpReturnWithAIP(j){let $=this.getAIPMessageBuffer(j),{address:J,signature:q}=this.signMessage($.flat());return this.formatAIPOutput($,J,q)}getPublicKey(){return this.key.toPublicKey().toString()}import(j){this.idName=j.name,this.description=j.description,this.key=I.fromWif(j.derivedPrivateKey),this.address=this.key.toAddress(),this.identityAttributes=j.identityAttributes||{},this.identityKey=j.identityKey}static fromMemberIdentity(j){let $=new O(I.fromWif(j.derivedPrivateKey));return $.import(j),$}static fromBackup(j){let $=new O(I.fromWif(j.wif)),J=JSON.parse($.decrypt(j.id));return $.import(J),$}export(){return{name:this.idName,description:this.description,derivedPrivateKey:this.key.toWif(),address:this.address,identityAttributes:this.getAttributes(),identityKey:this.identityKey}}getEncryptionKey(){return{privKey:this.key.deriveChild(this.key.toPublicKey(),Y),pubKey:this.key.deriveChild(this.key.toPublicKey(),Y).toPublicKey()}}getEncryptionPublicKey(){let{pubKey:j}=this.getEncryptionKey();return j.toString()}exportForBackup(j){let $=this.export(),J=this.encrypt(JSON.stringify($));return{wif:this.key.toWif(),id:J,...j&&{label:j},createdAt:new Date().toISOString()}}}var{toArray:X,toHex:V,toBase58:Lj,toUTF8:n,toBase64:v}=Qj,{electrumDecrypt:u,electrumEncrypt:A}=Zj,{magicHash:d}=E;class f extends x{#$;#j;#J;#Q=S;#W="";#q;#Z;#z;#L;idName;description;rootAddress;identityKey;identityAttributes;getApiData;constructor(j,$={},J=""){super();if(j instanceof Wj)if(this.#J=!1,J){let z=V(U.sha256(J,"utf8")),Q=G.getSigningPathFromHex(z);this.#$=j.derive(Q)}else this.#$=j;else if(this.#J=!0,this.#j=j.rootPk,J){let z=V(U.sha256(J,"utf8"));this.#j=this.#j.deriveChild(this.#j.toPublicKey(),z)}if(this.#L=J,this.idName="ID 1",this.description="",this.#q=`${k}/0/0/0`,this.#Z=`${k}/0/0/0`,this.#z=`${k}/0/0/1`,this.#J){if(!this.#j)throw new Error("Master private key not initialized");let z=this.#j.deriveChild(this.#j.toPublicKey(),this.#q);this.rootAddress=z.toPublicKey().toAddress()}else{if(!this.#$)throw new Error("HD private key not initialized");let z=this.#$.derive(this.#q);this.rootAddress=z.privKey.toPublicKey().toAddress()}this.identityKey=this.deriveIdentityKey(this.rootAddress);let q={...$};this.identityAttributes=this.parseAttributes(q),this.getApiData=T(this.#Q,this.#W)}set BAP_SERVER(j){this.#Q=j}get BAP_SERVER(){return this.#Q}set BAP_TOKEN(j){this.#W=j}get BAP_TOKEN(){return this.#W}deriveIdentityKey(j){let $=V(U.sha256(j,"utf8"));return Lj(U.ripemd160($,"hex"))}parseAttributes(j){if(typeof j==="string")return this.parseStringUrns(j);for(let $ in j)if(!j[$].value||!j[$].nonce)throw new Error("Invalid identity attribute");return j||{}}parseStringUrns(j){let $={},J=j.replace(/^\s+/g,"").replace(/\r/gm,"").split(`
5
- `);for(let q of J){let Q=q.replace(/^\s+/g,"").replace(/\s+$/g,"").split(":");if(Q[0]==="urn"&&Q[1]==="bap"&&Q[2]==="id"&&Q[3]&&Q[4]&&Q[5])$[Q[3]]={value:Q[4],nonce:Q[5]}}return $}getIdentityKey(){return this.identityKey}set rootPath(j){if(this.#J){if(this.#q=j,!this.#j)throw new Error("Master private key not initialized");let $=this.#j.deriveChild(this.#j.toPublicKey(),j);this.rootAddress=$.toPublicKey().toAddress(),this.#Z=j,this.#z=j}else{let $=j;if(j.split("/").length<5)$=`${k}${j}`;if(!this.validatePath($))throw new Error(`invalid signing path given ${$}`);if(this.#q=$,!this.#$)throw new Error("HD private key not initialized");let J=this.#$.derive($);this.rootAddress=J.pubKey.toAddress(),this.#Z=$,this.#z=$}this.identityKey=this.deriveIdentityKey(this.rootAddress)}get rootPath(){return this.#q}getRootPath(){return this.#q}set currentPath(j){if(this.#J)this.#Z=this.#z,this.#z=j;else{let $=j;if(j.split("/").length<5)$=`${k}${j}`;if(!this.validatePath($))throw new Error("invalid signing path given");this.#Z=this.#z,this.#z=$}}get currentPath(){return this.#z}get previousPath(){return this.#Z}get idSeed(){return this.#L}incrementPath(){this.currentPath=G.getNextPath(this.currentPath)}validatePath(j){if(j.match(/\/[0-9]{1,10}'?\/[0-9]{1,10}'?\/[0-9]{1,10}'?\/[0-9]{1,10}'?\/[0-9]{1,10}'?\/[0-9]{1,10}'?/)){let $=j.split("/");if($.length===7&&Number($[1].replace("'",""))<=F&&Number($[2].replace("'",""))<=F&&Number($[3].replace("'",""))<=F&&Number($[4].replace("'",""))<=F&&Number($[5].replace("'",""))<=F&&Number($[6].replace("'",""))<=F)return!0}return!1}getInitialIdTransaction(){return this.getIdTransaction(this.#q)}getIdTransaction(j=""){if(this.#z===this.#q)throw new Error("Current path equals rootPath. ID was probably not initialized properly");let $=[X(C),X("ID"),X(this.identityKey),X(this.getCurrentAddress())];return this.signOpReturnWithAIP($,j||this.#Z)}getAddress(j){if(this.#J){if(!this.#j)throw new Error("Master private key not initialized");return this.#j.deriveChild(this.#j.toPublicKey(),j).toPublicKey().toAddress()}if(!this.#$)throw new Error("HD private key not initialized");return this.#$.derive(j).privKey.toPublicKey().toAddress()}getCurrentAddress(){return this.getAddress(this.#z)}getEncryptionKey(){if(this.#J){if(!this.#j)throw new Error("Master private key not initialized");let J=this.#j.deriveChild(this.#j.toPublicKey(),this.#q),q=J.deriveChild(J.toPublicKey(),Y);return{privKey:q,pubKey:q.toPublicKey()}}if(!this.#$)throw new Error("HD private key not initialized");let $=this.#$.derive(this.#q).derive(Y).privKey;return{privKey:$,pubKey:$.toPublicKey()}}getEncryptionKeyType42(){if(this.#J)return this.getEncryptionKey();if(!this.#$)throw new Error("HD private key not initialized");let j=this.#$.derive(this.#q),$=j.privKey.deriveChild(j.toPublic().pubKey,Y);return{privKey:$,pubKey:$.toPublicKey()}}getEncryptionPublicKey(){let{pubKey:j}=this.getEncryptionKey();return j.toString()}getEncryptionPublicKeyWithSeed(j){return this.getEncryptionPrivateKeyWithSeed(j).toPublicKey().toString()}encrypt(j,$){let{privKey:J,pubKey:q}=this.getEncryptionKey(),z=$?H.fromString($):q;return v(A(X(j),z,J))}decrypt(j,$){let{privKey:J}=this.getEncryptionKey(),q;if($)q=H.fromString($);return n(u(X(j,"base64"),J,q))}encryptWithSeed(j,$,J){let q=this.getEncryptionPrivateKeyWithSeed($),z=q.toPublicKey(),Q=J?H.fromString(J):z;return v(A(X(j),Q,q))}decryptWithSeed(j,$,J){let q=this.getEncryptionPrivateKeyWithSeed($),z;if(J)z=H.fromString(J);return n(u(X(j,"base64"),q,z))}getEncryptionPrivateKeyWithSeed(j){let $=V(U.sha256(j,"utf8"));if(this.#J){if(!this.#j)throw new Error("Master private key not initialized");let z=this.#j.deriveChild(this.#j.toPublicKey(),this.#q);return z.deriveChild(z.toPublicKey(),$)}if(!this.#$)throw new Error("HD private key not initialized");let J=G.getSigningPathFromHex($);return this.#$.derive(this.#q).derive(J).privKey}getAttestation(j){let $=U.sha256(j,"utf8");return`bap:attest:${V($)}:${this.getIdentityKey()}`}getAttestationHash(j){let $=this.getAttributeUrn(j);if(!$)return null;let J=this.getAttestation($),q=U.sha256(J,"utf8");return V(q)}signMessage(j,$){let J=$||this.#z,q;if(this.#J){if(!this.#j)throw new Error("Master private key not initialized");q=this.#j.deriveChild(this.#j.toPublicKey(),J)}else{if(!this.#$)throw new Error("HD private key not initialized");q=this.#$.derive(J).privKey}let z=q.toAddress(),Q=E.sign(j,q,"raw"),W=new o(d(j)),L=Q.CalculateRecoveryFactor(q.toPublicKey(),W),w=E.sign(j,q,"raw").toCompact(L,!0,"base64");return{address:z,signature:w}}signMessageWithSeed(j,$){let J=V(U.sha256($,"utf8")),q;if(this.#J){if(!this.#j)throw new Error("Master private key not initialized");let N=this.#j.deriveChild(this.#j.toPublicKey(),this.#q);q=N.deriveChild(N.toPublicKey(),J)}else{if(!this.#$)throw new Error("HD private key not initialized");let N=G.getSigningPathFromHex(J);q=this.#$.derive(this.#q).derive(N).privKey}let z=q.toPublicKey().toAddress(),Q=X(j,"utf8"),W=E.sign(Q,q,"raw"),L=new o(d(Q)),w=W.CalculateRecoveryFactor(q.toPublicKey(),L),B=E.sign(Q,q,"raw").toCompact(w,!0,"base64");return{address:z,signature:B}}signOpReturnWithAIP(j,$=""){let J=this.getAIPMessageBuffer(j),{address:q,signature:z}=this.signMessage(J.flat(),$);return this.formatAIPOutput(j,q,z)}async getIdSigningKeys(){let j=await this.getApiData("/signing-keys",{idKey:this.identityKey});return console.log("getIdSigningKeys",j),j}async getAttributeAttestations(j){let $=this.getAttestationHash(j),J=await this.getApiData("/attestation/get",{hash:$});return console.log("getAttestations",j,$,J),J}import(j){this.idName=j.name,this.description=j.description||"",this.identityKey=j.identityKey,this.#q=j.rootPath,this.rootAddress=j.rootAddress,this.#Z=j.previousPath,this.#z=j.currentPath,this.#L=("idSeed"in j?j.idSeed:"")||"",this.identityAttributes=this.parseAttributes(j.identityAttributes)}export(){return{name:this.idName,description:this.description,identityKey:this.identityKey,rootPath:this.#q,rootAddress:this.rootAddress,previousPath:this.#Z,currentPath:this.#z,idSeed:this.#L,identityAttributes:this.getAttributes(),lastIdPath:""}}exportMemberBackup(){let j;if(this.#J){if(!this.#j)throw new Error("Master private key not initialized");j=this.#j.deriveChild(this.#j.toPublicKey(),this.#z)}else{if(!this.#$)throw new Error("HD private key not initialized");j=this.#$.derive(this.#z).privKey}return{name:this.idName,description:this.description,derivedPrivateKey:j.toWif(),address:j.toPublicKey().toAddress(),identityAttributes:this.getAttributes(),identityKey:this.identityKey}}newId(){this.incrementPath();let j;if(this.#J){if(!this.#j)throw new Error("Master private key not initialized");j=this.#j.deriveChild(this.#j.toPublicKey(),this.#z)}else{if(!this.#$)throw new Error("HD private key not initialized");j=this.#$.derive(this.#z).privKey}return new O(j)}exportMember(){let j=this.exportMemberBackup(),$;if(this.#J){if(!this.#j)throw new Error("Master private key not initialized");$=this.#j.deriveChild(this.#j.toPublicKey(),this.#z)}else{if(!this.#$)throw new Error("HD private key not initialized");$=this.#$.derive(this.#z).privKey}let J=v(A(X(JSON.stringify(j)),$.toPublicKey()));return{wif:j.derivedPrivateKey,encryptedData:J}}}var{toArray:Z,toUTF8:_,toBase64:c,toHex:D}=Cj,{electrumEncrypt:y,electrumDecrypt:s}=Yj;class Uj{#$;#j;#J;#Q={};#W=S;#q="";#Z="";#z=0;getApiData;constructor(j,$="",J=""){if(!j)throw new Error("No key source given");if(typeof j==="string")this.#$=Gj.fromString(j),this.#J=!1;else this.#j=Fj.fromWif(j.rootPk),this.#J=!0;if($)this.#q=$;if(J)this.#W=J;this.getApiData=T(this.#W,this.#q)}get lastIdPath(){return this.#Z}getPublicKey(j=""){if(this.#J){if(!this.#j)throw new Error("Master private key not initialized");if(j)return this.#j.deriveChild(this.#j.toPublicKey(),j).toPublicKey().toString();return this.#j.toPublicKey().toString()}if(!this.#$)throw new Error("HD private key not initialized");if(j)return this.#$.derive(j).pubKey.toString();return this.#$.pubKey.toString()}getHdPublicKey(j=""){if(this.#J)throw new Error("HD public keys are not available in Type 42 mode");if(!this.#$)throw new Error("HD private key not initialized");if(j)return this.#$.derive(j).toPublic().toString();return this.#$.toPublic().toString()}set BAP_SERVER(j){this.#W=j;for(let $ in this.#Q)this.#Q[$].BAP_SERVER=j}get BAP_SERVER(){return this.#W}set BAP_TOKEN(j){this.#q=j;for(let $ in this.#Q)this.#Q[$].BAP_TOKEN=j}get BAP_TOKEN(){return this.#q}checkIdBelongs(j){let $;if(this.#J){if(!this.#j)throw new Error("Master private key not initialized");$=this.#j.deriveChild(this.#j.toPublicKey(),j.rootPath).toPublicKey().toAddress()}else{if(!this.#$)throw new Error("HD private key not initialized");$=this.#$.derive(j.rootPath).pubKey.toAddress()}if($!==j.rootAddress)throw new Error("ID does not belong to this private key");return!0}listIds(){return Object.keys(this.#Q)}newId(j,$,J={},q=""){let z,Q,W;if(typeof j==="object"||j===void 0||typeof j==="string"&&j.startsWith("/"))Q=typeof j==="string"?j:void 0,W=typeof j==="object"?j:typeof $==="object"?$:{},z="Default Identity";else z=j,Q=typeof $==="string"?$:void 0,W=typeof $==="object"?$:J;let L;if(Q)L=Q;else if(this.#J)L=`bap:${this.#z}`,this.#z++;else L=this.getNextValidPath();let w;if(this.#J){if(!this.#j)throw new Error("Type 42 parameters not initialized");w=new f({rootPk:this.#j},W,q)}else{if(!this.#$)throw new Error("HD private key not initialized");w=new f(this.#$,W,q)}if(w.BAP_SERVER=this.#W,w.BAP_TOKEN=this.#q,w.idName=z,w.rootPath=L,this.#J)w.currentPath=L;else w.currentPath=G.getNextPath(L);let B=w.getIdentityKey();return this.#Q[B]=w,this.#Z=L,this.#Q[B]}removeId(j){delete this.#Q[j]}getNextValidPath(){if(this.#Z)return G.getNextIdentityPath(this.#Z);return`/0'/${Object.keys(this.#Q).length}'/0'`}newIdWithCounter(j,$=`Identity ${j}`){if(!this.#J)throw new Error("newIdWithCounter only works in Type 42 mode");let J=`bap:${j}`;return this.newId($,J)}getId(j){return this.#Q[j]||null}setId(j){this.checkIdBelongs(j),this.#Q[j.getIdentityKey()]=j}importIds(j,$=!0){if($&&typeof j==="string"){this.importEncryptedIds(j);return}let J=j;if(!J.lastIdPath)throw new Error("ID cannot be imported as it is not complete");if(!J.ids)throw new Error(`ID data is not in the correct format: ${j}`);let q=j.lastIdPath;for(let z of J.ids){if(!z.identityKey||!z.identityAttributes||!z.rootAddress)throw new Error("ID cannot be imported as it is not complete");let Q;if(this.#J){if(!this.#j)throw new Error("Type 42 parameters not initialized");Q=new f({rootPk:this.#j},{},z.idSeed)}else{if(!this.#$)throw new Error("HD private key not initialized");Q=new f(this.#$,{},z.idSeed)}if(Q.BAP_SERVER=this.#W,Q.BAP_TOKEN=this.#q,Q.import(z),q==="")q=Q.currentPath;if(this.checkIdBelongs(Q),this.#Q[Q.getIdentityKey()]=Q,this.#J&&Q.rootPath.startsWith("bap:")){let W=Q.rootPath.split(":");if(W.length>=2){let L=Number.parseInt(W[1],10);if(!Number.isNaN(L))this.#z=Math.max(this.#z,L+1)}}}this.#Z=q}importEncryptedIds(j){let $=this.decrypt(j),J=JSON.parse($);if(Array.isArray(J)){console.log(`Importing old format:
6
- `,J),this.importOldIds(J);return}if(typeof J!=="object")throw new Error("decrypted, but found unrecognized identities format");this.importIds(J,!1)}importOldIds(j){for(let $ of j){let J;if(this.#J){if(!this.#j)throw new Error("Type 42 parameters not initialized");J=new f({rootPk:this.#j},{},$.idSeed??"")}else{if(!this.#$)throw new Error("HD private key not initialized");J=new f(this.#$,{},$.idSeed??"")}J.BAP_SERVER=this.#W,J.BAP_TOKEN=this.#q,J.import($),this.checkIdBelongs(J),this.#Q[J.getIdentityKey()]=J,this.#Z=J.currentPath}}exportIds(j,$=!0){let J={lastIdPath:this.#Z,ids:[]},q=j||Object.keys(this.#Q);for(let z of q){if(!this.#Q[z])throw new Error(`Identity ${z} not found`);J.ids.push(this.#Q[z].export())}if($)return this.encrypt(JSON.stringify(J));return J}exportId(j,$=!0){let J={lastIdPath:this.#Z,ids:[]};if(J.ids.push(this.#Q[j].export()),$)return this.encrypt(JSON.stringify(J));return J}encrypt(j){if(this.#J){if(!this.#j)throw new Error("Master private key not initialized");let J=this.#j.deriveChild(this.#j.toPublicKey(),Y);return c(y(Z(j),J.toPublicKey(),null))}if(!this.#$)throw new Error("HD private key not initialized");let $=this.#$.derive(Y);return c(y(Z(j),$.pubKey,null))}decrypt(j){if(this.#J){if(!this.#j)throw new Error("Master private key not initialized");let J=this.#j.deriveChild(this.#j.toPublicKey(),Y);return _(s(Z(j,"base64"),J))}if(!this.#$)throw new Error("HD private key not initialized");let $=this.#$.derive(Y);return _(s(Z(j,"base64"),$.privKey))}signAttestationWithAIP(j,$,J=0,q=""){let z=this.getId($);if(!z)throw new Error("Could not find identity to attest with");let Q=this.getAttestationBuffer(j,J,q),{address:W,signature:L}=z.signMessage(Q);return this.createAttestationTransaction(j,J,W,L,q)}verifyAttestationWithAIP(j){if(!j.every((q)=>Array.isArray(q))||j[0][0]!==K.OP_RETURN||D(j[1])!==p)throw new Error("Not a valid BAP transaction");let $=D(j[7])==="44415441"?5:0,J={type:_(j[2]),hash:D(j[3]),sequence:_(j[4]),signingProtocol:_(j[7+$]),signingAddress:_(j[8+$]),signature:c(j[9+$])};if($&&j[3]===j[8])J.data=D(j[9]);console.log({attestation:J});try{let q=[];for(let z=0;z<6+$;z++)q.push(j[z]);J.verified=this.verifySignature(q.flat(),J.signingAddress,J.signature)}catch{J.verified=!1}return J}createAttestationTransaction(j,$,J,q,z=""){let Q=[[K.OP_RETURN],Z(C),Z("ATTEST"),Z(j),Z(`${$}`),Z("|")];if(z)Q.push(Z(C),Z("DATA"),Z(j),Z(z),Z("|"));return Q.push(Z(R),Z("BITCOIN_ECDSA"),Z(J),Z(q,"base64")),console.log({elements:Q}),Q}getAttestationBuffer(j,$=0,J=""){let q=[[K.OP_RETURN],Z(C),Z("ATTEST"),Z(j),Z(`${$}`),Z("|")];if(J)q.push(Z(C),Z("DATA"),Z(j),Z(J),Z("|"));return q.flat()}verifySignature(j,$,J){let q;if(Array.isArray(j))q=j;else if(Buffer.isBuffer(j))q=[...j];else q=Z(j,"utf8");let z=Xj.fromCompact(J,"base64"),Q;for(let W=0;W<4;W++)try{if(Q=z.RecoverPublicKey(W,new wj(l.magicHash(q))),l.verify(q,z,Q)&&Q.toAddress()===$)return!0}catch{}return!1}async verifyChallengeSignature(j,$,J,q){if(!this.verifySignature(J,$,q))return!1;try{let Q=await this.getApiData("/attestation/valid",{idKey:j,address:$,challenge:J,signature:q});if(Q?.status==="success"&&Q?.result?.valid===!0)return!0;return!1}catch(Q){return console.error("API call failed:",Q),!1}}async isValidAttestationTransaction(j){if(this.verifyAttestationWithAIP(j))return this.getApiData("/attestation/valid",{tx:j});return!1}async getIdentityFromAddress(j){return this.getApiData("/identity/from-address",{address:j})}async getIdentity(j){return this.getApiData("/identity/get",{idKey:j})}async getAttestationsForHash(j){return this.getApiData("/attestations",{hash:j})}exportForBackup(j,$,J){let z={ids:this.exportIds(),...j&&{label:j},createdAt:new Date().toISOString()};if(this.#J){if(!this.#j)throw new Error("Type 42 parameters not initialized");return{...z,rootPk:this.#j.toWif()}}if(!this.#$)throw new Error("HD private key not initialized");return{...z,xprv:$||this.#$.toString(),mnemonic:J||""}}exportMemberForBackup(j,$){let J=this.#Q[j];if(!J)throw new Error(`Identity ${j} not found`);let q=J.exportMember();return{wif:q.wif,id:q.encryptedData,...$&&{label:$},createdAt:new Date().toISOString()}}}export{O as MemberID,f as MasterID,Uj as BAP};
4
+ `);for(let q of J){let Q=q.replace(/^\s+/g,"").replace(/\s+$/g,"").split(":");if(Q[0]==="urn"&&Q[1]==="bap"&&Q[2]==="id"&&Q[3]&&Q[4]&&Q[5])$[Q[3]]={value:Q[4],nonce:Q[5]}}return $}parseAttributes(j){if(typeof j==="string")return this.parseStringUrns(j);for(let $ in j)if(!j[$].value||!j[$].nonce)throw Error("Invalid identity attribute");return j||{}}updateExistingAttribute(j,$){if(typeof $==="string"){this.identityAttributes[j].value=$;return}if(this.identityAttributes[j].value=$.value||"",$.nonce)this.identityAttributes[j].nonce=$.nonce}createNewAttribute(j,$){if(typeof $==="string"){this.addAttribute(j,$);return}this.addAttribute(j,$.value||"",$.nonce)}getAIPMessageBuffer(j,$){let J=j.findIndex((z)=>z[0]===h.OP_RETURN),q=[];if(J===-1)q.push([h.OP_RETURN]),J=0;if($)for(let z of $)q.push(j[J+z]);else for(let z of j)q.push(z);return q}formatAIPOutput(j,$,J){let q=[M("|"),M(R),M("BITCOIN_ECDSA"),M($),M(J,"base64")];return[...j,...q]}}var{magicHash:wj}=g,{toArray:P,toUTF8:Yj,toBase64:Gj,toHex:Xj}=Wj,{electrumDecrypt:Fj,electrumEncrypt:Cj}=Lj;class O extends x{key;idName;description;address;identityKey;constructor(j,$={}){super();this.key=j,this.address=j.toAddress(),this.idName="Member ID 1",this.description="",this.identityKey="",this.identityAttributes=this.parseAttributes($)}signMessage(j,$){let J=this.key,q=J.toAddress(),z=g.sign(j,J,"raw"),Q=new Qj(wj(j)),W=z.CalculateRecoveryFactor(J.toPublicKey(),Q),L=g.sign(j,J,"raw").toCompact(W,!0,"base64");return{address:q,signature:L}}signOpReturnWithAIP(j){let $=this.getAIPMessageBuffer(j),{address:J,signature:q}=this.signMessage($.flat());return this.formatAIPOutput($,J,q)}getPublicKey(){return this.key.toPublicKey().toString()}import(j){this.idName=j.name,this.description=j.description,this.key=I.fromWif(j.derivedPrivateKey),this.address=this.key.toAddress(),this.identityAttributes=j.identityAttributes||{},this.identityKey=j.identityKey}static fromMemberIdentity(j){let $=new O(I.fromWif(j.derivedPrivateKey));return $.import(j),$}static fromBackup(j){let $=new O(I.fromWif(j.wif)),J=JSON.parse($.decrypt(j.id));return $.import(J),$}export(){return{name:this.idName,description:this.description,derivedPrivateKey:this.key.toWif(),address:this.address,identityAttributes:this.getAttributes(),identityKey:this.identityKey}}getEncryptionKey(){return{privKey:this.key.deriveChild(this.key.toPublicKey(),Y),pubKey:this.key.deriveChild(this.key.toPublicKey(),Y).toPublicKey()}}getEncryptionPublicKey(){let{pubKey:j}=this.getEncryptionKey();return j.toString()}getEncryptionPrivateKeyWithSeed(j){let $=Xj(Zj.sha256(j,"utf8"));return this.key.deriveChild(this.key.toPublicKey(),$)}getEncryptionKeyWithSeed(j){let $=this.getEncryptionPrivateKeyWithSeed(j);return{privKey:$,pubKey:$.toPublicKey()}}getEncryptionPublicKeyWithSeed(j){return this.getEncryptionPrivateKeyWithSeed(j).toPublicKey().toString()}encryptWithSeed(j,$,J){let q=this.getEncryptionPrivateKeyWithSeed($),z=q.toPublicKey(),Q=this.key.toPublicKey().constructor,W=J?Q.fromString(J):z;return Gj(Cj(P(j),W,q))}decryptWithSeed(j,$,J){let q=this.getEncryptionPrivateKeyWithSeed($),z;if(J)z=zj.fromString(J);return Yj(Fj(P(j,"base64"),q,z))}exportForBackup(j){let $=this.export(),J=this.encrypt(JSON.stringify($));return{wif:this.key.toWif(),id:J,...j&&{label:j},createdAt:new Date().toISOString()}}}var{toArray:X,toHex:V,toBase58:Vj,toUTF8:u,toBase64:v}=fj,{electrumDecrypt:d,electrumEncrypt:A}=Uj,{magicHash:y}=E;class U extends x{#$;#j;#J;#Q=S;#W="";#q;#Z;#z;#L;idName;description;rootAddress;identityKey;identityAttributes;getApiData;constructor(j,$={},J=""){super();if(j instanceof Mj)if(this.#J=!1,J){let z=V(f.sha256(J,"utf8")),Q=G.getSigningPathFromHex(z);this.#$=j.derive(Q)}else this.#$=j;else if(this.#J=!0,this.#j=j.rootPk,J){let z=V(f.sha256(J,"utf8"));this.#j=this.#j.deriveChild(this.#j.toPublicKey(),z)}if(this.#L=J,this.idName="ID 1",this.description="",this.#q=`${k}/0/0/0`,this.#Z=`${k}/0/0/0`,this.#z=`${k}/0/0/1`,this.#J){if(!this.#j)throw Error("Master private key not initialized");let z=this.#j.deriveChild(this.#j.toPublicKey(),this.#q);this.rootAddress=z.toPublicKey().toAddress()}else{if(!this.#$)throw Error("HD private key not initialized");let z=this.#$.derive(this.#q);this.rootAddress=z.privKey.toPublicKey().toAddress()}this.identityKey=this.deriveIdentityKey(this.rootAddress);let q={...$};this.identityAttributes=this.parseAttributes(q),this.getApiData=T(this.#Q,this.#W)}set BAP_SERVER(j){this.#Q=j}get BAP_SERVER(){return this.#Q}set BAP_TOKEN(j){this.#W=j}get BAP_TOKEN(){return this.#W}deriveIdentityKey(j){let $=V(f.sha256(j,"utf8"));return Vj(f.ripemd160($,"hex"))}parseAttributes(j){if(typeof j==="string")return this.parseStringUrns(j);for(let $ in j)if(!j[$].value||!j[$].nonce)throw Error("Invalid identity attribute");return j||{}}parseStringUrns(j){let $={},J=j.replace(/^\s+/g,"").replace(/\r/gm,"").split(`
5
+ `);for(let q of J){let Q=q.replace(/^\s+/g,"").replace(/\s+$/g,"").split(":");if(Q[0]==="urn"&&Q[1]==="bap"&&Q[2]==="id"&&Q[3]&&Q[4]&&Q[5])$[Q[3]]={value:Q[4],nonce:Q[5]}}return $}getIdentityKey(){return this.identityKey}set rootPath(j){if(this.#J){if(this.#q=j,!this.#j)throw Error("Master private key not initialized");let $=this.#j.deriveChild(this.#j.toPublicKey(),j);this.rootAddress=$.toPublicKey().toAddress(),this.#Z=j,this.#z=j}else{let $=j;if(j.split("/").length<5)$=`${k}${j}`;if(!this.validatePath($))throw Error(`invalid signing path given ${$}`);if(this.#q=$,!this.#$)throw Error("HD private key not initialized");let J=this.#$.derive($);this.rootAddress=J.pubKey.toAddress(),this.#Z=$,this.#z=$}this.identityKey=this.deriveIdentityKey(this.rootAddress)}get rootPath(){return this.#q}getRootPath(){return this.#q}set currentPath(j){if(this.#J)this.#Z=this.#z,this.#z=j;else{let $=j;if(j.split("/").length<5)$=`${k}${j}`;if(!this.validatePath($))throw Error("invalid signing path given");this.#Z=this.#z,this.#z=$}}get currentPath(){return this.#z}get previousPath(){return this.#Z}get idSeed(){return this.#L}incrementPath(){this.currentPath=G.getNextPath(this.currentPath)}validatePath(j){if(j.match(/\/[0-9]{1,10}'?\/[0-9]{1,10}'?\/[0-9]{1,10}'?\/[0-9]{1,10}'?\/[0-9]{1,10}'?\/[0-9]{1,10}'?/)){let $=j.split("/");if($.length===7&&Number($[1].replace("'",""))<=F&&Number($[2].replace("'",""))<=F&&Number($[3].replace("'",""))<=F&&Number($[4].replace("'",""))<=F&&Number($[5].replace("'",""))<=F&&Number($[6].replace("'",""))<=F)return!0}return!1}getInitialIdTransaction(){return this.getIdTransaction(this.#q)}getIdTransaction(j=""){if(this.#z===this.#q)throw Error("Current path equals rootPath. ID was probably not initialized properly");let $=[X(C),X("ID"),X(this.identityKey),X(this.getCurrentAddress())];return this.signOpReturnWithAIP($,j||this.#Z)}getAddress(j){if(this.#J){if(!this.#j)throw Error("Master private key not initialized");return this.#j.deriveChild(this.#j.toPublicKey(),j).toPublicKey().toAddress()}if(!this.#$)throw Error("HD private key not initialized");return this.#$.derive(j).privKey.toPublicKey().toAddress()}getCurrentAddress(){return this.getAddress(this.#z)}getEncryptionKey(){if(this.#J){if(!this.#j)throw Error("Master private key not initialized");let J=this.#j.deriveChild(this.#j.toPublicKey(),this.#q),q=J.deriveChild(J.toPublicKey(),Y);return{privKey:q,pubKey:q.toPublicKey()}}if(!this.#$)throw Error("HD private key not initialized");let $=this.#$.derive(this.#q).derive(Y).privKey;return{privKey:$,pubKey:$.toPublicKey()}}getEncryptionKeyType42(){if(this.#J)return this.getEncryptionKey();if(!this.#$)throw Error("HD private key not initialized");let j=this.#$.derive(this.#q),$=j.privKey.deriveChild(j.toPublic().pubKey,Y);return{privKey:$,pubKey:$.toPublicKey()}}getEncryptionPublicKey(){let{pubKey:j}=this.getEncryptionKey();return j.toString()}getEncryptionPublicKeyWithSeed(j){return this.getEncryptionPrivateKeyWithSeed(j).toPublicKey().toString()}encrypt(j,$){let{privKey:J,pubKey:q}=this.getEncryptionKey(),z=$?H.fromString($):q;return v(A(X(j),z,J))}decrypt(j,$){let{privKey:J}=this.getEncryptionKey(),q;if($)q=H.fromString($);return u(d(X(j,"base64"),J,q))}encryptWithSeed(j,$,J){let q=this.getEncryptionPrivateKeyWithSeed($),z=q.toPublicKey(),Q=J?H.fromString(J):z;return v(A(X(j),Q,q))}decryptWithSeed(j,$,J){let q=this.getEncryptionPrivateKeyWithSeed($),z;if(J)z=H.fromString(J);return u(d(X(j,"base64"),q,z))}getEncryptionPrivateKeyWithSeed(j){let $=V(f.sha256(j,"utf8"));if(this.#J){if(!this.#j)throw Error("Master private key not initialized");let z=this.#j.deriveChild(this.#j.toPublicKey(),this.#q);return z.deriveChild(z.toPublicKey(),$)}if(!this.#$)throw Error("HD private key not initialized");let J=G.getSigningPathFromHex($);return this.#$.derive(this.#q).derive(J).privKey}getAttestation(j){let $=f.sha256(j,"utf8");return`bap:attest:${V($)}:${this.getIdentityKey()}`}getAttestationHash(j){let $=this.getAttributeUrn(j);if(!$)return null;let J=this.getAttestation($),q=f.sha256(J,"utf8");return V(q)}signMessage(j,$){let J=$||this.#z,q;if(this.#J){if(!this.#j)throw Error("Master private key not initialized");q=this.#j.deriveChild(this.#j.toPublicKey(),J)}else{if(!this.#$)throw Error("HD private key not initialized");q=this.#$.derive(J).privKey}let z=q.toAddress(),Q=E.sign(j,q,"raw"),W=new n(y(j)),L=Q.CalculateRecoveryFactor(q.toPublicKey(),W),w=E.sign(j,q,"raw").toCompact(L,!0,"base64");return{address:z,signature:w}}signMessageWithSeed(j,$){let J=V(f.sha256($,"utf8")),q;if(this.#J){if(!this.#j)throw Error("Master private key not initialized");let N=this.#j.deriveChild(this.#j.toPublicKey(),this.#q);q=N.deriveChild(N.toPublicKey(),J)}else{if(!this.#$)throw Error("HD private key not initialized");let N=G.getSigningPathFromHex(J);q=this.#$.derive(this.#q).derive(N).privKey}let z=q.toPublicKey().toAddress(),Q=X(j,"utf8"),W=E.sign(Q,q,"raw"),L=new n(y(Q)),w=W.CalculateRecoveryFactor(q.toPublicKey(),L),B=E.sign(Q,q,"raw").toCompact(w,!0,"base64");return{address:z,signature:B}}signOpReturnWithAIP(j,$=""){let J=this.getAIPMessageBuffer(j),{address:q,signature:z}=this.signMessage(J.flat(),$);return this.formatAIPOutput(j,q,z)}async getIdSigningKeys(){let j=await this.getApiData("/signing-keys",{idKey:this.identityKey});return console.log("getIdSigningKeys",j),j}async getAttributeAttestations(j){let $=this.getAttestationHash(j),J=await this.getApiData("/attestation/get",{hash:$});return console.log("getAttestations",j,$,J),J}import(j){this.idName=j.name,this.description=j.description||"",this.identityKey=j.identityKey,this.#q=j.rootPath,this.rootAddress=j.rootAddress,this.#Z=j.previousPath,this.#z=j.currentPath,this.#L=("idSeed"in j?j.idSeed:"")||"",this.identityAttributes=this.parseAttributes(j.identityAttributes)}export(){return{name:this.idName,description:this.description,identityKey:this.identityKey,rootPath:this.#q,rootAddress:this.rootAddress,previousPath:this.#Z,currentPath:this.#z,idSeed:this.#L,identityAttributes:this.getAttributes(),lastIdPath:""}}exportMemberBackup(){let j;if(this.#J){if(!this.#j)throw Error("Master private key not initialized");j=this.#j.deriveChild(this.#j.toPublicKey(),this.#z)}else{if(!this.#$)throw Error("HD private key not initialized");j=this.#$.derive(this.#z).privKey}return{name:this.idName,description:this.description,derivedPrivateKey:j.toWif(),address:j.toPublicKey().toAddress(),identityAttributes:this.getAttributes(),identityKey:this.identityKey}}newId(){this.incrementPath();let j;if(this.#J){if(!this.#j)throw Error("Master private key not initialized");j=this.#j.deriveChild(this.#j.toPublicKey(),this.#z)}else{if(!this.#$)throw Error("HD private key not initialized");j=this.#$.derive(this.#z).privKey}return new O(j)}exportMember(){let j=this.exportMemberBackup(),$;if(this.#J){if(!this.#j)throw Error("Master private key not initialized");$=this.#j.deriveChild(this.#j.toPublicKey(),this.#z)}else{if(!this.#$)throw Error("HD private key not initialized");$=this.#$.derive(this.#z).privKey}let J=v(A(X(JSON.stringify(j)),$.toPublicKey()));return{wif:j.derivedPrivateKey,encryptedData:J}}}var{toArray:Z,toUTF8:_,toBase64:c,toHex:D}=Ej,{electrumEncrypt:s,electrumDecrypt:i}=Oj;class Bj{#$;#j;#J;#Q={};#W=S;#q="";#Z="";#z=0;getApiData;constructor(j,$="",J=""){if(!j)throw Error("No key source given");if(typeof j==="string")this.#$=_j.fromString(j),this.#J=!1;else this.#j=xj.fromWif(j.rootPk),this.#J=!0;if($)this.#q=$;if(J)this.#W=J;this.getApiData=T(this.#W,this.#q)}get lastIdPath(){return this.#Z}getPublicKey(j=""){if(this.#J){if(!this.#j)throw Error("Master private key not initialized");if(j)return this.#j.deriveChild(this.#j.toPublicKey(),j).toPublicKey().toString();return this.#j.toPublicKey().toString()}if(!this.#$)throw Error("HD private key not initialized");if(j)return this.#$.derive(j).pubKey.toString();return this.#$.pubKey.toString()}getHdPublicKey(j=""){if(this.#J)throw Error("HD public keys are not available in Type 42 mode");if(!this.#$)throw Error("HD private key not initialized");if(j)return this.#$.derive(j).toPublic().toString();return this.#$.toPublic().toString()}set BAP_SERVER(j){this.#W=j;for(let $ in this.#Q)this.#Q[$].BAP_SERVER=j}get BAP_SERVER(){return this.#W}set BAP_TOKEN(j){this.#q=j;for(let $ in this.#Q)this.#Q[$].BAP_TOKEN=j}get BAP_TOKEN(){return this.#q}checkIdBelongs(j){let $;if(this.#J){if(!this.#j)throw Error("Master private key not initialized");$=this.#j.deriveChild(this.#j.toPublicKey(),j.rootPath).toPublicKey().toAddress()}else{if(!this.#$)throw Error("HD private key not initialized");$=this.#$.derive(j.rootPath).pubKey.toAddress()}if($!==j.rootAddress)throw Error("ID does not belong to this private key");return!0}listIds(){return Object.keys(this.#Q)}newId(j,$,J={},q=""){let z,Q,W;if(typeof j==="object"||j===void 0||typeof j==="string"&&j.startsWith("/"))Q=typeof j==="string"?j:void 0,W=typeof j==="object"?j:typeof $==="object"?$:{},z="Default Identity";else z=j,Q=typeof $==="string"?$:void 0,W=typeof $==="object"?$:J;let L;if(Q)L=Q;else if(this.#J)L=`bap:${this.#z}`,this.#z++;else L=this.getNextValidPath();let w;if(this.#J){if(!this.#j)throw Error("Type 42 parameters not initialized");w=new U({rootPk:this.#j},W,q)}else{if(!this.#$)throw Error("HD private key not initialized");w=new U(this.#$,W,q)}if(w.BAP_SERVER=this.#W,w.BAP_TOKEN=this.#q,w.idName=z,w.rootPath=L,this.#J)w.currentPath=L;else w.currentPath=G.getNextPath(L);let B=w.getIdentityKey();return this.#Q[B]=w,this.#Z=L,this.#Q[B]}removeId(j){delete this.#Q[j]}getNextValidPath(){if(this.#Z)return G.getNextIdentityPath(this.#Z);return`/0'/${Object.keys(this.#Q).length}'/0'`}newIdWithCounter(j,$=`Identity ${j}`){if(!this.#J)throw Error("newIdWithCounter only works in Type 42 mode");let J=`bap:${j}`;return this.newId($,J)}getId(j){return this.#Q[j]||null}setId(j){this.checkIdBelongs(j),this.#Q[j.getIdentityKey()]=j}importIds(j,$=!0){if($&&typeof j==="string"){this.importEncryptedIds(j);return}let J=j;if(!J.lastIdPath)throw Error("ID cannot be imported as it is not complete");if(!J.ids)throw Error(`ID data is not in the correct format: ${j}`);let q=j.lastIdPath;for(let z of J.ids){if(!z.identityKey||!z.identityAttributes||!z.rootAddress)throw Error("ID cannot be imported as it is not complete");let Q;if(this.#J){if(!this.#j)throw Error("Type 42 parameters not initialized");Q=new U({rootPk:this.#j},{},z.idSeed)}else{if(!this.#$)throw Error("HD private key not initialized");Q=new U(this.#$,{},z.idSeed)}if(Q.BAP_SERVER=this.#W,Q.BAP_TOKEN=this.#q,Q.import(z),q==="")q=Q.currentPath;if(this.checkIdBelongs(Q),this.#Q[Q.getIdentityKey()]=Q,this.#J&&Q.rootPath.startsWith("bap:")){let W=Q.rootPath.split(":");if(W.length>=2){let L=Number.parseInt(W[1],10);if(!Number.isNaN(L))this.#z=Math.max(this.#z,L+1)}}}this.#Z=q}importEncryptedIds(j){let $=this.decrypt(j),J=JSON.parse($);if(Array.isArray(J)){console.log(`Importing old format:
6
+ `,J),this.importOldIds(J);return}if(typeof J!=="object")throw Error("decrypted, but found unrecognized identities format");this.importIds(J,!1)}importOldIds(j){for(let $ of j){let J;if(this.#J){if(!this.#j)throw Error("Type 42 parameters not initialized");J=new U({rootPk:this.#j},{},$.idSeed??"")}else{if(!this.#$)throw Error("HD private key not initialized");J=new U(this.#$,{},$.idSeed??"")}J.BAP_SERVER=this.#W,J.BAP_TOKEN=this.#q,J.import($),this.checkIdBelongs(J),this.#Q[J.getIdentityKey()]=J,this.#Z=J.currentPath}}exportIds(j,$=!0){let J={lastIdPath:this.#Z,ids:[]},q=j||Object.keys(this.#Q);for(let z of q){if(!this.#Q[z])throw Error(`Identity ${z} not found`);J.ids.push(this.#Q[z].export())}if($)return this.encrypt(JSON.stringify(J));return J}exportId(j,$=!0){let J={lastIdPath:this.#Z,ids:[]};if(J.ids.push(this.#Q[j].export()),$)return this.encrypt(JSON.stringify(J));return J}encrypt(j){if(this.#J){if(!this.#j)throw Error("Master private key not initialized");let J=this.#j.deriveChild(this.#j.toPublicKey(),Y);return c(s(Z(j),J.toPublicKey(),null))}if(!this.#$)throw Error("HD private key not initialized");let $=this.#$.derive(Y);return c(s(Z(j),$.pubKey,null))}decrypt(j){if(this.#J){if(!this.#j)throw Error("Master private key not initialized");let J=this.#j.deriveChild(this.#j.toPublicKey(),Y);return _(i(Z(j,"base64"),J))}if(!this.#$)throw Error("HD private key not initialized");let $=this.#$.derive(Y);return _(i(Z(j,"base64"),$.privKey))}signAttestationWithAIP(j,$,J=0,q=""){let z=this.getId($);if(!z)throw Error("Could not find identity to attest with");let Q=this.getAttestationBuffer(j,J,q),{address:W,signature:L}=z.signMessage(Q);return this.createAttestationTransaction(j,J,W,L,q)}verifyAttestationWithAIP(j){if(!j.every((q)=>Array.isArray(q))||j[0][0]!==K.OP_RETURN||D(j[1])!==p)throw Error("Not a valid BAP transaction");let $=D(j[7])==="44415441"?5:0,J={type:_(j[2]),hash:D(j[3]),sequence:_(j[4]),signingProtocol:_(j[7+$]),signingAddress:_(j[8+$]),signature:c(j[9+$])};if($&&j[3]===j[8])J.data=D(j[9]);console.log({attestation:J});try{let q=[];for(let z=0;z<6+$;z++)q.push(j[z]);J.verified=this.verifySignature(q.flat(),J.signingAddress,J.signature)}catch{J.verified=!1}return J}createAttestationTransaction(j,$,J,q,z=""){let Q=[[K.OP_RETURN],Z(C),Z("ATTEST"),Z(j),Z(`${$}`),Z("|")];if(z)Q.push(Z(C),Z("DATA"),Z(j),Z(z),Z("|"));return Q.push(Z(R),Z("BITCOIN_ECDSA"),Z(J),Z(q,"base64")),console.log({elements:Q}),Q}getAttestationBuffer(j,$=0,J=""){let q=[[K.OP_RETURN],Z(C),Z("ATTEST"),Z(j),Z(`${$}`),Z("|")];if(J)q.push(Z(C),Z("DATA"),Z(j),Z(J),Z("|"));return q.flat()}verifySignature(j,$,J){let q;if(Array.isArray(j))q=j;else if(Buffer.isBuffer(j))q=[...j];else q=Z(j,"utf8");let z=Rj.fromCompact(J,"base64"),Q;for(let W=0;W<4;W++)try{if(Q=z.RecoverPublicKey(W,new kj(l.magicHash(q))),l.verify(q,z,Q)&&Q.toAddress()===$)return!0}catch{}return!1}async verifyChallengeSignature(j,$,J,q){if(!this.verifySignature(J,$,q))return!1;try{let Q=await this.getApiData("/attestation/valid",{idKey:j,address:$,challenge:J,signature:q});if(Q?.status==="success"&&Q?.result?.valid===!0)return!0;return!1}catch(Q){return console.error("API call failed:",Q),!1}}async isValidAttestationTransaction(j){if(this.verifyAttestationWithAIP(j))return this.getApiData("/attestation/valid",{tx:j});return!1}async getIdentityFromAddress(j){return this.getApiData("/identity/from-address",{address:j})}async getIdentity(j){return this.getApiData("/identity/get",{idKey:j})}async getAttestationsForHash(j){return this.getApiData("/attestations",{hash:j})}exportForBackup(j,$,J){let z={ids:this.exportIds(),...j&&{label:j},createdAt:new Date().toISOString()};if(this.#J){if(!this.#j)throw Error("Type 42 parameters not initialized");return{...z,rootPk:this.#j.toWif()}}if(!this.#$)throw Error("HD private key not initialized");return{...z,xprv:$||this.#$.toString(),mnemonic:J||""}}exportMemberForBackup(j,$){let J=this.#Q[j];if(!J)throw Error(`Identity ${j} not found`);let q=J.exportMember();return{wif:q.wif,id:q.encryptedData,...$&&{label:$},createdAt:new Date().toISOString()}}}export{O as MemberID,U as MasterID,Bj as BAP};
7
7
 
8
- //# debugId=78F095C16B95FE2864756E2164756E21
8
+ //# debugId=7C675258BEF437DC64756E2164756E21
@@ -7,10 +7,10 @@
7
7
  "import { Utils } from \"@bsv/sdk\";\nconst { toHex, toArray } = Utils;\n\nexport const BAP_BITCOM_ADDRESS = \"1BAPSuaPnfGnSBM3GLV9yhxUdYe4vGbdMT\";\nexport const BAP_BITCOM_ADDRESS_HEX = toHex(toArray(BAP_BITCOM_ADDRESS));\nexport const AIP_BITCOM_ADDRESS = \"15PciHG22SNLQJXMoSUaWVi7WSqc7hCfva\";\nexport const AIP_BITCOM_ADDRESS_HEX = toHex(toArray(AIP_BITCOM_ADDRESS));\nexport const BAP_SERVER = \"https://api.sigmaidentity.com/v1\";\nexport const MAX_INT = 2147483648 - 1; // 0x80000000\n\n// This is just a choice for this library and could be anything else if so needed/wanted\n// but it is advisable to use the same derivation between libraries for compatibility\nexport const SIGNING_PATH_PREFIX = \"m/424150'/0'/0'\"; // BAP in hex\nexport const ENCRYPTION_PATH = `m/424150'/${MAX_INT}'/${MAX_INT}'`;\n",
8
8
  "import {\n BSM,\n Utils as BSVUtils,\n ECIES,\n Hash,\n PublicKey,\n type PrivateKey,\n BigNumber,\n HD,\n} from \"@bsv/sdk\";\nimport type { Signature } from \"@bsv/sdk\";\n\nimport { type APIFetcher, apiFetcher } from \"./api\";\nimport type {\n GetAttestationResponse,\n GetSigningKeysResponse,\n} from \"./apiTypes\";\nimport {\n BAP_BITCOM_ADDRESS,\n BAP_SERVER,\n ENCRYPTION_PATH,\n MAX_INT,\n SIGNING_PATH_PREFIX,\n} from \"./constants\";\nimport type {\n Identity,\n IdentityAttributes,\n OldIdentity,\n MemberIdentity,\n} from \"./interface\";\nimport { Utils } from \"./utils\";\nimport { MemberID } from \"./MemberID\";\nimport { BaseClass } from \"./BaseClass\";\nconst { toArray, toHex, toBase58, toUTF8, toBase64 } = BSVUtils;\nconst { electrumDecrypt, electrumEncrypt } = ECIES;\nconst { magicHash } = BSM;\n\n// Type 42 key source\ninterface Type42KeySource {\n rootPk: PrivateKey;\n}\n\n/**\n * MasterID class\n *\n * This class should be used in conjunction with the BAP class\n * Supports both BIP32 (HD) and Type 42 key derivation\n *\n * @type {MasterID}\n */\nclass MasterID extends BaseClass {\n #HDPrivateKey: HD | undefined;\n #masterPrivateKey: PrivateKey | undefined;\n #isType42: boolean;\n #BAP_SERVER: string = BAP_SERVER;\n #BAP_TOKEN = \"\";\n #rootPath: string;\n #previousPath: string;\n #currentPath: string;\n #idSeed: string;\n\n idName: string;\n description: string;\n\n rootAddress: string;\n identityKey: string;\n identityAttributes: IdentityAttributes;\n\n getApiData: APIFetcher;\n\n constructor(\n keySource: HD | Type42KeySource,\n identityAttributes: IdentityAttributes = {},\n idSeed = \"\"\n ) {\n super();\n\n // Determine if we're using Type 42 or BIP32\n if (keySource instanceof HD) {\n // BIP32 mode\n this.#isType42 = false;\n if (idSeed) {\n // create a new HDPrivateKey based on the seed\n const seedHex = toHex(Hash.sha256(idSeed, \"utf8\"));\n const seedPath = Utils.getSigningPathFromHex(seedHex);\n this.#HDPrivateKey = keySource.derive(seedPath);\n } else {\n this.#HDPrivateKey = keySource;\n }\n } else {\n // Type 42 mode\n this.#isType42 = true;\n this.#masterPrivateKey = keySource.rootPk;\n \n if (idSeed) {\n // For Type 42 with seed, we derive a new master key using the seed as invoice number\n const seedHex = toHex(Hash.sha256(idSeed, \"utf8\"));\n this.#masterPrivateKey = this.#masterPrivateKey.deriveChild(\n this.#masterPrivateKey.toPublicKey(),\n seedHex\n );\n }\n }\n\n this.#idSeed = idSeed;\n this.idName = \"ID 1\";\n this.description = \"\";\n\n this.#rootPath = `${SIGNING_PATH_PREFIX}/0/0/0`;\n this.#previousPath = `${SIGNING_PATH_PREFIX}/0/0/0`;\n this.#currentPath = `${SIGNING_PATH_PREFIX}/0/0/1`;\n\n // Derive root address based on mode\n if (this.#isType42) {\n if (!this.#masterPrivateKey) throw new Error(\"Master private key not initialized\");\n // In Type 42, we use the path as invoice number\n const rootKey = this.#masterPrivateKey.deriveChild(\n this.#masterPrivateKey.toPublicKey(),\n this.#rootPath\n );\n this.rootAddress = rootKey.toPublicKey().toAddress();\n } else {\n if (!this.#HDPrivateKey) throw new Error(\"HD private key not initialized\");\n const rootChild = this.#HDPrivateKey.derive(this.#rootPath);\n this.rootAddress = rootChild.privKey.toPublicKey().toAddress();\n }\n \n this.identityKey = this.deriveIdentityKey(this.rootAddress);\n\n // unlink the object\n const attributes = { ...identityAttributes };\n this.identityAttributes = this.parseAttributes(attributes);\n\n this.getApiData = apiFetcher(this.#BAP_SERVER, this.#BAP_TOKEN);\n }\n\n set BAP_SERVER(bapServer) {\n this.#BAP_SERVER = bapServer;\n }\n\n get BAP_SERVER(): string {\n return this.#BAP_SERVER;\n }\n\n set BAP_TOKEN(token) {\n this.#BAP_TOKEN = token;\n }\n\n get BAP_TOKEN(): string {\n return this.#BAP_TOKEN;\n }\n\n deriveIdentityKey(address: string): string {\n // base58( ripemd160 ( sha256 ( rootAddress ) ) )\n const rootAddressHash = toHex(Hash.sha256(address, \"utf8\"));\n return toBase58(Hash.ripemd160(rootAddressHash, \"hex\"));\n }\n\n /**\n * Helper function to parse identity attributes\n *\n * @param identityAttributes\n * @returns {{}}\n */\n parseAttributes(\n identityAttributes: IdentityAttributes | string\n ): IdentityAttributes {\n if (typeof identityAttributes === \"string\") {\n return this.parseStringUrns(identityAttributes);\n }\n\n for (const key in identityAttributes) {\n if (!identityAttributes[key].value || !identityAttributes[key].nonce) {\n throw new Error(\"Invalid identity attribute\");\n }\n }\n\n return identityAttributes || {};\n }\n\n /**\n * Parse a text of urn string into identity attributes\n *\n * urn:bap:id:name:John Doe:e2c6fb4063cc04af58935737eaffc938011dff546d47b7fbb18ed346f8c4d4fa\n * urn:bap:id:birthday:1990-05-22:e61f23cbbb2284842d77965e2b0e32f0ca890b1894ca4ce652831347ee3596d9\n * urn:bap:id:over18:1:480ca17ccaacd671b28dc811332525f2f2cd594d8e8e7825de515ce5d52d30e8\n *\n * @param urnIdentityAttributes\n */\n parseStringUrns(urnIdentityAttributes: string): IdentityAttributes {\n const identityAttributes: IdentityAttributes = {};\n // avoid forEach\n\n const attributesRaw = urnIdentityAttributes\n .replace(/^\\s+/g, \"\")\n .replace(/\\r/gm, \"\")\n .split(\"\\n\");\n\n for (const line of attributesRaw) {\n // remove any whitespace from the string (trim)\n const attribute = line.replace(/^\\s+/g, \"\").replace(/\\s+$/g, \"\");\n const urn = attribute.split(\":\");\n if (\n urn[0] === \"urn\" &&\n urn[1] === \"bap\" &&\n urn[2] === \"id\" &&\n urn[3] &&\n urn[4] &&\n urn[5]\n ) {\n identityAttributes[urn[3]] = {\n value: urn[4],\n nonce: urn[5],\n };\n }\n }\n\n return identityAttributes;\n }\n\n /**\n * Returns the identity key\n *\n * @returns {*|string}\n */\n getIdentityKey(): string {\n return this.identityKey;\n }\n\n /**\n * This should be called with the last part of the signing path (/.../.../...)\n * This library assumes the first part is m/424150'/0'/0' as defined at the top of this file\n *\n * @param path The second path of the signing path in the format [0-9]{0,9}/[0-9]{0,9}/[0-9]{0,9}\n */\n set rootPath(path: string) {\n if (this.#isType42) {\n // Type 42 mode: use path directly as invoice number\n this.#rootPath = path;\n \n if (!this.#masterPrivateKey) throw new Error(\"Master private key not initialized\");\n const derivedKey = this.#masterPrivateKey.deriveChild(\n this.#masterPrivateKey.toPublicKey(),\n path // Use original path as invoice number\n );\n this.rootAddress = derivedKey.toPublicKey().toAddress();\n \n // For Type 42, paths don't need BIP32 formatting\n this.#previousPath = path;\n this.#currentPath = path;\n } else {\n // BIP32 mode: validate and format HD path\n let pathToUse = path;\n if (path.split(\"/\").length < 5) {\n pathToUse = `${SIGNING_PATH_PREFIX}${path}`;\n }\n\n if (!this.validatePath(pathToUse)) {\n throw new Error(`invalid signing path given ${pathToUse}`);\n }\n\n this.#rootPath = pathToUse;\n\n if (!this.#HDPrivateKey) throw new Error(\"HD private key not initialized\");\n const derivedChild = this.#HDPrivateKey.derive(pathToUse);\n this.rootAddress = derivedChild.pubKey.toAddress();\n \n // Set paths for BIP32\n this.#previousPath = pathToUse;\n this.#currentPath = pathToUse;\n }\n\n // Identity keys should be derivatives of the root address - this allows checking\n // of the creation transaction\n this.identityKey = this.deriveIdentityKey(this.rootAddress);\n }\n\n get rootPath(): string {\n return this.#rootPath;\n }\n\n getRootPath(): string {\n return this.#rootPath;\n }\n\n /**\n * This should be called with the last part of the signing path (/.../.../...)\n * This library assumes the first part is m/424150'/0'/0' as defined at the top of this file\n *\n * @param path The second path of the signing path in the format [0-9]{0,9}/[0-9]{0,9}/[0-9]{0,9}\n */\n set currentPath(path) {\n if (this.#isType42) {\n // Type 42 mode: use path directly as invoice number\n this.#previousPath = this.#currentPath;\n this.#currentPath = path;\n } else {\n // BIP32 mode: validate and format HD path\n let pathToUse = path;\n if (path.split(\"/\").length < 5) {\n pathToUse = `${SIGNING_PATH_PREFIX}${path}`;\n }\n\n if (!this.validatePath(pathToUse)) {\n throw new Error(\"invalid signing path given\");\n }\n\n this.#previousPath = this.#currentPath;\n this.#currentPath = pathToUse;\n }\n }\n\n get currentPath(): string {\n return this.#currentPath;\n }\n\n get previousPath(): string {\n return this.#previousPath;\n }\n\n /**\n * This can be used to break the deterministic way child keys are created to make it harder for\n * an attacker to steal the identites when the root key is compromised. This does however require\n * the seeds to be stored at all times. If the seed is lost, the identity will not be recoverable.\n */\n get idSeed(): string {\n return this.#idSeed;\n }\n\n /**\n * Increment current path to a new path\n *\n * @returns {*}\n */\n incrementPath(): void {\n this.currentPath = Utils.getNextPath(this.currentPath);\n }\n\n /**\n * Check whether the given path is a valid path for use with this class\n * The signing paths used here always have a length of 3\n *\n * @param path The last part of the signing path (example \"/0/0/1\")\n * @returns {boolean}\n */\n validatePath(path: string) {\n /* eslint-disable max-len */\n if (\n path.match(\n /\\/[0-9]{1,10}'?\\/[0-9]{1,10}'?\\/[0-9]{1,10}'?\\/[0-9]{1,10}'?\\/[0-9]{1,10}'?\\/[0-9]{1,10}'?/\n )\n ) {\n const pathValues = path.split(\"/\");\n if (\n pathValues.length === 7 &&\n Number(pathValues[1].replace(\"'\", \"\")) <= MAX_INT &&\n Number(pathValues[2].replace(\"'\", \"\")) <= MAX_INT &&\n Number(pathValues[3].replace(\"'\", \"\")) <= MAX_INT &&\n Number(pathValues[4].replace(\"'\", \"\")) <= MAX_INT &&\n Number(pathValues[5].replace(\"'\", \"\")) <= MAX_INT &&\n Number(pathValues[6].replace(\"'\", \"\")) <= MAX_INT\n ) {\n return true;\n }\n }\n\n return false;\n }\n\n /**\n * Get the OP_RETURN for the initial ID transaction (signed with root address)\n *\n * @returns {[]}\n */\n getInitialIdTransaction() {\n return this.getIdTransaction(this.#rootPath);\n }\n\n /**\n * Get the OP_RETURN for the ID transaction of the current address / path\n *\n * @returns {[]}\n */\n getIdTransaction(previousPath = \"\") {\n if (this.#currentPath === this.#rootPath) {\n throw new Error(\n \"Current path equals rootPath. ID was probably not initialized properly\"\n );\n }\n\n const opReturn = [\n toArray(BAP_BITCOM_ADDRESS),\n toArray(\"ID\"),\n toArray(this.identityKey),\n toArray(this.getCurrentAddress()),\n ];\n\n return this.signOpReturnWithAIP(\n opReturn,\n previousPath || this.#previousPath\n );\n }\n\n /**\n * Get address for given path\n *\n * @param path\n * @returns {*}\n */\n getAddress(path: string): string {\n if (this.#isType42) {\n if (!this.#masterPrivateKey) throw new Error(\"Master private key not initialized\");\n // In Type 42, use path as invoice number\n const derivedKey = this.#masterPrivateKey.deriveChild(\n this.#masterPrivateKey.toPublicKey(),\n path\n );\n return derivedKey.toPublicKey().toAddress();\n }\n if (!this.#HDPrivateKey) throw new Error(\"HD private key not initialized\");\n const derivedChild = this.#HDPrivateKey.derive(path);\n return derivedChild.privKey.toPublicKey().toAddress();\n }\n\n /**\n * Get current signing address\n *\n * @returns {*}\n */\n getCurrentAddress(): string {\n return this.getAddress(this.#currentPath);\n }\n\n /**\n * Get the encryption key pair for this identity\n */\n getEncryptionKey(): { privKey: PrivateKey; pubKey: PublicKey } {\n if (this.#isType42) {\n if (!this.#masterPrivateKey) throw new Error(\"Master private key not initialized\");\n // First derive to root path, then to encryption path\n const rootKey = this.#masterPrivateKey.deriveChild(\n this.#masterPrivateKey.toPublicKey(),\n this.#rootPath\n );\n const encryptionKey = rootKey.deriveChild(\n rootKey.toPublicKey(),\n ENCRYPTION_PATH\n );\n return {\n privKey: encryptionKey,\n pubKey: encryptionKey.toPublicKey(),\n };\n }\n if (!this.#HDPrivateKey) throw new Error(\"HD private key not initialized\");\n const HDPrivateKey = this.#HDPrivateKey.derive(this.#rootPath);\n const encryptionKey = HDPrivateKey.derive(ENCRYPTION_PATH).privKey;\n return {\n privKey: encryptionKey,\n pubKey: encryptionKey.toPublicKey(),\n };\n }\n\n /**\n * Get the encryption key using type 42 (different key / incompatible with above)\n * @deprecated Use getEncryptionKey() which now handles both BIP32 and Type 42\n */\n getEncryptionKeyType42(): { privKey: PrivateKey; pubKey: PublicKey } {\n if (this.#isType42) {\n // If already in Type 42 mode, just use the regular method\n return this.getEncryptionKey();\n }\n \n // Legacy behavior for BIP32 keys wanting Type 42 style derivation\n if (!this.#HDPrivateKey) throw new Error(\"HD private key not initialized\");\n const HDPrivateKey = this.#HDPrivateKey.derive(this.#rootPath);\n const encryptionKey = HDPrivateKey.privKey.deriveChild(\n HDPrivateKey.toPublic().pubKey,\n ENCRYPTION_PATH\n );\n return {\n privKey: encryptionKey,\n pubKey: encryptionKey.toPublicKey(),\n };\n }\n /**\n * Get the public key for encrypting data for this identity\n */\n getEncryptionPublicKey(): string {\n const { pubKey } = this.getEncryptionKey();\n return pubKey.toString();\n }\n\n /**\n * Get the public key for encrypting data for this identity, using a seed for the encryption\n */\n getEncryptionPublicKeyWithSeed(seed: string): string {\n const encryptionKey = this.getEncryptionPrivateKeyWithSeed(seed);\n return encryptionKey.toPublicKey().toString();\n }\n\n /**\n * Encrypt the given string data with the identity encryption key\n * @param stringData\n * @param counterPartyPublicKey Optional public key of the counterparty\n * @return string Base64\n */\n encrypt(stringData: string, counterPartyPublicKey?: string): string {\n const { privKey: encryptionKey, pubKey: publicKey } = this.getEncryptionKey();\n const pubKey = counterPartyPublicKey\n ? PublicKey.fromString(counterPartyPublicKey)\n : publicKey;\n return toBase64(electrumEncrypt(toArray(stringData), pubKey, encryptionKey));\n }\n\n /**\n * Decrypt the given ciphertext with the identity encryption key\n * @param ciphertext\n */\n decrypt(ciphertext: string, counterPartyPublicKey?: string): string {\n const { privKey: encryptionKey } = this.getEncryptionKey();\n let pubKey: PublicKey | undefined;\n if (counterPartyPublicKey) {\n pubKey = PublicKey.fromString(counterPartyPublicKey);\n }\n return toUTF8(\n electrumDecrypt(toArray(ciphertext, \"base64\"), encryptionKey, pubKey)\n );\n }\n\n /**\n * Encrypt the given string data with the identity encryption key\n * @param stringData\n * @param seed String seed\n * @param counterPartyPublicKey Optional public key of the counterparty\n * @return string Base64\n */\n encryptWithSeed(\n stringData: string,\n seed: string,\n counterPartyPublicKey?: string\n ): string {\n const encryptionKey = this.getEncryptionPrivateKeyWithSeed(seed);\n const publicKey = encryptionKey.toPublicKey();\n const pubKey = counterPartyPublicKey\n ? PublicKey.fromString(counterPartyPublicKey)\n : publicKey;\n return toBase64(\n electrumEncrypt(toArray(stringData), pubKey, encryptionKey)\n );\n }\n\n /**\n * Decrypt the given ciphertext with the identity encryption key\n * @param ciphertext\n * @param seed String seed\n // * @param counterPartyPublicKey Public key of the counterparty\n */\n decryptWithSeed(\n ciphertext: string,\n seed: string,\n counterPartyPublicKey?: string\n ): string {\n const encryptionKey = this.getEncryptionPrivateKeyWithSeed(seed);\n let pubKey: PublicKey | undefined;\n if (counterPartyPublicKey) {\n pubKey = PublicKey.fromString(counterPartyPublicKey);\n }\n return toUTF8(\n electrumDecrypt(toArray(ciphertext, \"base64\"), encryptionKey, pubKey)\n );\n }\n\n private getEncryptionPrivateKeyWithSeed(seed: string): PrivateKey {\n const pathHex = toHex(Hash.sha256(seed, \"utf8\"));\n \n if (this.#isType42) {\n if (!this.#masterPrivateKey) throw new Error(\"Master private key not initialized\");\n // First derive to root path\n const rootKey = this.#masterPrivateKey.deriveChild(\n this.#masterPrivateKey.toPublicKey(),\n this.#rootPath\n );\n // Then derive with seed as invoice number\n return rootKey.deriveChild(rootKey.toPublicKey(), pathHex);\n }\n if (!this.#HDPrivateKey) throw new Error(\"HD private key not initialized\");\n const path = Utils.getSigningPathFromHex(pathHex);\n const HDPrivateKey = this.#HDPrivateKey.derive(this.#rootPath);\n return HDPrivateKey.derive(path).privKey;\n }\n\n /**\n * Get an attestation string for the given urn for this identity\n *\n * @param urn\n * @returns {string}\n */\n getAttestation(urn: string) {\n const urnHash = Hash.sha256(urn, \"utf8\");\n return `bap:attest:${toHex(urnHash)}:${this.getIdentityKey()}`;\n }\n\n /**\n * Generate and return the attestation hash for the given attribute of this identity\n *\n * @param attribute Attribute name (name, email etc.)\n * @returns {string}\n */\n getAttestationHash(attribute: string) {\n const urn = this.getAttributeUrn(attribute);\n if (!urn) return null;\n\n const attestation = this.getAttestation(urn);\n const attestationHash = Hash.sha256(attestation, \"utf8\");\n\n return toHex(attestationHash);\n }\n\n /**\n * Sign a message with the current signing address of this identity\n *\n * @param message\n * @param signingPath\n * @returns {{address: string, signature: string}}\n */\n signMessage(\n message: number[],\n signingPath?: string\n ): { address: string; signature: string } {\n const pathToUse = signingPath || this.#currentPath;\n let childPk: PrivateKey;\n \n if (this.#isType42) {\n if (!this.#masterPrivateKey) throw new Error(\"Master private key not initialized\");\n // In Type 42, use path as invoice number\n childPk = this.#masterPrivateKey.deriveChild(\n this.#masterPrivateKey.toPublicKey(),\n pathToUse\n );\n } else {\n if (!this.#HDPrivateKey) throw new Error(\"HD private key not initialized\");\n childPk = this.#HDPrivateKey.derive(pathToUse).privKey;\n }\n \n const address = childPk.toAddress();\n\n // Needed to calculate the recovery factor\n const dummySig = BSM.sign(message, childPk, \"raw\") as Signature;\n const h = new BigNumber(magicHash(message));\n const r = dummySig.CalculateRecoveryFactor(childPk.toPublicKey(), h);\n const signature = (\n BSM.sign(message, childPk, \"raw\") as Signature\n ).toCompact(r, true, \"base64\") as string;\n\n return { address, signature };\n }\n\n /**\n * Sign a message using a key based on the given string seed\n *\n * This works by creating a private key from the root key of this identity. It will always\n * work with the rootPath / rootKey, to be deterministic. It will not change even if the keys\n * are rotated for this ID.\n *\n * This is used in for instance deterministic login systems, that do not support BAP.\n *\n * @param message\n * @param seed {string} String seed that will be used to generate a path\n */\n signMessageWithSeed(\n message: string,\n seed: string\n ): { address: string; signature: string } {\n const pathHex = toHex(Hash.sha256(seed, \"utf8\"));\n let derivedKey: PrivateKey;\n \n if (this.#isType42) {\n if (!this.#masterPrivateKey) throw new Error(\"Master private key not initialized\");\n // First derive to root path\n const rootKey = this.#masterPrivateKey.deriveChild(\n this.#masterPrivateKey.toPublicKey(),\n this.#rootPath\n );\n // Then derive with seed hex as invoice number\n derivedKey = rootKey.deriveChild(rootKey.toPublicKey(), pathHex);\n } else {\n if (!this.#HDPrivateKey) throw new Error(\"HD private key not initialized\");\n const path = Utils.getSigningPathFromHex(pathHex);\n const HDPrivateKey = this.#HDPrivateKey.derive(this.#rootPath);\n const derivedChild = HDPrivateKey.derive(path);\n derivedKey = derivedChild.privKey;\n }\n \n const address = derivedKey.toPublicKey().toAddress();\n const messageArray = toArray(message, \"utf8\");\n \n const dummySig = BSM.sign(messageArray, derivedKey, \"raw\") as Signature;\n const h = new BigNumber(magicHash(messageArray));\n const r = dummySig.CalculateRecoveryFactor(derivedKey.toPublicKey(), h);\n\n const signature = (\n BSM.sign(messageArray, derivedKey, \"raw\") as Signature\n ).toCompact(r, true, \"base64\") as string;\n\n return { address, signature };\n }\n\n /**\n * Sign an op_return hex array with AIP\n * @param opReturn {array}\n * @param signingPath {string}\n * @return {number[]}\n */\n signOpReturnWithAIP(opReturn: number[][], signingPath = \"\"): number[][] {\n const aipMessageBuffer = this.getAIPMessageBuffer(opReturn);\n const { address, signature } = this.signMessage(\n aipMessageBuffer.flat(),\n signingPath\n );\n return this.formatAIPOutput(opReturn, address, signature);\n }\n\n /**\n * Get all signing keys for this identity\n */\n async getIdSigningKeys(): Promise<GetSigningKeysResponse> {\n const signingKeys = await this.getApiData<GetSigningKeysResponse>(\n \"/signing-keys\",\n {\n idKey: this.identityKey,\n }\n );\n console.log(\"getIdSigningKeys\", signingKeys);\n\n return signingKeys;\n }\n\n /**\n * Get all attestations for the given attribute\n *\n * @param attribute\n */\n async getAttributeAttestations(\n attribute: string\n ): Promise<GetAttestationResponse> {\n // This function needs to make a call to a BAP server to get all the attestations for this\n // identity for the given attribute\n const attestationHash = this.getAttestationHash(attribute);\n\n // get all BAP ATTEST records for the given attestationHash\n const attestations = await this.getApiData<GetAttestationResponse>(\n \"/attestation/get\",\n {\n hash: attestationHash,\n }\n );\n console.log(\"getAttestations\", attribute, attestationHash, attestations);\n\n return attestations;\n }\n\n /**\n * Import an identity from a JSON object\n *\n * @param identity{{}}\n */\n import(identity: Identity | OldIdentity): void {\n this.idName = identity.name;\n this.description = identity.description || \"\";\n this.identityKey = identity.identityKey;\n this.#rootPath = identity.rootPath;\n this.rootAddress = identity.rootAddress;\n this.#previousPath = identity.previousPath;\n this.#currentPath = identity.currentPath;\n this.#idSeed = (\"idSeed\" in identity ? identity.idSeed : \"\") || \"\";\n this.identityAttributes = this.parseAttributes(identity.identityAttributes);\n }\n\n /**\n * Export this identity to a JSON object\n * @returns {{}}\n */\n export(): Identity {\n return {\n name: this.idName,\n description: this.description,\n identityKey: this.identityKey,\n rootPath: this.#rootPath,\n rootAddress: this.rootAddress,\n previousPath: this.#previousPath,\n currentPath: this.#currentPath,\n idSeed: this.#idSeed,\n identityAttributes: this.getAttributes(),\n lastIdPath: \"\",\n };\n }\n\n // New method to export a member-friendly backup, containing only the derived signing key\n exportMemberBackup(): MemberIdentity {\n let derivedKey: PrivateKey;\n \n if (this.#isType42) {\n if (!this.#masterPrivateKey) throw new Error(\"Master private key not initialized\");\n derivedKey = this.#masterPrivateKey.deriveChild(\n this.#masterPrivateKey.toPublicKey(),\n this.#currentPath\n );\n } else {\n if (!this.#HDPrivateKey) throw new Error(\"HD private key not initialized\");\n derivedKey = this.#HDPrivateKey.derive(this.#currentPath).privKey;\n }\n \n return {\n name: this.idName,\n description: this.description,\n derivedPrivateKey: derivedKey.toWif(),\n address: derivedKey.toPublicKey().toAddress(),\n identityAttributes: this.getAttributes(),\n identityKey: this.identityKey,\n };\n }\n\n // New method to derive a new member ID from the master HD key\n public newId(): MemberID {\n // Assuming incrementPath updates the internal current path\n this.incrementPath();\n \n let derivedKey: PrivateKey;\n if (this.#isType42) {\n if (!this.#masterPrivateKey) throw new Error(\"Master private key not initialized\");\n derivedKey = this.#masterPrivateKey.deriveChild(\n this.#masterPrivateKey.toPublicKey(),\n this.#currentPath\n );\n } else {\n if (!this.#HDPrivateKey) throw new Error(\"HD private key not initialized\");\n derivedKey = this.#HDPrivateKey.derive(this.#currentPath).privKey;\n }\n \n return new MemberID(derivedKey);\n }\n\n /**\n * Export member data in bitcoin-backup compatible format\n * @returns Object with wif and encrypted member data\n */\n exportMember(): { wif: string; encryptedData: string } {\n const memberExport = this.exportMemberBackup();\n \n let derivedKey: PrivateKey;\n if (this.#isType42) {\n if (!this.#masterPrivateKey) throw new Error(\"Master private key not initialized\");\n derivedKey = this.#masterPrivateKey.deriveChild(\n this.#masterPrivateKey.toPublicKey(),\n this.#currentPath\n );\n } else {\n if (!this.#HDPrivateKey) throw new Error(\"HD private key not initialized\");\n derivedKey = this.#HDPrivateKey.derive(this.#currentPath).privKey;\n }\n\n // Encrypt the member data using ECIES\n const encryptedData = toBase64(\n electrumEncrypt(\n toArray(JSON.stringify(memberExport)),\n derivedKey.toPublicKey()\n )\n );\n\n return {\n wif: memberExport.derivedPrivateKey,\n encryptedData,\n };\n }\n}\nexport { MasterID };\n",
9
9
  "import type { PathPrefix } from \"./interface.js\";\n\nexport const Utils = {\n /**\n * Helper function to generate cryptographically secure random bytes\n * \n * This follows the pattern used by BSV SDK and other Bitcoin libraries.\n * Uses crypto.getRandomValues() which is available in browsers and modern Node.js.\n *\n * @param {number} byteLength - Number of random bytes to generate (default: 32)\n * @returns {Uint8Array} Array of cryptographically secure random bytes\n */\n getRandomBytes(byteLength = 32): Uint8Array {\n // Use crypto.getRandomValues() - available in browsers and Node.js 15+\n if (typeof globalThis !== 'undefined' && globalThis.crypto && globalThis.crypto.getRandomValues) {\n const array = new Uint8Array(byteLength);\n globalThis.crypto.getRandomValues(array);\n return array;\n }\n\n // Fallback error - crypto operations require secure randomness\n throw new Error(\n 'Secure random number generation not available. ' +\n 'crypto.getRandomValues() is required for cryptographic operations. ' +\n 'This environment may not be suitable for secure key generation.'\n );\n },\n\n /**\n * Helper function to generate a random hex string\n *\n * @param {number} byteLength - Number of random bytes to generate (default: 32)\n * @returns {string} Hex string of random bytes\n */\n getRandomString(byteLength = 32): string {\n const bytes = this.getRandomBytes(byteLength);\n return Array.from(bytes, byte => byte.toString(16).padStart(2, '0')).join('');\n },\n\n /**\n * Get a signing path from a hex number\n *\n * @param hexString {string}\n * @param hardened {boolean} Whether to return a hardened path\n * @returns {string}\n */\n getSigningPathFromHex(hexString: string, hardened = true) {\n // \"m/0/0/1\"\n let signingPath = \"m\";\n const signingHex = hexString.match(/.{1,8}/g);\n if (!signingHex) {\n throw new Error(\"Invalid hex string\");\n }\n const maxNumber = 2147483648 - 1; // 0x80000000\n for (const hexNumber of signingHex) {\n let number = Number(`0x${hexNumber}`);\n if (number > maxNumber) number -= maxNumber;\n signingPath += `/${number}${hardened ? \"'\" : \"\"}`;\n }\n\n return signingPath;\n },\n\n /**\n * Increment that second to last part from the given part, set the last part to 0\n *\n * @param path string\n * @returns {*}\n */\n getNextIdentityPath(path: string): PathPrefix {\n const pathValues = path.split(\"/\");\n const secondToLastPart = pathValues[pathValues.length - 2];\n\n let hardened = false;\n if (secondToLastPart.match(\"'\")) {\n hardened = true;\n }\n\n const nextPath = (\n Number(secondToLastPart.replace(/[^0-9]/g, \"\")) + 1\n ).toString();\n pathValues[pathValues.length - 2] = nextPath + (hardened ? \"'\" : \"\");\n pathValues[pathValues.length - 1] = `0${hardened ? \"'\" : \"\"}`;\n\n return pathValues.join(\"/\") as PathPrefix;\n },\n\n /**\n * Increment that last part of the given path\n *\n * @param path string\n * @returns {*}\n */\n getNextPath(path: string) {\n const pathValues = path.split(\"/\");\n const lastPart = pathValues[pathValues.length - 1];\n let hardened = false;\n if (lastPart.match(\"'\")) {\n hardened = true;\n }\n const nextPath = (Number(lastPart.replace(/[^0-9]/g, \"\")) + 1).toString();\n pathValues[pathValues.length - 1] = nextPath + (hardened ? \"'\" : \"\");\n return pathValues.join(\"/\");\n },\n};\n",
10
- "import {\n BSM,\n type PublicKey,\n PrivateKey,\n BigNumber,\n} from \"@bsv/sdk\";\nimport type { Signature } from \"@bsv/sdk\";\nimport { BaseClass } from \"./BaseClass\";\nimport type { IdentityAttributes, MemberIdentity } from \"./interface\";\nimport { ENCRYPTION_PATH } from \"./constants\";\nconst { magicHash } = BSM;\n\nexport class MemberID extends BaseClass {\n private key: PrivateKey;\n public idName: string;\n public description: string;\n public address: string;\n public identityKey: string;\n\n constructor(key: PrivateKey, identityAttributes: IdentityAttributes = {}) {\n super();\n this.key = key;\n this.address = key.toAddress();\n this.idName = \"Member ID 1\";\n this.description = \"\";\n this.identityKey = \"\";\n this.identityAttributes = this.parseAttributes(identityAttributes);\n }\n\n // Implement the abstract signMessage method from BaseClass\n public signMessage(\n message: number[],\n _signingPath?: string\n ): { address: string; signature: string } {\n const childPk = this.key;\n const address = childPk.toAddress();\n\n // Sign using the raw message buffer directly\n const dummySig = BSM.sign(message, childPk, \"raw\") as Signature;\n const h = new BigNumber(magicHash(message));\n const r = dummySig.CalculateRecoveryFactor(childPk.toPublicKey(), h);\n\n const signature = (\n BSM.sign(message, childPk, \"raw\") as Signature\n ).toCompact(r, true, \"base64\") as string;\n\n return { address, signature };\n }\n\n // Implement signOpReturnWithAIP - MemberID ignores signing path\n public signOpReturnWithAIP(opReturn: number[][]): number[][] {\n const aipMessageBuffer = this.getAIPMessageBuffer(opReturn);\n const { address, signature } = this.signMessage(aipMessageBuffer.flat());\n return this.formatAIPOutput(aipMessageBuffer, address, signature);\n }\n\n // Return the member's public key\n public getPublicKey(): string {\n return this.key.toPublicKey().toString();\n }\n\n // Import the member identity from an object containing the derived private key and identity data\n public import(identity: MemberIdentity): void {\n this.idName = identity.name;\n this.description = identity.description;\n this.key = PrivateKey.fromWif(identity.derivedPrivateKey);\n this.address = this.key.toAddress();\n this.identityAttributes = identity.identityAttributes || {};\n this.identityKey = identity.identityKey;\n }\n\n static fromMemberIdentity(identity: MemberIdentity): MemberID {\n const member = new MemberID(PrivateKey.fromWif(identity.derivedPrivateKey));\n member.import(identity);\n return member;\n }\n\n static fromBackup(singleBackup: { wif: string; id: string }): MemberID {\n // decrypt the id and set the details\n const member = new MemberID(PrivateKey.fromWif(singleBackup.wif));\n const id = JSON.parse(member.decrypt(singleBackup.id));\n member.import(id);\n return member;\n }\n\n // Export the member identity as an object containing the derived private key and identity data\n public export(): MemberIdentity {\n return {\n name: this.idName,\n description: this.description,\n derivedPrivateKey: this.key.toWif(),\n address: this.address,\n identityAttributes: this.getAttributes(),\n identityKey: this.identityKey,\n };\n }\n\n /**\n * Get the encryption key pair for this identity\n * We use the same key for both signing and encryption for simplicity\n */\n getEncryptionKey(): { privKey: PrivateKey; pubKey: PublicKey } {\n // Derive the encryption key from the private key using the ENCRYPTION_PATH\n // Since member keys are not HD keys, we use the path as the invoice number,\n // and use our own public key as the other party's public key\n return {\n privKey: this.key.deriveChild(this.key.toPublicKey(), ENCRYPTION_PATH),\n pubKey: this.key\n .deriveChild(this.key.toPublicKey(), ENCRYPTION_PATH)\n .toPublicKey(),\n };\n }\n\n /**\n * Get the public key for encrypting data for this identity\n */\n getEncryptionPublicKey(): string {\n const { pubKey } = this.getEncryptionKey();\n return pubKey.toString();\n }\n\n /**\n * Export member data in bitcoin-backup compatible format\n * @param label Optional user-defined label\n * @returns BapMemberBackup compatible object\n */\n exportForBackup(label?: string): {\n wif: string;\n id: string;\n label?: string;\n createdAt: string;\n } {\n const memberData = this.export();\n const encryptedData = this.encrypt(JSON.stringify(memberData));\n\n return {\n wif: this.key.toWif(),\n id: encryptedData,\n ...(label && { label }),\n createdAt: new Date().toISOString(),\n };\n }\n}\n",
10
+ "import {\n BSM,\n PublicKey,\n PrivateKey,\n BigNumber,\n Hash,\n Utils as BSVUtils,\n ECIES,\n} from \"@bsv/sdk\";\nimport type { Signature } from \"@bsv/sdk\";\nimport { BaseClass } from \"./BaseClass\";\nimport type { IdentityAttributes, MemberIdentity } from \"./interface\";\nimport { ENCRYPTION_PATH } from \"./constants\";\nconst { magicHash } = BSM;\nconst { toArray, toUTF8, toBase64, toHex } = BSVUtils;\nconst { electrumDecrypt, electrumEncrypt } = ECIES;\n\nexport class MemberID extends BaseClass {\n private key: PrivateKey;\n public idName: string;\n public description: string;\n public address: string;\n public identityKey: string;\n\n constructor(key: PrivateKey, identityAttributes: IdentityAttributes = {}) {\n super();\n this.key = key;\n this.address = key.toAddress();\n this.idName = \"Member ID 1\";\n this.description = \"\";\n this.identityKey = \"\";\n this.identityAttributes = this.parseAttributes(identityAttributes);\n }\n\n // Implement the abstract signMessage method from BaseClass\n public signMessage(\n message: number[],\n _signingPath?: string\n ): { address: string; signature: string } {\n const childPk = this.key;\n const address = childPk.toAddress();\n\n // Sign using the raw message buffer directly\n const dummySig = BSM.sign(message, childPk, \"raw\") as Signature;\n const h = new BigNumber(magicHash(message));\n const r = dummySig.CalculateRecoveryFactor(childPk.toPublicKey(), h);\n\n const signature = (\n BSM.sign(message, childPk, \"raw\") as Signature\n ).toCompact(r, true, \"base64\") as string;\n\n return { address, signature };\n }\n\n // Implement signOpReturnWithAIP - MemberID ignores signing path\n public signOpReturnWithAIP(opReturn: number[][]): number[][] {\n const aipMessageBuffer = this.getAIPMessageBuffer(opReturn);\n const { address, signature } = this.signMessage(aipMessageBuffer.flat());\n return this.formatAIPOutput(aipMessageBuffer, address, signature);\n }\n\n // Return the member's public key\n public getPublicKey(): string {\n return this.key.toPublicKey().toString();\n }\n\n // Import the member identity from an object containing the derived private key and identity data\n public import(identity: MemberIdentity): void {\n this.idName = identity.name;\n this.description = identity.description;\n this.key = PrivateKey.fromWif(identity.derivedPrivateKey);\n this.address = this.key.toAddress();\n this.identityAttributes = identity.identityAttributes || {};\n this.identityKey = identity.identityKey;\n }\n\n static fromMemberIdentity(identity: MemberIdentity): MemberID {\n const member = new MemberID(PrivateKey.fromWif(identity.derivedPrivateKey));\n member.import(identity);\n return member;\n }\n\n static fromBackup(singleBackup: { wif: string; id: string }): MemberID {\n // decrypt the id and set the details\n const member = new MemberID(PrivateKey.fromWif(singleBackup.wif));\n const id = JSON.parse(member.decrypt(singleBackup.id));\n member.import(id);\n return member;\n }\n\n // Export the member identity as an object containing the derived private key and identity data\n public export(): MemberIdentity {\n return {\n name: this.idName,\n description: this.description,\n derivedPrivateKey: this.key.toWif(),\n address: this.address,\n identityAttributes: this.getAttributes(),\n identityKey: this.identityKey,\n };\n }\n\n /**\n * Get the encryption key pair for this identity\n * We use the same key for both signing and encryption for simplicity\n */\n getEncryptionKey(): { privKey: PrivateKey; pubKey: PublicKey } {\n // Derive the encryption key from the private key using the ENCRYPTION_PATH\n // Since member keys are not HD keys, we use the path as the invoice number,\n // and use our own public key as the other party's public key\n return {\n privKey: this.key.deriveChild(this.key.toPublicKey(), ENCRYPTION_PATH),\n pubKey: this.key\n .deriveChild(this.key.toPublicKey(), ENCRYPTION_PATH)\n .toPublicKey(),\n };\n }\n\n /**\n * Get the public key for encrypting data for this identity\n */\n getEncryptionPublicKey(): string {\n const { pubKey } = this.getEncryptionKey();\n return pubKey.toString();\n }\n\n /**\n * Get a derived encryption key using a seed string (Type42 derivation)\n * This allows deriving unique encryption keys per friend/conversation\n * @param seed - The seed string (e.g., friend's BAP ID)\n * @returns The derived private key for this seed\n */\n private getEncryptionPrivateKeyWithSeed(seed: string): PrivateKey {\n // Hash the seed to get a deterministic value\n const seedHash = toHex(Hash.sha256(seed, \"utf8\"));\n // Use Type42 derivation: deriveChild(publicKey, invoice)\n return this.key.deriveChild(this.key.toPublicKey(), seedHash);\n }\n\n /**\n * Get the encryption key pair for a specific seed\n * @param seed - The seed string (e.g., friend's BAP ID)\n */\n getEncryptionKeyWithSeed(seed: string): { privKey: PrivateKey; pubKey: PublicKey } {\n const privKey = this.getEncryptionPrivateKeyWithSeed(seed);\n return {\n privKey,\n pubKey: privKey.toPublicKey(),\n };\n }\n\n /**\n * Get the public key for encrypting data for a specific seed\n * This is the public key to include in friend requests\n * @param seed - The seed string (e.g., friend's BAP ID)\n */\n getEncryptionPublicKeyWithSeed(seed: string): string {\n return this.getEncryptionPrivateKeyWithSeed(seed).toPublicKey().toString();\n }\n\n /**\n * Encrypt data using a seed-derived key\n * @param stringData - The data to encrypt\n * @param seed - The seed string for key derivation (e.g., friend's BAP ID)\n * @param counterPartyPublicKey - Optional public key of the recipient\n * @returns Base64 encoded encrypted data\n */\n encryptWithSeed(stringData: string, seed: string, counterPartyPublicKey?: string): string {\n const derivedKey = this.getEncryptionPrivateKeyWithSeed(seed);\n const pubKey = derivedKey.toPublicKey();\n // Import PublicKey type-safely - counterPartyPublicKey is already a hex pubkey string\n const PublicKeyClass = this.key.toPublicKey().constructor as typeof import(\"@bsv/sdk\").PublicKey;\n const targetPubKey = counterPartyPublicKey\n ? PublicKeyClass.fromString(counterPartyPublicKey)\n : pubKey;\n return toBase64(electrumEncrypt(toArray(stringData), targetPubKey, derivedKey));\n }\n\n /**\n * Decrypt data using a seed-derived key\n * @param ciphertext - Base64 encoded encrypted data\n * @param seed - The seed string for key derivation (e.g., friend's BAP ID)\n * @param counterPartyPublicKey - Optional public key of the sender\n * @returns Decrypted string\n */\n decryptWithSeed(ciphertext: string, seed: string, counterPartyPublicKey?: string): string {\n const derivedKey = this.getEncryptionPrivateKeyWithSeed(seed);\n let senderPubKey: PublicKey | undefined;\n if (counterPartyPublicKey) {\n senderPubKey = PublicKey.fromString(counterPartyPublicKey);\n }\n return toUTF8(electrumDecrypt(toArray(ciphertext, \"base64\"), derivedKey, senderPubKey));\n }\n\n /**\n * Export member data in bitcoin-backup compatible format\n * @param label Optional user-defined label\n * @returns BapMemberBackup compatible object\n */\n exportForBackup(label?: string): {\n wif: string;\n id: string;\n label?: string;\n createdAt: string;\n } {\n const memberData = this.export();\n const encryptedData = this.encrypt(JSON.stringify(memberData));\n\n return {\n wif: this.key.toWif(),\n id: encryptedData,\n ...(label && { label }),\n createdAt: new Date().toISOString(),\n };\n }\n}\n",
11
11
  "import { ECIES, Utils as BSVUtils, OP, PublicKey } from \"@bsv/sdk\";\nimport type { PrivateKey } from \"@bsv/sdk\";\nimport { AIP_BITCOM_ADDRESS } from \"./constants\";\nimport type { IdentityAttribute, IdentityAttributes } from \"./interface\";\nimport { Utils } from \"./utils\";\nconst { toArray, toUTF8, toBase64 } = BSVUtils;\nconst { electrumDecrypt, electrumEncrypt } = ECIES;\n\nabstract class BaseClass {\n protected identityAttributes: IdentityAttributes = {};\n\n /**\n * Abstract method that must be implemented by derived classes to sign messages\n * @param message - The message to sign\n * @param signingPath - Optional signing path for HD wallets\n * @returns Object containing address and signature\n */\n abstract signMessage(\n message: number[],\n signingPath?: string\n ): { address: string; signature: string };\n\n /**\n * Abstract method that must be implemented by derived classes to get encryption key\n */\n abstract getEncryptionKey(): { privKey: PrivateKey; pubKey: PublicKey };\n\n /**\n * Encrypt the given string data with the identity encryption key\n * @param stringData\n * @param counterPartyPublicKey Optional public key of the counterparty\n * @return string Base64\n */\n encrypt(stringData: string, counterPartyPublicKey?: string): string {\n const { privKey, pubKey } = this.getEncryptionKey();\n const targetPubKey = counterPartyPublicKey\n ? PublicKey.fromString(counterPartyPublicKey)\n : pubKey;\n return toBase64(\n electrumEncrypt(toArray(stringData), targetPubKey, privKey)\n );\n }\n\n /**\n * Decrypt the given ciphertext with the identity encryption key\n * @param ciphertext\n * @param counterPartyPublicKey Optional public key of the counterparty\n */\n decrypt(ciphertext: string, counterPartyPublicKey?: string): string {\n const { privKey } = this.getEncryptionKey();\n let pubKey: PublicKey | undefined;\n if (counterPartyPublicKey) {\n pubKey = PublicKey.fromString(counterPartyPublicKey);\n }\n return toUTF8(\n electrumDecrypt(toArray(ciphertext, \"base64\"), privKey, pubKey)\n );\n }\n\n /**\n * Sign an op_return hex array with AIP\n * Each implementation must handle its own signing path logic\n * @param opReturn {array}\n * @param signingPath {string}\n * @return {number[]}\n */\n signOpReturnWithAIP(opReturn: number[][], signingPath?: string): number[][] {\n const aipMessageBuffer = this.getAIPMessageBuffer(opReturn);\n const { address, signature } = this.signMessage(\n aipMessageBuffer.flat(),\n signingPath\n );\n return this.formatAIPOutput(aipMessageBuffer, address, signature);\n }\n\n /**\n * Returns all the attributes in the identity\n * @returns {IdentityAttributes}\n */\n getAttributes(): IdentityAttributes {\n return this.identityAttributes;\n }\n\n /**\n * Get the value of the given attribute\n * @param attributeName\n * @returns {IdentityAttribute | null}\n */\n getAttribute(attributeName: string): IdentityAttribute | null {\n if (this.identityAttributes[attributeName]) {\n return this.identityAttributes[attributeName];\n }\n return null;\n }\n\n /**\n * Set the value of the given attribute\n * If an empty value ('' || null || false) is given, the attribute is removed from the ID\n * @param attributeName string\n * @param attributeValue any\n */\n setAttribute(\n attributeName: string,\n attributeValue: string | Record<string, string>\n ): void {\n if (!attributeValue) {\n return;\n }\n\n if (this.identityAttributes[attributeName]) {\n this.updateExistingAttribute(attributeName, attributeValue);\n } else {\n this.createNewAttribute(attributeName, attributeValue);\n }\n }\n\n /**\n * Unset the given attribute from the ID\n * @param attributeName\n */\n unsetAttribute(attributeName: string): void {\n delete this.identityAttributes[attributeName];\n }\n\n /**\n * Add an attribute to this identity\n * @param attributeName\n * @param value\n * @param nonce\n */\n addAttribute(attributeName: string, value: string, nonce = \"\"): void {\n let nonceToUse = nonce;\n if (!nonce) {\n nonceToUse = Utils.getRandomString();\n }\n\n this.identityAttributes[attributeName] = {\n value,\n nonce: nonceToUse,\n };\n }\n\n /**\n * Get all attribute URNs for this ID\n * @returns {string}\n */\n getAttributeUrns(): string {\n let urns = \"\";\n for (const key in this.identityAttributes) {\n const urn = this.getAttributeUrn(key);\n if (urn) {\n urns += `${urn}\\n`;\n }\n }\n return urns;\n }\n\n /**\n * Create and return the attribute URN for the given attribute\n * @param attributeName\n * @returns {string|null}\n */\n getAttributeUrn(attributeName: string): string | null {\n const attribute = this.identityAttributes[attributeName];\n if (attribute) {\n return `urn:bap:id:${attributeName}:${attribute.value}:${attribute.nonce}`;\n }\n return null;\n }\n\n /**\n * Parse a text of URN string into identity attributes\n * @param urnIdentityAttributes\n */\n protected parseStringUrns(urnIdentityAttributes: string): IdentityAttributes {\n const identityAttributes: IdentityAttributes = {};\n const attributesRaw = urnIdentityAttributes\n .replace(/^\\s+/g, \"\")\n .replace(/\\r/gm, \"\")\n .split(\"\\n\");\n\n for (const line of attributesRaw) {\n const attribute = line.replace(/^\\s+/g, \"\").replace(/\\s+$/g, \"\");\n const urn = attribute.split(\":\");\n if (\n urn[0] === \"urn\" &&\n urn[1] === \"bap\" &&\n urn[2] === \"id\" &&\n urn[3] &&\n urn[4] &&\n urn[5]\n ) {\n identityAttributes[urn[3]] = {\n value: urn[4],\n nonce: urn[5],\n };\n }\n }\n\n return identityAttributes;\n }\n\n /**\n * Helper function to parse identity attributes\n * @param identityAttributes\n * @returns {IdentityAttributes}\n */\n protected parseAttributes(\n identityAttributes: IdentityAttributes | string\n ): IdentityAttributes {\n if (typeof identityAttributes === \"string\") {\n return this.parseStringUrns(identityAttributes);\n }\n\n for (const key in identityAttributes) {\n if (!identityAttributes[key].value || !identityAttributes[key].nonce) {\n throw new Error(\"Invalid identity attribute\");\n }\n }\n\n return identityAttributes || {};\n }\n\n /**\n * Helper method to update an existing attribute\n */\n protected updateExistingAttribute(\n attributeName: string,\n attributeValue: string | Record<string, string>\n ): void {\n if (typeof attributeValue === \"string\") {\n this.identityAttributes[attributeName].value = attributeValue;\n return;\n }\n\n this.identityAttributes[attributeName].value = attributeValue.value || \"\";\n if (attributeValue.nonce) {\n this.identityAttributes[attributeName].nonce = attributeValue.nonce;\n }\n }\n\n /**\n * Helper method to create a new attribute\n */\n protected createNewAttribute(\n attributeName: string,\n attributeValue: string | Record<string, string>\n ): void {\n if (typeof attributeValue === \"string\") {\n this.addAttribute(attributeName, attributeValue);\n return;\n }\n\n this.addAttribute(\n attributeName,\n attributeValue.value || \"\",\n attributeValue.nonce\n );\n }\n\n /**\n * Construct an AIP buffer from the op return data\n * @param opReturn\n * @returns {number[]} Array of numbers representing the buffer\n */\n protected getAIPMessageBuffer(\n opReturn: number[][],\n indicies?: number[]\n ): number[][] {\n // locate the position of OP_RETURN in the opReturn array\n let opReturnIndex = opReturn.findIndex((op) => op[0] === OP.OP_RETURN);\n const buffers: number[][] = [];\n\n // include OP_RETURN in constructing the signature buffer\n if (opReturnIndex === -1) {\n buffers.push([OP.OP_RETURN]);\n opReturnIndex = 0;\n }\n\n // if indicies is specified, only include the specified indicies in the buffer\n // relative to the position of OP_RETURN as \"0\"\n if (indicies) {\n for (const index of indicies) {\n buffers.push(opReturn[opReturnIndex + index]);\n }\n } else {\n for (const op of opReturn) {\n buffers.push(op);\n }\n }\n\n return buffers;\n }\n\n /**\n * Helper method to format AIP output\n * @param opReturn Original OP_RETURN data\n * @param address Signing address\n * @param signature Base64 signature\n * @returns Formatted AIP output as number[]\n */\n protected formatAIPOutput(\n opReturnBuffers: number[][],\n address: string,\n signature: string\n ): number[][] {\n // Add AIP protocol elements\n const aipElements = [\n toArray(\"|\"),\n toArray(AIP_BITCOM_ADDRESS),\n toArray(\"BITCOIN_ECDSA\"),\n toArray(address),\n toArray(signature, \"base64\"),\n ];\n\n // Concatenate all buffers\n return [...opReturnBuffers, ...aipElements];\n }\n}\n\nexport { BaseClass };\n"
12
12
  ],
13
- "mappings": ";AAAA,cACE,eACA,YACA,SACA,SACA,eAEA,iBACA,kBAGF,gBAAS,kBCJF,IAAM,EAAa,MACxB,EACA,EACA,EACA,IACe,CACf,IAAM,EAAM,GAAG,IAAS,IAWxB,OAViB,MAAM,MAAM,EAAK,CAChC,OAAQ,OACR,QAAS,CACP,eAAgB,kCAChB,QACA,OAAQ,MACV,EACA,KAAM,KAAK,UAAU,CAAO,CAC9B,CAAC,GAEe,KAAK,GAKV,EACX,CAAC,EAAc,IACf,MAAU,EAAa,IAA8B,CACnD,OAAO,EAAc,EAAK,EAAM,EAAM,CAAK,GChC/C,gBAAS,iBACT,IAAQ,QAAO,WAAY,EAEd,EAAqB,qCACrB,EAAyB,EAAM,EAAQ,CAAkB,CAAC,EAC1D,EAAqB,qCACrB,GAAyB,EAAM,EAAQ,CAAkB,CAAC,EAC1D,EAAa,mCACb,EAAU,WAIV,EAAsB,kBACtB,EAAkB,aAAa,MAAY,KCbxD,cACE,WACA,YACA,WACA,eACA,eAEA,QACA,kBCNK,IAAM,EAAQ,CAUnB,cAAc,CAAC,EAAa,GAAgB,CAE1C,GAAI,OAAO,aAAe,aAAe,WAAW,QAAU,WAAW,OAAO,gBAAiB,CAC/F,IAAM,EAAQ,IAAI,WAAW,CAAU,EAEvC,OADA,WAAW,OAAO,gBAAgB,CAAK,EAChC,EAIT,MAAM,IAAI,MACR,mLAGF,GASF,eAAe,CAAC,EAAa,GAAY,CACvC,IAAM,EAAQ,KAAK,eAAe,CAAU,EAC5C,OAAO,MAAM,KAAK,EAAO,KAAQ,EAAK,SAAS,EAAE,EAAE,SAAS,EAAG,GAAG,CAAC,EAAE,KAAK,EAAE,GAU9E,qBAAqB,CAAC,EAAmB,EAAW,GAAM,CAExD,IAAI,EAAc,IACZ,EAAa,EAAU,MAAM,SAAS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M,CACvC,EAGA,GAAI,CAAC,KAAK,GACR,MAAU,MAAM,gCAAgC,EAElD,MAAO,IACF,EACH,KAAM,GAAQ,KAAK,GAAc,SAAS,EAC1C,SAAU,GAAY,EACxB,EASJ,qBAAqB,CACnB,EACA,EAMA,CACA,IAAM,EAAW,KAAK,GAAK,GAC3B,GAAI,CAAC,EACH,MAAU,MAAM,YAAY,aAAiB,EAI/C,IAAM,EAAe,EAAS,aAAa,EAE3C,MAAO,CACL,IAAK,EAAa,IAClB,GAAI,EAAa,iBACb,GAAS,CAAE,OAAM,EACrB,UAAW,IAAI,KAAK,EAAE,YAAY,CACpC,EAEJ",
14
+ "debugId": "7C675258BEF437DC64756E2164756E21",
15
15
  "names": []
16
16
  }
@@ -1,8 +1,8 @@
1
1
  // @bun
2
- import{BSM as l,BigNumber as wj,ECIES as Yj,HD as Gj,OP as K,Signature as Xj,PrivateKey as Fj}from"@bsv/sdk";import{Utils as Cj}from"@bsv/sdk";var i=async(j,$,J,q)=>{let z=`${J}${j}`;return(await fetch(z,{method:"post",headers:{"Content-type":"application/json; charset=utf-8",token:q,format:"json"},body:JSON.stringify($)})).json()},T=(j,$)=>async(J,q)=>{return i(J,q,j,$)};import{Utils as r}from"@bsv/sdk";var{toHex:b,toArray:m}=r,C="1BAPSuaPnfGnSBM3GLV9yhxUdYe4vGbdMT",p=b(m(C)),R="15PciHG22SNLQJXMoSUaWVi7WSqc7hCfva",Oj=b(m(R)),S="https://api.sigmaidentity.com/v1",F=2147483647,k="m/424150'/0'/0'",Y=`m/424150'/${F}'/${F}'`;import{BSM as E,Utils as Qj,ECIES as Zj,Hash as U,PublicKey as H,BigNumber as o,HD as Wj}from"@bsv/sdk";var G={getRandomBytes(j=32){if(typeof globalThis!=="undefined"&&globalThis.crypto&&globalThis.crypto.getRandomValues){let $=new Uint8Array(j);return globalThis.crypto.getRandomValues($),$}throw new Error("Secure random number generation not available. crypto.getRandomValues() is required for cryptographic operations. This environment may not be suitable for secure key generation.")},getRandomString(j=32){let $=this.getRandomBytes(j);return Array.from($,(J)=>J.toString(16).padStart(2,"0")).join("")},getSigningPathFromHex(j,$=!0){let J="m",q=j.match(/.{1,8}/g);if(!q)throw new Error("Invalid hex string");let z=2147483647;for(let Q of q){let W=Number(`0x${Q}`);if(W>z)W-=z;J+=`/${W}${$?"'":""}`}return J},getNextIdentityPath(j){let $=j.split("/"),J=$[$.length-2],q=!1;if(J.match("'"))q=!0;let z=(Number(J.replace(/[^0-9]/g,""))+1).toString();return $[$.length-2]=z+(q?"'":""),$[$.length-1]=`0${q?"'":""}`,$.join("/")},getNextPath(j){let $=j.split("/"),J=$[$.length-1],q=!1;if(J.match("'"))q=!0;let z=(Number(J.replace(/[^0-9]/g,""))+1).toString();return $[$.length-1]=z+(q?"'":""),$.join("/")}};import{BSM as g,PrivateKey as I,BigNumber as qj}from"@bsv/sdk";import{ECIES as a,Utils as e,OP as h,PublicKey as P}from"@bsv/sdk";var{toArray:M,toUTF8:t,toBase64:jj}=e,{electrumDecrypt:$j,electrumEncrypt:Jj}=a;class x{identityAttributes={};encrypt(j,$){let{privKey:J,pubKey:q}=this.getEncryptionKey(),z=$?P.fromString($):q;return jj(Jj(M(j),z,J))}decrypt(j,$){let{privKey:J}=this.getEncryptionKey(),q;if($)q=P.fromString($);return t($j(M(j,"base64"),J,q))}signOpReturnWithAIP(j,$){let J=this.getAIPMessageBuffer(j),{address:q,signature:z}=this.signMessage(J.flat(),$);return this.formatAIPOutput(J,q,z)}getAttributes(){return this.identityAttributes}getAttribute(j){if(this.identityAttributes[j])return this.identityAttributes[j];return null}setAttribute(j,$){if(!$)return;if(this.identityAttributes[j])this.updateExistingAttribute(j,$);else this.createNewAttribute(j,$)}unsetAttribute(j){delete this.identityAttributes[j]}addAttribute(j,$,J=""){let q=J;if(!J)q=G.getRandomString();this.identityAttributes[j]={value:$,nonce:q}}getAttributeUrns(){let j="";for(let $ in this.identityAttributes){let J=this.getAttributeUrn($);if(J)j+=`${J}
2
+ import{BSM as l,BigNumber as kj,ECIES as Oj,HD as _j,OP as K,Signature as Rj,PrivateKey as xj}from"@bsv/sdk";import{Utils as Ej}from"@bsv/sdk";var r=async(j,$,J,q)=>{let z=`${J}${j}`;return(await fetch(z,{method:"post",headers:{"Content-type":"application/json; charset=utf-8",token:q,format:"json"},body:JSON.stringify($)})).json()},T=(j,$)=>async(J,q)=>{return r(J,q,j,$)};import{Utils as a}from"@bsv/sdk";var{toHex:m,toArray:b}=a,C="1BAPSuaPnfGnSBM3GLV9yhxUdYe4vGbdMT",p=m(b(C)),R="15PciHG22SNLQJXMoSUaWVi7WSqc7hCfva",Dj=m(b(R)),S="https://api.sigmaidentity.com/v1",F=2147483647,k="m/424150'/0'/0'",Y=`m/424150'/${F}'/${F}'`;import{BSM as E,Utils as fj,ECIES as Uj,Hash as f,PublicKey as H,BigNumber as n,HD as Mj}from"@bsv/sdk";var G={getRandomBytes(j=32){if(typeof globalThis<"u"&&globalThis.crypto&&globalThis.crypto.getRandomValues){let $=new Uint8Array(j);return globalThis.crypto.getRandomValues($),$}throw Error("Secure random number generation not available. crypto.getRandomValues() is required for cryptographic operations. This environment may not be suitable for secure key generation.")},getRandomString(j=32){let $=this.getRandomBytes(j);return Array.from($,(J)=>J.toString(16).padStart(2,"0")).join("")},getSigningPathFromHex(j,$=!0){let J="m",q=j.match(/.{1,8}/g);if(!q)throw Error("Invalid hex string");let z=2147483647;for(let Q of q){let W=Number(`0x${Q}`);if(W>z)W-=z;J+=`/${W}${$?"'":""}`}return J},getNextIdentityPath(j){let $=j.split("/"),J=$[$.length-2],q=!1;if(J.match("'"))q=!0;let z=(Number(J.replace(/[^0-9]/g,""))+1).toString();return $[$.length-2]=z+(q?"'":""),$[$.length-1]=`0${q?"'":""}`,$.join("/")},getNextPath(j){let $=j.split("/"),J=$[$.length-1],q=!1;if(J.match("'"))q=!0;let z=(Number(J.replace(/[^0-9]/g,""))+1).toString();return $[$.length-1]=z+(q?"'":""),$.join("/")}};import{BSM as g,PublicKey as zj,PrivateKey as I,BigNumber as Qj,Hash as Zj,Utils as Wj,ECIES as Lj}from"@bsv/sdk";import{ECIES as e,Utils as t,OP as h,PublicKey as o}from"@bsv/sdk";var{toArray:M,toUTF8:jj,toBase64:$j}=t,{electrumDecrypt:Jj,electrumEncrypt:qj}=e;class x{identityAttributes={};encrypt(j,$){let{privKey:J,pubKey:q}=this.getEncryptionKey(),z=$?o.fromString($):q;return $j(qj(M(j),z,J))}decrypt(j,$){let{privKey:J}=this.getEncryptionKey(),q;if($)q=o.fromString($);return jj(Jj(M(j,"base64"),J,q))}signOpReturnWithAIP(j,$){let J=this.getAIPMessageBuffer(j),{address:q,signature:z}=this.signMessage(J.flat(),$);return this.formatAIPOutput(J,q,z)}getAttributes(){return this.identityAttributes}getAttribute(j){if(this.identityAttributes[j])return this.identityAttributes[j];return null}setAttribute(j,$){if(!$)return;if(this.identityAttributes[j])this.updateExistingAttribute(j,$);else this.createNewAttribute(j,$)}unsetAttribute(j){delete this.identityAttributes[j]}addAttribute(j,$,J=""){let q=J;if(!J)q=G.getRandomString();this.identityAttributes[j]={value:$,nonce:q}}getAttributeUrns(){let j="";for(let $ in this.identityAttributes){let J=this.getAttributeUrn($);if(J)j+=`${J}
3
3
  `}return j}getAttributeUrn(j){let $=this.identityAttributes[j];if($)return`urn:bap:id:${j}:${$.value}:${$.nonce}`;return null}parseStringUrns(j){let $={},J=j.replace(/^\s+/g,"").replace(/\r/gm,"").split(`
4
- `);for(let q of J){let Q=q.replace(/^\s+/g,"").replace(/\s+$/g,"").split(":");if(Q[0]==="urn"&&Q[1]==="bap"&&Q[2]==="id"&&Q[3]&&Q[4]&&Q[5])$[Q[3]]={value:Q[4],nonce:Q[5]}}return $}parseAttributes(j){if(typeof j==="string")return this.parseStringUrns(j);for(let $ in j)if(!j[$].value||!j[$].nonce)throw new Error("Invalid identity attribute");return j||{}}updateExistingAttribute(j,$){if(typeof $==="string"){this.identityAttributes[j].value=$;return}if(this.identityAttributes[j].value=$.value||"",$.nonce)this.identityAttributes[j].nonce=$.nonce}createNewAttribute(j,$){if(typeof $==="string"){this.addAttribute(j,$);return}this.addAttribute(j,$.value||"",$.nonce)}getAIPMessageBuffer(j,$){let J=j.findIndex((z)=>z[0]===h.OP_RETURN),q=[];if(J===-1)q.push([h.OP_RETURN]),J=0;if($)for(let z of $)q.push(j[J+z]);else for(let z of j)q.push(z);return q}formatAIPOutput(j,$,J){let q=[M("|"),M(R),M("BITCOIN_ECDSA"),M($),M(J,"base64")];return[...j,...q]}}var{magicHash:zj}=g;class O extends x{key;idName;description;address;identityKey;constructor(j,$={}){super();this.key=j,this.address=j.toAddress(),this.idName="Member ID 1",this.description="",this.identityKey="",this.identityAttributes=this.parseAttributes($)}signMessage(j,$){let J=this.key,q=J.toAddress(),z=g.sign(j,J,"raw"),Q=new qj(zj(j)),W=z.CalculateRecoveryFactor(J.toPublicKey(),Q),L=g.sign(j,J,"raw").toCompact(W,!0,"base64");return{address:q,signature:L}}signOpReturnWithAIP(j){let $=this.getAIPMessageBuffer(j),{address:J,signature:q}=this.signMessage($.flat());return this.formatAIPOutput($,J,q)}getPublicKey(){return this.key.toPublicKey().toString()}import(j){this.idName=j.name,this.description=j.description,this.key=I.fromWif(j.derivedPrivateKey),this.address=this.key.toAddress(),this.identityAttributes=j.identityAttributes||{},this.identityKey=j.identityKey}static fromMemberIdentity(j){let $=new O(I.fromWif(j.derivedPrivateKey));return $.import(j),$}static fromBackup(j){let $=new O(I.fromWif(j.wif)),J=JSON.parse($.decrypt(j.id));return $.import(J),$}export(){return{name:this.idName,description:this.description,derivedPrivateKey:this.key.toWif(),address:this.address,identityAttributes:this.getAttributes(),identityKey:this.identityKey}}getEncryptionKey(){return{privKey:this.key.deriveChild(this.key.toPublicKey(),Y),pubKey:this.key.deriveChild(this.key.toPublicKey(),Y).toPublicKey()}}getEncryptionPublicKey(){let{pubKey:j}=this.getEncryptionKey();return j.toString()}exportForBackup(j){let $=this.export(),J=this.encrypt(JSON.stringify($));return{wif:this.key.toWif(),id:J,...j&&{label:j},createdAt:new Date().toISOString()}}}var{toArray:X,toHex:V,toBase58:Lj,toUTF8:n,toBase64:v}=Qj,{electrumDecrypt:u,electrumEncrypt:A}=Zj,{magicHash:d}=E;class f extends x{#$;#j;#J;#Q=S;#W="";#q;#Z;#z;#L;idName;description;rootAddress;identityKey;identityAttributes;getApiData;constructor(j,$={},J=""){super();if(j instanceof Wj)if(this.#J=!1,J){let z=V(U.sha256(J,"utf8")),Q=G.getSigningPathFromHex(z);this.#$=j.derive(Q)}else this.#$=j;else if(this.#J=!0,this.#j=j.rootPk,J){let z=V(U.sha256(J,"utf8"));this.#j=this.#j.deriveChild(this.#j.toPublicKey(),z)}if(this.#L=J,this.idName="ID 1",this.description="",this.#q=`${k}/0/0/0`,this.#Z=`${k}/0/0/0`,this.#z=`${k}/0/0/1`,this.#J){if(!this.#j)throw new Error("Master private key not initialized");let z=this.#j.deriveChild(this.#j.toPublicKey(),this.#q);this.rootAddress=z.toPublicKey().toAddress()}else{if(!this.#$)throw new Error("HD private key not initialized");let z=this.#$.derive(this.#q);this.rootAddress=z.privKey.toPublicKey().toAddress()}this.identityKey=this.deriveIdentityKey(this.rootAddress);let q={...$};this.identityAttributes=this.parseAttributes(q),this.getApiData=T(this.#Q,this.#W)}set BAP_SERVER(j){this.#Q=j}get BAP_SERVER(){return this.#Q}set BAP_TOKEN(j){this.#W=j}get BAP_TOKEN(){return this.#W}deriveIdentityKey(j){let $=V(U.sha256(j,"utf8"));return Lj(U.ripemd160($,"hex"))}parseAttributes(j){if(typeof j==="string")return this.parseStringUrns(j);for(let $ in j)if(!j[$].value||!j[$].nonce)throw new Error("Invalid identity attribute");return j||{}}parseStringUrns(j){let $={},J=j.replace(/^\s+/g,"").replace(/\r/gm,"").split(`
5
- `);for(let q of J){let Q=q.replace(/^\s+/g,"").replace(/\s+$/g,"").split(":");if(Q[0]==="urn"&&Q[1]==="bap"&&Q[2]==="id"&&Q[3]&&Q[4]&&Q[5])$[Q[3]]={value:Q[4],nonce:Q[5]}}return $}getIdentityKey(){return this.identityKey}set rootPath(j){if(this.#J){if(this.#q=j,!this.#j)throw new Error("Master private key not initialized");let $=this.#j.deriveChild(this.#j.toPublicKey(),j);this.rootAddress=$.toPublicKey().toAddress(),this.#Z=j,this.#z=j}else{let $=j;if(j.split("/").length<5)$=`${k}${j}`;if(!this.validatePath($))throw new Error(`invalid signing path given ${$}`);if(this.#q=$,!this.#$)throw new Error("HD private key not initialized");let J=this.#$.derive($);this.rootAddress=J.pubKey.toAddress(),this.#Z=$,this.#z=$}this.identityKey=this.deriveIdentityKey(this.rootAddress)}get rootPath(){return this.#q}getRootPath(){return this.#q}set currentPath(j){if(this.#J)this.#Z=this.#z,this.#z=j;else{let $=j;if(j.split("/").length<5)$=`${k}${j}`;if(!this.validatePath($))throw new Error("invalid signing path given");this.#Z=this.#z,this.#z=$}}get currentPath(){return this.#z}get previousPath(){return this.#Z}get idSeed(){return this.#L}incrementPath(){this.currentPath=G.getNextPath(this.currentPath)}validatePath(j){if(j.match(/\/[0-9]{1,10}'?\/[0-9]{1,10}'?\/[0-9]{1,10}'?\/[0-9]{1,10}'?\/[0-9]{1,10}'?\/[0-9]{1,10}'?/)){let $=j.split("/");if($.length===7&&Number($[1].replace("'",""))<=F&&Number($[2].replace("'",""))<=F&&Number($[3].replace("'",""))<=F&&Number($[4].replace("'",""))<=F&&Number($[5].replace("'",""))<=F&&Number($[6].replace("'",""))<=F)return!0}return!1}getInitialIdTransaction(){return this.getIdTransaction(this.#q)}getIdTransaction(j=""){if(this.#z===this.#q)throw new Error("Current path equals rootPath. ID was probably not initialized properly");let $=[X(C),X("ID"),X(this.identityKey),X(this.getCurrentAddress())];return this.signOpReturnWithAIP($,j||this.#Z)}getAddress(j){if(this.#J){if(!this.#j)throw new Error("Master private key not initialized");return this.#j.deriveChild(this.#j.toPublicKey(),j).toPublicKey().toAddress()}if(!this.#$)throw new Error("HD private key not initialized");return this.#$.derive(j).privKey.toPublicKey().toAddress()}getCurrentAddress(){return this.getAddress(this.#z)}getEncryptionKey(){if(this.#J){if(!this.#j)throw new Error("Master private key not initialized");let J=this.#j.deriveChild(this.#j.toPublicKey(),this.#q),q=J.deriveChild(J.toPublicKey(),Y);return{privKey:q,pubKey:q.toPublicKey()}}if(!this.#$)throw new Error("HD private key not initialized");let $=this.#$.derive(this.#q).derive(Y).privKey;return{privKey:$,pubKey:$.toPublicKey()}}getEncryptionKeyType42(){if(this.#J)return this.getEncryptionKey();if(!this.#$)throw new Error("HD private key not initialized");let j=this.#$.derive(this.#q),$=j.privKey.deriveChild(j.toPublic().pubKey,Y);return{privKey:$,pubKey:$.toPublicKey()}}getEncryptionPublicKey(){let{pubKey:j}=this.getEncryptionKey();return j.toString()}getEncryptionPublicKeyWithSeed(j){return this.getEncryptionPrivateKeyWithSeed(j).toPublicKey().toString()}encrypt(j,$){let{privKey:J,pubKey:q}=this.getEncryptionKey(),z=$?H.fromString($):q;return v(A(X(j),z,J))}decrypt(j,$){let{privKey:J}=this.getEncryptionKey(),q;if($)q=H.fromString($);return n(u(X(j,"base64"),J,q))}encryptWithSeed(j,$,J){let q=this.getEncryptionPrivateKeyWithSeed($),z=q.toPublicKey(),Q=J?H.fromString(J):z;return v(A(X(j),Q,q))}decryptWithSeed(j,$,J){let q=this.getEncryptionPrivateKeyWithSeed($),z;if(J)z=H.fromString(J);return n(u(X(j,"base64"),q,z))}getEncryptionPrivateKeyWithSeed(j){let $=V(U.sha256(j,"utf8"));if(this.#J){if(!this.#j)throw new Error("Master private key not initialized");let z=this.#j.deriveChild(this.#j.toPublicKey(),this.#q);return z.deriveChild(z.toPublicKey(),$)}if(!this.#$)throw new Error("HD private key not initialized");let J=G.getSigningPathFromHex($);return this.#$.derive(this.#q).derive(J).privKey}getAttestation(j){let $=U.sha256(j,"utf8");return`bap:attest:${V($)}:${this.getIdentityKey()}`}getAttestationHash(j){let $=this.getAttributeUrn(j);if(!$)return null;let J=this.getAttestation($),q=U.sha256(J,"utf8");return V(q)}signMessage(j,$){let J=$||this.#z,q;if(this.#J){if(!this.#j)throw new Error("Master private key not initialized");q=this.#j.deriveChild(this.#j.toPublicKey(),J)}else{if(!this.#$)throw new Error("HD private key not initialized");q=this.#$.derive(J).privKey}let z=q.toAddress(),Q=E.sign(j,q,"raw"),W=new o(d(j)),L=Q.CalculateRecoveryFactor(q.toPublicKey(),W),w=E.sign(j,q,"raw").toCompact(L,!0,"base64");return{address:z,signature:w}}signMessageWithSeed(j,$){let J=V(U.sha256($,"utf8")),q;if(this.#J){if(!this.#j)throw new Error("Master private key not initialized");let N=this.#j.deriveChild(this.#j.toPublicKey(),this.#q);q=N.deriveChild(N.toPublicKey(),J)}else{if(!this.#$)throw new Error("HD private key not initialized");let N=G.getSigningPathFromHex(J);q=this.#$.derive(this.#q).derive(N).privKey}let z=q.toPublicKey().toAddress(),Q=X(j,"utf8"),W=E.sign(Q,q,"raw"),L=new o(d(Q)),w=W.CalculateRecoveryFactor(q.toPublicKey(),L),B=E.sign(Q,q,"raw").toCompact(w,!0,"base64");return{address:z,signature:B}}signOpReturnWithAIP(j,$=""){let J=this.getAIPMessageBuffer(j),{address:q,signature:z}=this.signMessage(J.flat(),$);return this.formatAIPOutput(j,q,z)}async getIdSigningKeys(){let j=await this.getApiData("/signing-keys",{idKey:this.identityKey});return console.log("getIdSigningKeys",j),j}async getAttributeAttestations(j){let $=this.getAttestationHash(j),J=await this.getApiData("/attestation/get",{hash:$});return console.log("getAttestations",j,$,J),J}import(j){this.idName=j.name,this.description=j.description||"",this.identityKey=j.identityKey,this.#q=j.rootPath,this.rootAddress=j.rootAddress,this.#Z=j.previousPath,this.#z=j.currentPath,this.#L=("idSeed"in j?j.idSeed:"")||"",this.identityAttributes=this.parseAttributes(j.identityAttributes)}export(){return{name:this.idName,description:this.description,identityKey:this.identityKey,rootPath:this.#q,rootAddress:this.rootAddress,previousPath:this.#Z,currentPath:this.#z,idSeed:this.#L,identityAttributes:this.getAttributes(),lastIdPath:""}}exportMemberBackup(){let j;if(this.#J){if(!this.#j)throw new Error("Master private key not initialized");j=this.#j.deriveChild(this.#j.toPublicKey(),this.#z)}else{if(!this.#$)throw new Error("HD private key not initialized");j=this.#$.derive(this.#z).privKey}return{name:this.idName,description:this.description,derivedPrivateKey:j.toWif(),address:j.toPublicKey().toAddress(),identityAttributes:this.getAttributes(),identityKey:this.identityKey}}newId(){this.incrementPath();let j;if(this.#J){if(!this.#j)throw new Error("Master private key not initialized");j=this.#j.deriveChild(this.#j.toPublicKey(),this.#z)}else{if(!this.#$)throw new Error("HD private key not initialized");j=this.#$.derive(this.#z).privKey}return new O(j)}exportMember(){let j=this.exportMemberBackup(),$;if(this.#J){if(!this.#j)throw new Error("Master private key not initialized");$=this.#j.deriveChild(this.#j.toPublicKey(),this.#z)}else{if(!this.#$)throw new Error("HD private key not initialized");$=this.#$.derive(this.#z).privKey}let J=v(A(X(JSON.stringify(j)),$.toPublicKey()));return{wif:j.derivedPrivateKey,encryptedData:J}}}var{toArray:Z,toUTF8:_,toBase64:c,toHex:D}=Cj,{electrumEncrypt:y,electrumDecrypt:s}=Yj;class Uj{#$;#j;#J;#Q={};#W=S;#q="";#Z="";#z=0;getApiData;constructor(j,$="",J=""){if(!j)throw new Error("No key source given");if(typeof j==="string")this.#$=Gj.fromString(j),this.#J=!1;else this.#j=Fj.fromWif(j.rootPk),this.#J=!0;if($)this.#q=$;if(J)this.#W=J;this.getApiData=T(this.#W,this.#q)}get lastIdPath(){return this.#Z}getPublicKey(j=""){if(this.#J){if(!this.#j)throw new Error("Master private key not initialized");if(j)return this.#j.deriveChild(this.#j.toPublicKey(),j).toPublicKey().toString();return this.#j.toPublicKey().toString()}if(!this.#$)throw new Error("HD private key not initialized");if(j)return this.#$.derive(j).pubKey.toString();return this.#$.pubKey.toString()}getHdPublicKey(j=""){if(this.#J)throw new Error("HD public keys are not available in Type 42 mode");if(!this.#$)throw new Error("HD private key not initialized");if(j)return this.#$.derive(j).toPublic().toString();return this.#$.toPublic().toString()}set BAP_SERVER(j){this.#W=j;for(let $ in this.#Q)this.#Q[$].BAP_SERVER=j}get BAP_SERVER(){return this.#W}set BAP_TOKEN(j){this.#q=j;for(let $ in this.#Q)this.#Q[$].BAP_TOKEN=j}get BAP_TOKEN(){return this.#q}checkIdBelongs(j){let $;if(this.#J){if(!this.#j)throw new Error("Master private key not initialized");$=this.#j.deriveChild(this.#j.toPublicKey(),j.rootPath).toPublicKey().toAddress()}else{if(!this.#$)throw new Error("HD private key not initialized");$=this.#$.derive(j.rootPath).pubKey.toAddress()}if($!==j.rootAddress)throw new Error("ID does not belong to this private key");return!0}listIds(){return Object.keys(this.#Q)}newId(j,$,J={},q=""){let z,Q,W;if(typeof j==="object"||j===void 0||typeof j==="string"&&j.startsWith("/"))Q=typeof j==="string"?j:void 0,W=typeof j==="object"?j:typeof $==="object"?$:{},z="Default Identity";else z=j,Q=typeof $==="string"?$:void 0,W=typeof $==="object"?$:J;let L;if(Q)L=Q;else if(this.#J)L=`bap:${this.#z}`,this.#z++;else L=this.getNextValidPath();let w;if(this.#J){if(!this.#j)throw new Error("Type 42 parameters not initialized");w=new f({rootPk:this.#j},W,q)}else{if(!this.#$)throw new Error("HD private key not initialized");w=new f(this.#$,W,q)}if(w.BAP_SERVER=this.#W,w.BAP_TOKEN=this.#q,w.idName=z,w.rootPath=L,this.#J)w.currentPath=L;else w.currentPath=G.getNextPath(L);let B=w.getIdentityKey();return this.#Q[B]=w,this.#Z=L,this.#Q[B]}removeId(j){delete this.#Q[j]}getNextValidPath(){if(this.#Z)return G.getNextIdentityPath(this.#Z);return`/0'/${Object.keys(this.#Q).length}'/0'`}newIdWithCounter(j,$=`Identity ${j}`){if(!this.#J)throw new Error("newIdWithCounter only works in Type 42 mode");let J=`bap:${j}`;return this.newId($,J)}getId(j){return this.#Q[j]||null}setId(j){this.checkIdBelongs(j),this.#Q[j.getIdentityKey()]=j}importIds(j,$=!0){if($&&typeof j==="string"){this.importEncryptedIds(j);return}let J=j;if(!J.lastIdPath)throw new Error("ID cannot be imported as it is not complete");if(!J.ids)throw new Error(`ID data is not in the correct format: ${j}`);let q=j.lastIdPath;for(let z of J.ids){if(!z.identityKey||!z.identityAttributes||!z.rootAddress)throw new Error("ID cannot be imported as it is not complete");let Q;if(this.#J){if(!this.#j)throw new Error("Type 42 parameters not initialized");Q=new f({rootPk:this.#j},{},z.idSeed)}else{if(!this.#$)throw new Error("HD private key not initialized");Q=new f(this.#$,{},z.idSeed)}if(Q.BAP_SERVER=this.#W,Q.BAP_TOKEN=this.#q,Q.import(z),q==="")q=Q.currentPath;if(this.checkIdBelongs(Q),this.#Q[Q.getIdentityKey()]=Q,this.#J&&Q.rootPath.startsWith("bap:")){let W=Q.rootPath.split(":");if(W.length>=2){let L=Number.parseInt(W[1],10);if(!Number.isNaN(L))this.#z=Math.max(this.#z,L+1)}}}this.#Z=q}importEncryptedIds(j){let $=this.decrypt(j),J=JSON.parse($);if(Array.isArray(J)){console.log(`Importing old format:
6
- `,J),this.importOldIds(J);return}if(typeof J!=="object")throw new Error("decrypted, but found unrecognized identities format");this.importIds(J,!1)}importOldIds(j){for(let $ of j){let J;if(this.#J){if(!this.#j)throw new Error("Type 42 parameters not initialized");J=new f({rootPk:this.#j},{},$.idSeed??"")}else{if(!this.#$)throw new Error("HD private key not initialized");J=new f(this.#$,{},$.idSeed??"")}J.BAP_SERVER=this.#W,J.BAP_TOKEN=this.#q,J.import($),this.checkIdBelongs(J),this.#Q[J.getIdentityKey()]=J,this.#Z=J.currentPath}}exportIds(j,$=!0){let J={lastIdPath:this.#Z,ids:[]},q=j||Object.keys(this.#Q);for(let z of q){if(!this.#Q[z])throw new Error(`Identity ${z} not found`);J.ids.push(this.#Q[z].export())}if($)return this.encrypt(JSON.stringify(J));return J}exportId(j,$=!0){let J={lastIdPath:this.#Z,ids:[]};if(J.ids.push(this.#Q[j].export()),$)return this.encrypt(JSON.stringify(J));return J}encrypt(j){if(this.#J){if(!this.#j)throw new Error("Master private key not initialized");let J=this.#j.deriveChild(this.#j.toPublicKey(),Y);return c(y(Z(j),J.toPublicKey(),null))}if(!this.#$)throw new Error("HD private key not initialized");let $=this.#$.derive(Y);return c(y(Z(j),$.pubKey,null))}decrypt(j){if(this.#J){if(!this.#j)throw new Error("Master private key not initialized");let J=this.#j.deriveChild(this.#j.toPublicKey(),Y);return _(s(Z(j,"base64"),J))}if(!this.#$)throw new Error("HD private key not initialized");let $=this.#$.derive(Y);return _(s(Z(j,"base64"),$.privKey))}signAttestationWithAIP(j,$,J=0,q=""){let z=this.getId($);if(!z)throw new Error("Could not find identity to attest with");let Q=this.getAttestationBuffer(j,J,q),{address:W,signature:L}=z.signMessage(Q);return this.createAttestationTransaction(j,J,W,L,q)}verifyAttestationWithAIP(j){if(!j.every((q)=>Array.isArray(q))||j[0][0]!==K.OP_RETURN||D(j[1])!==p)throw new Error("Not a valid BAP transaction");let $=D(j[7])==="44415441"?5:0,J={type:_(j[2]),hash:D(j[3]),sequence:_(j[4]),signingProtocol:_(j[7+$]),signingAddress:_(j[8+$]),signature:c(j[9+$])};if($&&j[3]===j[8])J.data=D(j[9]);console.log({attestation:J});try{let q=[];for(let z=0;z<6+$;z++)q.push(j[z]);J.verified=this.verifySignature(q.flat(),J.signingAddress,J.signature)}catch{J.verified=!1}return J}createAttestationTransaction(j,$,J,q,z=""){let Q=[[K.OP_RETURN],Z(C),Z("ATTEST"),Z(j),Z(`${$}`),Z("|")];if(z)Q.push(Z(C),Z("DATA"),Z(j),Z(z),Z("|"));return Q.push(Z(R),Z("BITCOIN_ECDSA"),Z(J),Z(q,"base64")),console.log({elements:Q}),Q}getAttestationBuffer(j,$=0,J=""){let q=[[K.OP_RETURN],Z(C),Z("ATTEST"),Z(j),Z(`${$}`),Z("|")];if(J)q.push(Z(C),Z("DATA"),Z(j),Z(J),Z("|"));return q.flat()}verifySignature(j,$,J){let q;if(Array.isArray(j))q=j;else if(Buffer.isBuffer(j))q=[...j];else q=Z(j,"utf8");let z=Xj.fromCompact(J,"base64"),Q;for(let W=0;W<4;W++)try{if(Q=z.RecoverPublicKey(W,new wj(l.magicHash(q))),l.verify(q,z,Q)&&Q.toAddress()===$)return!0}catch{}return!1}async verifyChallengeSignature(j,$,J,q){if(!this.verifySignature(J,$,q))return!1;try{let Q=await this.getApiData("/attestation/valid",{idKey:j,address:$,challenge:J,signature:q});if(Q?.status==="success"&&Q?.result?.valid===!0)return!0;return!1}catch(Q){return console.error("API call failed:",Q),!1}}async isValidAttestationTransaction(j){if(this.verifyAttestationWithAIP(j))return this.getApiData("/attestation/valid",{tx:j});return!1}async getIdentityFromAddress(j){return this.getApiData("/identity/from-address",{address:j})}async getIdentity(j){return this.getApiData("/identity/get",{idKey:j})}async getAttestationsForHash(j){return this.getApiData("/attestations",{hash:j})}exportForBackup(j,$,J){let z={ids:this.exportIds(),...j&&{label:j},createdAt:new Date().toISOString()};if(this.#J){if(!this.#j)throw new Error("Type 42 parameters not initialized");return{...z,rootPk:this.#j.toWif()}}if(!this.#$)throw new Error("HD private key not initialized");return{...z,xprv:$||this.#$.toString(),mnemonic:J||""}}exportMemberForBackup(j,$){let J=this.#Q[j];if(!J)throw new Error(`Identity ${j} not found`);let q=J.exportMember();return{wif:q.wif,id:q.encryptedData,...$&&{label:$},createdAt:new Date().toISOString()}}}export{O as MemberID,f as MasterID,Uj as BAP};
4
+ `);for(let q of J){let Q=q.replace(/^\s+/g,"").replace(/\s+$/g,"").split(":");if(Q[0]==="urn"&&Q[1]==="bap"&&Q[2]==="id"&&Q[3]&&Q[4]&&Q[5])$[Q[3]]={value:Q[4],nonce:Q[5]}}return $}parseAttributes(j){if(typeof j==="string")return this.parseStringUrns(j);for(let $ in j)if(!j[$].value||!j[$].nonce)throw Error("Invalid identity attribute");return j||{}}updateExistingAttribute(j,$){if(typeof $==="string"){this.identityAttributes[j].value=$;return}if(this.identityAttributes[j].value=$.value||"",$.nonce)this.identityAttributes[j].nonce=$.nonce}createNewAttribute(j,$){if(typeof $==="string"){this.addAttribute(j,$);return}this.addAttribute(j,$.value||"",$.nonce)}getAIPMessageBuffer(j,$){let J=j.findIndex((z)=>z[0]===h.OP_RETURN),q=[];if(J===-1)q.push([h.OP_RETURN]),J=0;if($)for(let z of $)q.push(j[J+z]);else for(let z of j)q.push(z);return q}formatAIPOutput(j,$,J){let q=[M("|"),M(R),M("BITCOIN_ECDSA"),M($),M(J,"base64")];return[...j,...q]}}var{magicHash:wj}=g,{toArray:P,toUTF8:Yj,toBase64:Gj,toHex:Xj}=Wj,{electrumDecrypt:Fj,electrumEncrypt:Cj}=Lj;class O extends x{key;idName;description;address;identityKey;constructor(j,$={}){super();this.key=j,this.address=j.toAddress(),this.idName="Member ID 1",this.description="",this.identityKey="",this.identityAttributes=this.parseAttributes($)}signMessage(j,$){let J=this.key,q=J.toAddress(),z=g.sign(j,J,"raw"),Q=new Qj(wj(j)),W=z.CalculateRecoveryFactor(J.toPublicKey(),Q),L=g.sign(j,J,"raw").toCompact(W,!0,"base64");return{address:q,signature:L}}signOpReturnWithAIP(j){let $=this.getAIPMessageBuffer(j),{address:J,signature:q}=this.signMessage($.flat());return this.formatAIPOutput($,J,q)}getPublicKey(){return this.key.toPublicKey().toString()}import(j){this.idName=j.name,this.description=j.description,this.key=I.fromWif(j.derivedPrivateKey),this.address=this.key.toAddress(),this.identityAttributes=j.identityAttributes||{},this.identityKey=j.identityKey}static fromMemberIdentity(j){let $=new O(I.fromWif(j.derivedPrivateKey));return $.import(j),$}static fromBackup(j){let $=new O(I.fromWif(j.wif)),J=JSON.parse($.decrypt(j.id));return $.import(J),$}export(){return{name:this.idName,description:this.description,derivedPrivateKey:this.key.toWif(),address:this.address,identityAttributes:this.getAttributes(),identityKey:this.identityKey}}getEncryptionKey(){return{privKey:this.key.deriveChild(this.key.toPublicKey(),Y),pubKey:this.key.deriveChild(this.key.toPublicKey(),Y).toPublicKey()}}getEncryptionPublicKey(){let{pubKey:j}=this.getEncryptionKey();return j.toString()}getEncryptionPrivateKeyWithSeed(j){let $=Xj(Zj.sha256(j,"utf8"));return this.key.deriveChild(this.key.toPublicKey(),$)}getEncryptionKeyWithSeed(j){let $=this.getEncryptionPrivateKeyWithSeed(j);return{privKey:$,pubKey:$.toPublicKey()}}getEncryptionPublicKeyWithSeed(j){return this.getEncryptionPrivateKeyWithSeed(j).toPublicKey().toString()}encryptWithSeed(j,$,J){let q=this.getEncryptionPrivateKeyWithSeed($),z=q.toPublicKey(),Q=this.key.toPublicKey().constructor,W=J?Q.fromString(J):z;return Gj(Cj(P(j),W,q))}decryptWithSeed(j,$,J){let q=this.getEncryptionPrivateKeyWithSeed($),z;if(J)z=zj.fromString(J);return Yj(Fj(P(j,"base64"),q,z))}exportForBackup(j){let $=this.export(),J=this.encrypt(JSON.stringify($));return{wif:this.key.toWif(),id:J,...j&&{label:j},createdAt:new Date().toISOString()}}}var{toArray:X,toHex:V,toBase58:Vj,toUTF8:u,toBase64:v}=fj,{electrumDecrypt:d,electrumEncrypt:A}=Uj,{magicHash:y}=E;class U extends x{#$;#j;#J;#Q=S;#W="";#q;#Z;#z;#L;idName;description;rootAddress;identityKey;identityAttributes;getApiData;constructor(j,$={},J=""){super();if(j instanceof Mj)if(this.#J=!1,J){let z=V(f.sha256(J,"utf8")),Q=G.getSigningPathFromHex(z);this.#$=j.derive(Q)}else this.#$=j;else if(this.#J=!0,this.#j=j.rootPk,J){let z=V(f.sha256(J,"utf8"));this.#j=this.#j.deriveChild(this.#j.toPublicKey(),z)}if(this.#L=J,this.idName="ID 1",this.description="",this.#q=`${k}/0/0/0`,this.#Z=`${k}/0/0/0`,this.#z=`${k}/0/0/1`,this.#J){if(!this.#j)throw Error("Master private key not initialized");let z=this.#j.deriveChild(this.#j.toPublicKey(),this.#q);this.rootAddress=z.toPublicKey().toAddress()}else{if(!this.#$)throw Error("HD private key not initialized");let z=this.#$.derive(this.#q);this.rootAddress=z.privKey.toPublicKey().toAddress()}this.identityKey=this.deriveIdentityKey(this.rootAddress);let q={...$};this.identityAttributes=this.parseAttributes(q),this.getApiData=T(this.#Q,this.#W)}set BAP_SERVER(j){this.#Q=j}get BAP_SERVER(){return this.#Q}set BAP_TOKEN(j){this.#W=j}get BAP_TOKEN(){return this.#W}deriveIdentityKey(j){let $=V(f.sha256(j,"utf8"));return Vj(f.ripemd160($,"hex"))}parseAttributes(j){if(typeof j==="string")return this.parseStringUrns(j);for(let $ in j)if(!j[$].value||!j[$].nonce)throw Error("Invalid identity attribute");return j||{}}parseStringUrns(j){let $={},J=j.replace(/^\s+/g,"").replace(/\r/gm,"").split(`
5
+ `);for(let q of J){let Q=q.replace(/^\s+/g,"").replace(/\s+$/g,"").split(":");if(Q[0]==="urn"&&Q[1]==="bap"&&Q[2]==="id"&&Q[3]&&Q[4]&&Q[5])$[Q[3]]={value:Q[4],nonce:Q[5]}}return $}getIdentityKey(){return this.identityKey}set rootPath(j){if(this.#J){if(this.#q=j,!this.#j)throw Error("Master private key not initialized");let $=this.#j.deriveChild(this.#j.toPublicKey(),j);this.rootAddress=$.toPublicKey().toAddress(),this.#Z=j,this.#z=j}else{let $=j;if(j.split("/").length<5)$=`${k}${j}`;if(!this.validatePath($))throw Error(`invalid signing path given ${$}`);if(this.#q=$,!this.#$)throw Error("HD private key not initialized");let J=this.#$.derive($);this.rootAddress=J.pubKey.toAddress(),this.#Z=$,this.#z=$}this.identityKey=this.deriveIdentityKey(this.rootAddress)}get rootPath(){return this.#q}getRootPath(){return this.#q}set currentPath(j){if(this.#J)this.#Z=this.#z,this.#z=j;else{let $=j;if(j.split("/").length<5)$=`${k}${j}`;if(!this.validatePath($))throw Error("invalid signing path given");this.#Z=this.#z,this.#z=$}}get currentPath(){return this.#z}get previousPath(){return this.#Z}get idSeed(){return this.#L}incrementPath(){this.currentPath=G.getNextPath(this.currentPath)}validatePath(j){if(j.match(/\/[0-9]{1,10}'?\/[0-9]{1,10}'?\/[0-9]{1,10}'?\/[0-9]{1,10}'?\/[0-9]{1,10}'?\/[0-9]{1,10}'?/)){let $=j.split("/");if($.length===7&&Number($[1].replace("'",""))<=F&&Number($[2].replace("'",""))<=F&&Number($[3].replace("'",""))<=F&&Number($[4].replace("'",""))<=F&&Number($[5].replace("'",""))<=F&&Number($[6].replace("'",""))<=F)return!0}return!1}getInitialIdTransaction(){return this.getIdTransaction(this.#q)}getIdTransaction(j=""){if(this.#z===this.#q)throw Error("Current path equals rootPath. ID was probably not initialized properly");let $=[X(C),X("ID"),X(this.identityKey),X(this.getCurrentAddress())];return this.signOpReturnWithAIP($,j||this.#Z)}getAddress(j){if(this.#J){if(!this.#j)throw Error("Master private key not initialized");return this.#j.deriveChild(this.#j.toPublicKey(),j).toPublicKey().toAddress()}if(!this.#$)throw Error("HD private key not initialized");return this.#$.derive(j).privKey.toPublicKey().toAddress()}getCurrentAddress(){return this.getAddress(this.#z)}getEncryptionKey(){if(this.#J){if(!this.#j)throw Error("Master private key not initialized");let J=this.#j.deriveChild(this.#j.toPublicKey(),this.#q),q=J.deriveChild(J.toPublicKey(),Y);return{privKey:q,pubKey:q.toPublicKey()}}if(!this.#$)throw Error("HD private key not initialized");let $=this.#$.derive(this.#q).derive(Y).privKey;return{privKey:$,pubKey:$.toPublicKey()}}getEncryptionKeyType42(){if(this.#J)return this.getEncryptionKey();if(!this.#$)throw Error("HD private key not initialized");let j=this.#$.derive(this.#q),$=j.privKey.deriveChild(j.toPublic().pubKey,Y);return{privKey:$,pubKey:$.toPublicKey()}}getEncryptionPublicKey(){let{pubKey:j}=this.getEncryptionKey();return j.toString()}getEncryptionPublicKeyWithSeed(j){return this.getEncryptionPrivateKeyWithSeed(j).toPublicKey().toString()}encrypt(j,$){let{privKey:J,pubKey:q}=this.getEncryptionKey(),z=$?H.fromString($):q;return v(A(X(j),z,J))}decrypt(j,$){let{privKey:J}=this.getEncryptionKey(),q;if($)q=H.fromString($);return u(d(X(j,"base64"),J,q))}encryptWithSeed(j,$,J){let q=this.getEncryptionPrivateKeyWithSeed($),z=q.toPublicKey(),Q=J?H.fromString(J):z;return v(A(X(j),Q,q))}decryptWithSeed(j,$,J){let q=this.getEncryptionPrivateKeyWithSeed($),z;if(J)z=H.fromString(J);return u(d(X(j,"base64"),q,z))}getEncryptionPrivateKeyWithSeed(j){let $=V(f.sha256(j,"utf8"));if(this.#J){if(!this.#j)throw Error("Master private key not initialized");let z=this.#j.deriveChild(this.#j.toPublicKey(),this.#q);return z.deriveChild(z.toPublicKey(),$)}if(!this.#$)throw Error("HD private key not initialized");let J=G.getSigningPathFromHex($);return this.#$.derive(this.#q).derive(J).privKey}getAttestation(j){let $=f.sha256(j,"utf8");return`bap:attest:${V($)}:${this.getIdentityKey()}`}getAttestationHash(j){let $=this.getAttributeUrn(j);if(!$)return null;let J=this.getAttestation($),q=f.sha256(J,"utf8");return V(q)}signMessage(j,$){let J=$||this.#z,q;if(this.#J){if(!this.#j)throw Error("Master private key not initialized");q=this.#j.deriveChild(this.#j.toPublicKey(),J)}else{if(!this.#$)throw Error("HD private key not initialized");q=this.#$.derive(J).privKey}let z=q.toAddress(),Q=E.sign(j,q,"raw"),W=new n(y(j)),L=Q.CalculateRecoveryFactor(q.toPublicKey(),W),w=E.sign(j,q,"raw").toCompact(L,!0,"base64");return{address:z,signature:w}}signMessageWithSeed(j,$){let J=V(f.sha256($,"utf8")),q;if(this.#J){if(!this.#j)throw Error("Master private key not initialized");let N=this.#j.deriveChild(this.#j.toPublicKey(),this.#q);q=N.deriveChild(N.toPublicKey(),J)}else{if(!this.#$)throw Error("HD private key not initialized");let N=G.getSigningPathFromHex(J);q=this.#$.derive(this.#q).derive(N).privKey}let z=q.toPublicKey().toAddress(),Q=X(j,"utf8"),W=E.sign(Q,q,"raw"),L=new n(y(Q)),w=W.CalculateRecoveryFactor(q.toPublicKey(),L),B=E.sign(Q,q,"raw").toCompact(w,!0,"base64");return{address:z,signature:B}}signOpReturnWithAIP(j,$=""){let J=this.getAIPMessageBuffer(j),{address:q,signature:z}=this.signMessage(J.flat(),$);return this.formatAIPOutput(j,q,z)}async getIdSigningKeys(){let j=await this.getApiData("/signing-keys",{idKey:this.identityKey});return console.log("getIdSigningKeys",j),j}async getAttributeAttestations(j){let $=this.getAttestationHash(j),J=await this.getApiData("/attestation/get",{hash:$});return console.log("getAttestations",j,$,J),J}import(j){this.idName=j.name,this.description=j.description||"",this.identityKey=j.identityKey,this.#q=j.rootPath,this.rootAddress=j.rootAddress,this.#Z=j.previousPath,this.#z=j.currentPath,this.#L=("idSeed"in j?j.idSeed:"")||"",this.identityAttributes=this.parseAttributes(j.identityAttributes)}export(){return{name:this.idName,description:this.description,identityKey:this.identityKey,rootPath:this.#q,rootAddress:this.rootAddress,previousPath:this.#Z,currentPath:this.#z,idSeed:this.#L,identityAttributes:this.getAttributes(),lastIdPath:""}}exportMemberBackup(){let j;if(this.#J){if(!this.#j)throw Error("Master private key not initialized");j=this.#j.deriveChild(this.#j.toPublicKey(),this.#z)}else{if(!this.#$)throw Error("HD private key not initialized");j=this.#$.derive(this.#z).privKey}return{name:this.idName,description:this.description,derivedPrivateKey:j.toWif(),address:j.toPublicKey().toAddress(),identityAttributes:this.getAttributes(),identityKey:this.identityKey}}newId(){this.incrementPath();let j;if(this.#J){if(!this.#j)throw Error("Master private key not initialized");j=this.#j.deriveChild(this.#j.toPublicKey(),this.#z)}else{if(!this.#$)throw Error("HD private key not initialized");j=this.#$.derive(this.#z).privKey}return new O(j)}exportMember(){let j=this.exportMemberBackup(),$;if(this.#J){if(!this.#j)throw Error("Master private key not initialized");$=this.#j.deriveChild(this.#j.toPublicKey(),this.#z)}else{if(!this.#$)throw Error("HD private key not initialized");$=this.#$.derive(this.#z).privKey}let J=v(A(X(JSON.stringify(j)),$.toPublicKey()));return{wif:j.derivedPrivateKey,encryptedData:J}}}var{toArray:Z,toUTF8:_,toBase64:c,toHex:D}=Ej,{electrumEncrypt:s,electrumDecrypt:i}=Oj;class Bj{#$;#j;#J;#Q={};#W=S;#q="";#Z="";#z=0;getApiData;constructor(j,$="",J=""){if(!j)throw Error("No key source given");if(typeof j==="string")this.#$=_j.fromString(j),this.#J=!1;else this.#j=xj.fromWif(j.rootPk),this.#J=!0;if($)this.#q=$;if(J)this.#W=J;this.getApiData=T(this.#W,this.#q)}get lastIdPath(){return this.#Z}getPublicKey(j=""){if(this.#J){if(!this.#j)throw Error("Master private key not initialized");if(j)return this.#j.deriveChild(this.#j.toPublicKey(),j).toPublicKey().toString();return this.#j.toPublicKey().toString()}if(!this.#$)throw Error("HD private key not initialized");if(j)return this.#$.derive(j).pubKey.toString();return this.#$.pubKey.toString()}getHdPublicKey(j=""){if(this.#J)throw Error("HD public keys are not available in Type 42 mode");if(!this.#$)throw Error("HD private key not initialized");if(j)return this.#$.derive(j).toPublic().toString();return this.#$.toPublic().toString()}set BAP_SERVER(j){this.#W=j;for(let $ in this.#Q)this.#Q[$].BAP_SERVER=j}get BAP_SERVER(){return this.#W}set BAP_TOKEN(j){this.#q=j;for(let $ in this.#Q)this.#Q[$].BAP_TOKEN=j}get BAP_TOKEN(){return this.#q}checkIdBelongs(j){let $;if(this.#J){if(!this.#j)throw Error("Master private key not initialized");$=this.#j.deriveChild(this.#j.toPublicKey(),j.rootPath).toPublicKey().toAddress()}else{if(!this.#$)throw Error("HD private key not initialized");$=this.#$.derive(j.rootPath).pubKey.toAddress()}if($!==j.rootAddress)throw Error("ID does not belong to this private key");return!0}listIds(){return Object.keys(this.#Q)}newId(j,$,J={},q=""){let z,Q,W;if(typeof j==="object"||j===void 0||typeof j==="string"&&j.startsWith("/"))Q=typeof j==="string"?j:void 0,W=typeof j==="object"?j:typeof $==="object"?$:{},z="Default Identity";else z=j,Q=typeof $==="string"?$:void 0,W=typeof $==="object"?$:J;let L;if(Q)L=Q;else if(this.#J)L=`bap:${this.#z}`,this.#z++;else L=this.getNextValidPath();let w;if(this.#J){if(!this.#j)throw Error("Type 42 parameters not initialized");w=new U({rootPk:this.#j},W,q)}else{if(!this.#$)throw Error("HD private key not initialized");w=new U(this.#$,W,q)}if(w.BAP_SERVER=this.#W,w.BAP_TOKEN=this.#q,w.idName=z,w.rootPath=L,this.#J)w.currentPath=L;else w.currentPath=G.getNextPath(L);let B=w.getIdentityKey();return this.#Q[B]=w,this.#Z=L,this.#Q[B]}removeId(j){delete this.#Q[j]}getNextValidPath(){if(this.#Z)return G.getNextIdentityPath(this.#Z);return`/0'/${Object.keys(this.#Q).length}'/0'`}newIdWithCounter(j,$=`Identity ${j}`){if(!this.#J)throw Error("newIdWithCounter only works in Type 42 mode");let J=`bap:${j}`;return this.newId($,J)}getId(j){return this.#Q[j]||null}setId(j){this.checkIdBelongs(j),this.#Q[j.getIdentityKey()]=j}importIds(j,$=!0){if($&&typeof j==="string"){this.importEncryptedIds(j);return}let J=j;if(!J.lastIdPath)throw Error("ID cannot be imported as it is not complete");if(!J.ids)throw Error(`ID data is not in the correct format: ${j}`);let q=j.lastIdPath;for(let z of J.ids){if(!z.identityKey||!z.identityAttributes||!z.rootAddress)throw Error("ID cannot be imported as it is not complete");let Q;if(this.#J){if(!this.#j)throw Error("Type 42 parameters not initialized");Q=new U({rootPk:this.#j},{},z.idSeed)}else{if(!this.#$)throw Error("HD private key not initialized");Q=new U(this.#$,{},z.idSeed)}if(Q.BAP_SERVER=this.#W,Q.BAP_TOKEN=this.#q,Q.import(z),q==="")q=Q.currentPath;if(this.checkIdBelongs(Q),this.#Q[Q.getIdentityKey()]=Q,this.#J&&Q.rootPath.startsWith("bap:")){let W=Q.rootPath.split(":");if(W.length>=2){let L=Number.parseInt(W[1],10);if(!Number.isNaN(L))this.#z=Math.max(this.#z,L+1)}}}this.#Z=q}importEncryptedIds(j){let $=this.decrypt(j),J=JSON.parse($);if(Array.isArray(J)){console.log(`Importing old format:
6
+ `,J),this.importOldIds(J);return}if(typeof J!=="object")throw Error("decrypted, but found unrecognized identities format");this.importIds(J,!1)}importOldIds(j){for(let $ of j){let J;if(this.#J){if(!this.#j)throw Error("Type 42 parameters not initialized");J=new U({rootPk:this.#j},{},$.idSeed??"")}else{if(!this.#$)throw Error("HD private key not initialized");J=new U(this.#$,{},$.idSeed??"")}J.BAP_SERVER=this.#W,J.BAP_TOKEN=this.#q,J.import($),this.checkIdBelongs(J),this.#Q[J.getIdentityKey()]=J,this.#Z=J.currentPath}}exportIds(j,$=!0){let J={lastIdPath:this.#Z,ids:[]},q=j||Object.keys(this.#Q);for(let z of q){if(!this.#Q[z])throw Error(`Identity ${z} not found`);J.ids.push(this.#Q[z].export())}if($)return this.encrypt(JSON.stringify(J));return J}exportId(j,$=!0){let J={lastIdPath:this.#Z,ids:[]};if(J.ids.push(this.#Q[j].export()),$)return this.encrypt(JSON.stringify(J));return J}encrypt(j){if(this.#J){if(!this.#j)throw Error("Master private key not initialized");let J=this.#j.deriveChild(this.#j.toPublicKey(),Y);return c(s(Z(j),J.toPublicKey(),null))}if(!this.#$)throw Error("HD private key not initialized");let $=this.#$.derive(Y);return c(s(Z(j),$.pubKey,null))}decrypt(j){if(this.#J){if(!this.#j)throw Error("Master private key not initialized");let J=this.#j.deriveChild(this.#j.toPublicKey(),Y);return _(i(Z(j,"base64"),J))}if(!this.#$)throw Error("HD private key not initialized");let $=this.#$.derive(Y);return _(i(Z(j,"base64"),$.privKey))}signAttestationWithAIP(j,$,J=0,q=""){let z=this.getId($);if(!z)throw Error("Could not find identity to attest with");let Q=this.getAttestationBuffer(j,J,q),{address:W,signature:L}=z.signMessage(Q);return this.createAttestationTransaction(j,J,W,L,q)}verifyAttestationWithAIP(j){if(!j.every((q)=>Array.isArray(q))||j[0][0]!==K.OP_RETURN||D(j[1])!==p)throw Error("Not a valid BAP transaction");let $=D(j[7])==="44415441"?5:0,J={type:_(j[2]),hash:D(j[3]),sequence:_(j[4]),signingProtocol:_(j[7+$]),signingAddress:_(j[8+$]),signature:c(j[9+$])};if($&&j[3]===j[8])J.data=D(j[9]);console.log({attestation:J});try{let q=[];for(let z=0;z<6+$;z++)q.push(j[z]);J.verified=this.verifySignature(q.flat(),J.signingAddress,J.signature)}catch{J.verified=!1}return J}createAttestationTransaction(j,$,J,q,z=""){let Q=[[K.OP_RETURN],Z(C),Z("ATTEST"),Z(j),Z(`${$}`),Z("|")];if(z)Q.push(Z(C),Z("DATA"),Z(j),Z(z),Z("|"));return Q.push(Z(R),Z("BITCOIN_ECDSA"),Z(J),Z(q,"base64")),console.log({elements:Q}),Q}getAttestationBuffer(j,$=0,J=""){let q=[[K.OP_RETURN],Z(C),Z("ATTEST"),Z(j),Z(`${$}`),Z("|")];if(J)q.push(Z(C),Z("DATA"),Z(j),Z(J),Z("|"));return q.flat()}verifySignature(j,$,J){let q;if(Array.isArray(j))q=j;else if(Buffer.isBuffer(j))q=[...j];else q=Z(j,"utf8");let z=Rj.fromCompact(J,"base64"),Q;for(let W=0;W<4;W++)try{if(Q=z.RecoverPublicKey(W,new kj(l.magicHash(q))),l.verify(q,z,Q)&&Q.toAddress()===$)return!0}catch{}return!1}async verifyChallengeSignature(j,$,J,q){if(!this.verifySignature(J,$,q))return!1;try{let Q=await this.getApiData("/attestation/valid",{idKey:j,address:$,challenge:J,signature:q});if(Q?.status==="success"&&Q?.result?.valid===!0)return!0;return!1}catch(Q){return console.error("API call failed:",Q),!1}}async isValidAttestationTransaction(j){if(this.verifyAttestationWithAIP(j))return this.getApiData("/attestation/valid",{tx:j});return!1}async getIdentityFromAddress(j){return this.getApiData("/identity/from-address",{address:j})}async getIdentity(j){return this.getApiData("/identity/get",{idKey:j})}async getAttestationsForHash(j){return this.getApiData("/attestations",{hash:j})}exportForBackup(j,$,J){let z={ids:this.exportIds(),...j&&{label:j},createdAt:new Date().toISOString()};if(this.#J){if(!this.#j)throw Error("Type 42 parameters not initialized");return{...z,rootPk:this.#j.toWif()}}if(!this.#$)throw Error("HD private key not initialized");return{...z,xprv:$||this.#$.toString(),mnemonic:J||""}}exportMemberForBackup(j,$){let J=this.#Q[j];if(!J)throw Error(`Identity ${j} not found`);let q=J.exportMember();return{wif:q.wif,id:q.encryptedData,...$&&{label:$},createdAt:new Date().toISOString()}}}export{O as MemberID,U as MasterID,Bj as BAP};
7
7
 
8
- //# debugId=11C73009967D3CA164756E2164756E21
8
+ //# debugId=4BA596E1716B79D264756E2164756E21
@@ -7,10 +7,10 @@
7
7
  "import { Utils } from \"@bsv/sdk\";\nconst { toHex, toArray } = Utils;\n\nexport const BAP_BITCOM_ADDRESS = \"1BAPSuaPnfGnSBM3GLV9yhxUdYe4vGbdMT\";\nexport const BAP_BITCOM_ADDRESS_HEX = toHex(toArray(BAP_BITCOM_ADDRESS));\nexport const AIP_BITCOM_ADDRESS = \"15PciHG22SNLQJXMoSUaWVi7WSqc7hCfva\";\nexport const AIP_BITCOM_ADDRESS_HEX = toHex(toArray(AIP_BITCOM_ADDRESS));\nexport const BAP_SERVER = \"https://api.sigmaidentity.com/v1\";\nexport const MAX_INT = 2147483648 - 1; // 0x80000000\n\n// This is just a choice for this library and could be anything else if so needed/wanted\n// but it is advisable to use the same derivation between libraries for compatibility\nexport const SIGNING_PATH_PREFIX = \"m/424150'/0'/0'\"; // BAP in hex\nexport const ENCRYPTION_PATH = `m/424150'/${MAX_INT}'/${MAX_INT}'`;\n",
8
8
  "import {\n BSM,\n Utils as BSVUtils,\n ECIES,\n Hash,\n PublicKey,\n type PrivateKey,\n BigNumber,\n HD,\n} from \"@bsv/sdk\";\nimport type { Signature } from \"@bsv/sdk\";\n\nimport { type APIFetcher, apiFetcher } from \"./api\";\nimport type {\n GetAttestationResponse,\n GetSigningKeysResponse,\n} from \"./apiTypes\";\nimport {\n BAP_BITCOM_ADDRESS,\n BAP_SERVER,\n ENCRYPTION_PATH,\n MAX_INT,\n SIGNING_PATH_PREFIX,\n} from \"./constants\";\nimport type {\n Identity,\n IdentityAttributes,\n OldIdentity,\n MemberIdentity,\n} from \"./interface\";\nimport { Utils } from \"./utils\";\nimport { MemberID } from \"./MemberID\";\nimport { BaseClass } from \"./BaseClass\";\nconst { toArray, toHex, toBase58, toUTF8, toBase64 } = BSVUtils;\nconst { electrumDecrypt, electrumEncrypt } = ECIES;\nconst { magicHash } = BSM;\n\n// Type 42 key source\ninterface Type42KeySource {\n rootPk: PrivateKey;\n}\n\n/**\n * MasterID class\n *\n * This class should be used in conjunction with the BAP class\n * Supports both BIP32 (HD) and Type 42 key derivation\n *\n * @type {MasterID}\n */\nclass MasterID extends BaseClass {\n #HDPrivateKey: HD | undefined;\n #masterPrivateKey: PrivateKey | undefined;\n #isType42: boolean;\n #BAP_SERVER: string = BAP_SERVER;\n #BAP_TOKEN = \"\";\n #rootPath: string;\n #previousPath: string;\n #currentPath: string;\n #idSeed: string;\n\n idName: string;\n description: string;\n\n rootAddress: string;\n identityKey: string;\n identityAttributes: IdentityAttributes;\n\n getApiData: APIFetcher;\n\n constructor(\n keySource: HD | Type42KeySource,\n identityAttributes: IdentityAttributes = {},\n idSeed = \"\"\n ) {\n super();\n\n // Determine if we're using Type 42 or BIP32\n if (keySource instanceof HD) {\n // BIP32 mode\n this.#isType42 = false;\n if (idSeed) {\n // create a new HDPrivateKey based on the seed\n const seedHex = toHex(Hash.sha256(idSeed, \"utf8\"));\n const seedPath = Utils.getSigningPathFromHex(seedHex);\n this.#HDPrivateKey = keySource.derive(seedPath);\n } else {\n this.#HDPrivateKey = keySource;\n }\n } else {\n // Type 42 mode\n this.#isType42 = true;\n this.#masterPrivateKey = keySource.rootPk;\n \n if (idSeed) {\n // For Type 42 with seed, we derive a new master key using the seed as invoice number\n const seedHex = toHex(Hash.sha256(idSeed, \"utf8\"));\n this.#masterPrivateKey = this.#masterPrivateKey.deriveChild(\n this.#masterPrivateKey.toPublicKey(),\n seedHex\n );\n }\n }\n\n this.#idSeed = idSeed;\n this.idName = \"ID 1\";\n this.description = \"\";\n\n this.#rootPath = `${SIGNING_PATH_PREFIX}/0/0/0`;\n this.#previousPath = `${SIGNING_PATH_PREFIX}/0/0/0`;\n this.#currentPath = `${SIGNING_PATH_PREFIX}/0/0/1`;\n\n // Derive root address based on mode\n if (this.#isType42) {\n if (!this.#masterPrivateKey) throw new Error(\"Master private key not initialized\");\n // In Type 42, we use the path as invoice number\n const rootKey = this.#masterPrivateKey.deriveChild(\n this.#masterPrivateKey.toPublicKey(),\n this.#rootPath\n );\n this.rootAddress = rootKey.toPublicKey().toAddress();\n } else {\n if (!this.#HDPrivateKey) throw new Error(\"HD private key not initialized\");\n const rootChild = this.#HDPrivateKey.derive(this.#rootPath);\n this.rootAddress = rootChild.privKey.toPublicKey().toAddress();\n }\n \n this.identityKey = this.deriveIdentityKey(this.rootAddress);\n\n // unlink the object\n const attributes = { ...identityAttributes };\n this.identityAttributes = this.parseAttributes(attributes);\n\n this.getApiData = apiFetcher(this.#BAP_SERVER, this.#BAP_TOKEN);\n }\n\n set BAP_SERVER(bapServer) {\n this.#BAP_SERVER = bapServer;\n }\n\n get BAP_SERVER(): string {\n return this.#BAP_SERVER;\n }\n\n set BAP_TOKEN(token) {\n this.#BAP_TOKEN = token;\n }\n\n get BAP_TOKEN(): string {\n return this.#BAP_TOKEN;\n }\n\n deriveIdentityKey(address: string): string {\n // base58( ripemd160 ( sha256 ( rootAddress ) ) )\n const rootAddressHash = toHex(Hash.sha256(address, \"utf8\"));\n return toBase58(Hash.ripemd160(rootAddressHash, \"hex\"));\n }\n\n /**\n * Helper function to parse identity attributes\n *\n * @param identityAttributes\n * @returns {{}}\n */\n parseAttributes(\n identityAttributes: IdentityAttributes | string\n ): IdentityAttributes {\n if (typeof identityAttributes === \"string\") {\n return this.parseStringUrns(identityAttributes);\n }\n\n for (const key in identityAttributes) {\n if (!identityAttributes[key].value || !identityAttributes[key].nonce) {\n throw new Error(\"Invalid identity attribute\");\n }\n }\n\n return identityAttributes || {};\n }\n\n /**\n * Parse a text of urn string into identity attributes\n *\n * urn:bap:id:name:John Doe:e2c6fb4063cc04af58935737eaffc938011dff546d47b7fbb18ed346f8c4d4fa\n * urn:bap:id:birthday:1990-05-22:e61f23cbbb2284842d77965e2b0e32f0ca890b1894ca4ce652831347ee3596d9\n * urn:bap:id:over18:1:480ca17ccaacd671b28dc811332525f2f2cd594d8e8e7825de515ce5d52d30e8\n *\n * @param urnIdentityAttributes\n */\n parseStringUrns(urnIdentityAttributes: string): IdentityAttributes {\n const identityAttributes: IdentityAttributes = {};\n // avoid forEach\n\n const attributesRaw = urnIdentityAttributes\n .replace(/^\\s+/g, \"\")\n .replace(/\\r/gm, \"\")\n .split(\"\\n\");\n\n for (const line of attributesRaw) {\n // remove any whitespace from the string (trim)\n const attribute = line.replace(/^\\s+/g, \"\").replace(/\\s+$/g, \"\");\n const urn = attribute.split(\":\");\n if (\n urn[0] === \"urn\" &&\n urn[1] === \"bap\" &&\n urn[2] === \"id\" &&\n urn[3] &&\n urn[4] &&\n urn[5]\n ) {\n identityAttributes[urn[3]] = {\n value: urn[4],\n nonce: urn[5],\n };\n }\n }\n\n return identityAttributes;\n }\n\n /**\n * Returns the identity key\n *\n * @returns {*|string}\n */\n getIdentityKey(): string {\n return this.identityKey;\n }\n\n /**\n * This should be called with the last part of the signing path (/.../.../...)\n * This library assumes the first part is m/424150'/0'/0' as defined at the top of this file\n *\n * @param path The second path of the signing path in the format [0-9]{0,9}/[0-9]{0,9}/[0-9]{0,9}\n */\n set rootPath(path: string) {\n if (this.#isType42) {\n // Type 42 mode: use path directly as invoice number\n this.#rootPath = path;\n \n if (!this.#masterPrivateKey) throw new Error(\"Master private key not initialized\");\n const derivedKey = this.#masterPrivateKey.deriveChild(\n this.#masterPrivateKey.toPublicKey(),\n path // Use original path as invoice number\n );\n this.rootAddress = derivedKey.toPublicKey().toAddress();\n \n // For Type 42, paths don't need BIP32 formatting\n this.#previousPath = path;\n this.#currentPath = path;\n } else {\n // BIP32 mode: validate and format HD path\n let pathToUse = path;\n if (path.split(\"/\").length < 5) {\n pathToUse = `${SIGNING_PATH_PREFIX}${path}`;\n }\n\n if (!this.validatePath(pathToUse)) {\n throw new Error(`invalid signing path given ${pathToUse}`);\n }\n\n this.#rootPath = pathToUse;\n\n if (!this.#HDPrivateKey) throw new Error(\"HD private key not initialized\");\n const derivedChild = this.#HDPrivateKey.derive(pathToUse);\n this.rootAddress = derivedChild.pubKey.toAddress();\n \n // Set paths for BIP32\n this.#previousPath = pathToUse;\n this.#currentPath = pathToUse;\n }\n\n // Identity keys should be derivatives of the root address - this allows checking\n // of the creation transaction\n this.identityKey = this.deriveIdentityKey(this.rootAddress);\n }\n\n get rootPath(): string {\n return this.#rootPath;\n }\n\n getRootPath(): string {\n return this.#rootPath;\n }\n\n /**\n * This should be called with the last part of the signing path (/.../.../...)\n * This library assumes the first part is m/424150'/0'/0' as defined at the top of this file\n *\n * @param path The second path of the signing path in the format [0-9]{0,9}/[0-9]{0,9}/[0-9]{0,9}\n */\n set currentPath(path) {\n if (this.#isType42) {\n // Type 42 mode: use path directly as invoice number\n this.#previousPath = this.#currentPath;\n this.#currentPath = path;\n } else {\n // BIP32 mode: validate and format HD path\n let pathToUse = path;\n if (path.split(\"/\").length < 5) {\n pathToUse = `${SIGNING_PATH_PREFIX}${path}`;\n }\n\n if (!this.validatePath(pathToUse)) {\n throw new Error(\"invalid signing path given\");\n }\n\n this.#previousPath = this.#currentPath;\n this.#currentPath = pathToUse;\n }\n }\n\n get currentPath(): string {\n return this.#currentPath;\n }\n\n get previousPath(): string {\n return this.#previousPath;\n }\n\n /**\n * This can be used to break the deterministic way child keys are created to make it harder for\n * an attacker to steal the identites when the root key is compromised. This does however require\n * the seeds to be stored at all times. If the seed is lost, the identity will not be recoverable.\n */\n get idSeed(): string {\n return this.#idSeed;\n }\n\n /**\n * Increment current path to a new path\n *\n * @returns {*}\n */\n incrementPath(): void {\n this.currentPath = Utils.getNextPath(this.currentPath);\n }\n\n /**\n * Check whether the given path is a valid path for use with this class\n * The signing paths used here always have a length of 3\n *\n * @param path The last part of the signing path (example \"/0/0/1\")\n * @returns {boolean}\n */\n validatePath(path: string) {\n /* eslint-disable max-len */\n if (\n path.match(\n /\\/[0-9]{1,10}'?\\/[0-9]{1,10}'?\\/[0-9]{1,10}'?\\/[0-9]{1,10}'?\\/[0-9]{1,10}'?\\/[0-9]{1,10}'?/\n )\n ) {\n const pathValues = path.split(\"/\");\n if (\n pathValues.length === 7 &&\n Number(pathValues[1].replace(\"'\", \"\")) <= MAX_INT &&\n Number(pathValues[2].replace(\"'\", \"\")) <= MAX_INT &&\n Number(pathValues[3].replace(\"'\", \"\")) <= MAX_INT &&\n Number(pathValues[4].replace(\"'\", \"\")) <= MAX_INT &&\n Number(pathValues[5].replace(\"'\", \"\")) <= MAX_INT &&\n Number(pathValues[6].replace(\"'\", \"\")) <= MAX_INT\n ) {\n return true;\n }\n }\n\n return false;\n }\n\n /**\n * Get the OP_RETURN for the initial ID transaction (signed with root address)\n *\n * @returns {[]}\n */\n getInitialIdTransaction() {\n return this.getIdTransaction(this.#rootPath);\n }\n\n /**\n * Get the OP_RETURN for the ID transaction of the current address / path\n *\n * @returns {[]}\n */\n getIdTransaction(previousPath = \"\") {\n if (this.#currentPath === this.#rootPath) {\n throw new Error(\n \"Current path equals rootPath. ID was probably not initialized properly\"\n );\n }\n\n const opReturn = [\n toArray(BAP_BITCOM_ADDRESS),\n toArray(\"ID\"),\n toArray(this.identityKey),\n toArray(this.getCurrentAddress()),\n ];\n\n return this.signOpReturnWithAIP(\n opReturn,\n previousPath || this.#previousPath\n );\n }\n\n /**\n * Get address for given path\n *\n * @param path\n * @returns {*}\n */\n getAddress(path: string): string {\n if (this.#isType42) {\n if (!this.#masterPrivateKey) throw new Error(\"Master private key not initialized\");\n // In Type 42, use path as invoice number\n const derivedKey = this.#masterPrivateKey.deriveChild(\n this.#masterPrivateKey.toPublicKey(),\n path\n );\n return derivedKey.toPublicKey().toAddress();\n }\n if (!this.#HDPrivateKey) throw new Error(\"HD private key not initialized\");\n const derivedChild = this.#HDPrivateKey.derive(path);\n return derivedChild.privKey.toPublicKey().toAddress();\n }\n\n /**\n * Get current signing address\n *\n * @returns {*}\n */\n getCurrentAddress(): string {\n return this.getAddress(this.#currentPath);\n }\n\n /**\n * Get the encryption key pair for this identity\n */\n getEncryptionKey(): { privKey: PrivateKey; pubKey: PublicKey } {\n if (this.#isType42) {\n if (!this.#masterPrivateKey) throw new Error(\"Master private key not initialized\");\n // First derive to root path, then to encryption path\n const rootKey = this.#masterPrivateKey.deriveChild(\n this.#masterPrivateKey.toPublicKey(),\n this.#rootPath\n );\n const encryptionKey = rootKey.deriveChild(\n rootKey.toPublicKey(),\n ENCRYPTION_PATH\n );\n return {\n privKey: encryptionKey,\n pubKey: encryptionKey.toPublicKey(),\n };\n }\n if (!this.#HDPrivateKey) throw new Error(\"HD private key not initialized\");\n const HDPrivateKey = this.#HDPrivateKey.derive(this.#rootPath);\n const encryptionKey = HDPrivateKey.derive(ENCRYPTION_PATH).privKey;\n return {\n privKey: encryptionKey,\n pubKey: encryptionKey.toPublicKey(),\n };\n }\n\n /**\n * Get the encryption key using type 42 (different key / incompatible with above)\n * @deprecated Use getEncryptionKey() which now handles both BIP32 and Type 42\n */\n getEncryptionKeyType42(): { privKey: PrivateKey; pubKey: PublicKey } {\n if (this.#isType42) {\n // If already in Type 42 mode, just use the regular method\n return this.getEncryptionKey();\n }\n \n // Legacy behavior for BIP32 keys wanting Type 42 style derivation\n if (!this.#HDPrivateKey) throw new Error(\"HD private key not initialized\");\n const HDPrivateKey = this.#HDPrivateKey.derive(this.#rootPath);\n const encryptionKey = HDPrivateKey.privKey.deriveChild(\n HDPrivateKey.toPublic().pubKey,\n ENCRYPTION_PATH\n );\n return {\n privKey: encryptionKey,\n pubKey: encryptionKey.toPublicKey(),\n };\n }\n /**\n * Get the public key for encrypting data for this identity\n */\n getEncryptionPublicKey(): string {\n const { pubKey } = this.getEncryptionKey();\n return pubKey.toString();\n }\n\n /**\n * Get the public key for encrypting data for this identity, using a seed for the encryption\n */\n getEncryptionPublicKeyWithSeed(seed: string): string {\n const encryptionKey = this.getEncryptionPrivateKeyWithSeed(seed);\n return encryptionKey.toPublicKey().toString();\n }\n\n /**\n * Encrypt the given string data with the identity encryption key\n * @param stringData\n * @param counterPartyPublicKey Optional public key of the counterparty\n * @return string Base64\n */\n encrypt(stringData: string, counterPartyPublicKey?: string): string {\n const { privKey: encryptionKey, pubKey: publicKey } = this.getEncryptionKey();\n const pubKey = counterPartyPublicKey\n ? PublicKey.fromString(counterPartyPublicKey)\n : publicKey;\n return toBase64(electrumEncrypt(toArray(stringData), pubKey, encryptionKey));\n }\n\n /**\n * Decrypt the given ciphertext with the identity encryption key\n * @param ciphertext\n */\n decrypt(ciphertext: string, counterPartyPublicKey?: string): string {\n const { privKey: encryptionKey } = this.getEncryptionKey();\n let pubKey: PublicKey | undefined;\n if (counterPartyPublicKey) {\n pubKey = PublicKey.fromString(counterPartyPublicKey);\n }\n return toUTF8(\n electrumDecrypt(toArray(ciphertext, \"base64\"), encryptionKey, pubKey)\n );\n }\n\n /**\n * Encrypt the given string data with the identity encryption key\n * @param stringData\n * @param seed String seed\n * @param counterPartyPublicKey Optional public key of the counterparty\n * @return string Base64\n */\n encryptWithSeed(\n stringData: string,\n seed: string,\n counterPartyPublicKey?: string\n ): string {\n const encryptionKey = this.getEncryptionPrivateKeyWithSeed(seed);\n const publicKey = encryptionKey.toPublicKey();\n const pubKey = counterPartyPublicKey\n ? PublicKey.fromString(counterPartyPublicKey)\n : publicKey;\n return toBase64(\n electrumEncrypt(toArray(stringData), pubKey, encryptionKey)\n );\n }\n\n /**\n * Decrypt the given ciphertext with the identity encryption key\n * @param ciphertext\n * @param seed String seed\n // * @param counterPartyPublicKey Public key of the counterparty\n */\n decryptWithSeed(\n ciphertext: string,\n seed: string,\n counterPartyPublicKey?: string\n ): string {\n const encryptionKey = this.getEncryptionPrivateKeyWithSeed(seed);\n let pubKey: PublicKey | undefined;\n if (counterPartyPublicKey) {\n pubKey = PublicKey.fromString(counterPartyPublicKey);\n }\n return toUTF8(\n electrumDecrypt(toArray(ciphertext, \"base64\"), encryptionKey, pubKey)\n );\n }\n\n private getEncryptionPrivateKeyWithSeed(seed: string): PrivateKey {\n const pathHex = toHex(Hash.sha256(seed, \"utf8\"));\n \n if (this.#isType42) {\n if (!this.#masterPrivateKey) throw new Error(\"Master private key not initialized\");\n // First derive to root path\n const rootKey = this.#masterPrivateKey.deriveChild(\n this.#masterPrivateKey.toPublicKey(),\n this.#rootPath\n );\n // Then derive with seed as invoice number\n return rootKey.deriveChild(rootKey.toPublicKey(), pathHex);\n }\n if (!this.#HDPrivateKey) throw new Error(\"HD private key not initialized\");\n const path = Utils.getSigningPathFromHex(pathHex);\n const HDPrivateKey = this.#HDPrivateKey.derive(this.#rootPath);\n return HDPrivateKey.derive(path).privKey;\n }\n\n /**\n * Get an attestation string for the given urn for this identity\n *\n * @param urn\n * @returns {string}\n */\n getAttestation(urn: string) {\n const urnHash = Hash.sha256(urn, \"utf8\");\n return `bap:attest:${toHex(urnHash)}:${this.getIdentityKey()}`;\n }\n\n /**\n * Generate and return the attestation hash for the given attribute of this identity\n *\n * @param attribute Attribute name (name, email etc.)\n * @returns {string}\n */\n getAttestationHash(attribute: string) {\n const urn = this.getAttributeUrn(attribute);\n if (!urn) return null;\n\n const attestation = this.getAttestation(urn);\n const attestationHash = Hash.sha256(attestation, \"utf8\");\n\n return toHex(attestationHash);\n }\n\n /**\n * Sign a message with the current signing address of this identity\n *\n * @param message\n * @param signingPath\n * @returns {{address: string, signature: string}}\n */\n signMessage(\n message: number[],\n signingPath?: string\n ): { address: string; signature: string } {\n const pathToUse = signingPath || this.#currentPath;\n let childPk: PrivateKey;\n \n if (this.#isType42) {\n if (!this.#masterPrivateKey) throw new Error(\"Master private key not initialized\");\n // In Type 42, use path as invoice number\n childPk = this.#masterPrivateKey.deriveChild(\n this.#masterPrivateKey.toPublicKey(),\n pathToUse\n );\n } else {\n if (!this.#HDPrivateKey) throw new Error(\"HD private key not initialized\");\n childPk = this.#HDPrivateKey.derive(pathToUse).privKey;\n }\n \n const address = childPk.toAddress();\n\n // Needed to calculate the recovery factor\n const dummySig = BSM.sign(message, childPk, \"raw\") as Signature;\n const h = new BigNumber(magicHash(message));\n const r = dummySig.CalculateRecoveryFactor(childPk.toPublicKey(), h);\n const signature = (\n BSM.sign(message, childPk, \"raw\") as Signature\n ).toCompact(r, true, \"base64\") as string;\n\n return { address, signature };\n }\n\n /**\n * Sign a message using a key based on the given string seed\n *\n * This works by creating a private key from the root key of this identity. It will always\n * work with the rootPath / rootKey, to be deterministic. It will not change even if the keys\n * are rotated for this ID.\n *\n * This is used in for instance deterministic login systems, that do not support BAP.\n *\n * @param message\n * @param seed {string} String seed that will be used to generate a path\n */\n signMessageWithSeed(\n message: string,\n seed: string\n ): { address: string; signature: string } {\n const pathHex = toHex(Hash.sha256(seed, \"utf8\"));\n let derivedKey: PrivateKey;\n \n if (this.#isType42) {\n if (!this.#masterPrivateKey) throw new Error(\"Master private key not initialized\");\n // First derive to root path\n const rootKey = this.#masterPrivateKey.deriveChild(\n this.#masterPrivateKey.toPublicKey(),\n this.#rootPath\n );\n // Then derive with seed hex as invoice number\n derivedKey = rootKey.deriveChild(rootKey.toPublicKey(), pathHex);\n } else {\n if (!this.#HDPrivateKey) throw new Error(\"HD private key not initialized\");\n const path = Utils.getSigningPathFromHex(pathHex);\n const HDPrivateKey = this.#HDPrivateKey.derive(this.#rootPath);\n const derivedChild = HDPrivateKey.derive(path);\n derivedKey = derivedChild.privKey;\n }\n \n const address = derivedKey.toPublicKey().toAddress();\n const messageArray = toArray(message, \"utf8\");\n \n const dummySig = BSM.sign(messageArray, derivedKey, \"raw\") as Signature;\n const h = new BigNumber(magicHash(messageArray));\n const r = dummySig.CalculateRecoveryFactor(derivedKey.toPublicKey(), h);\n\n const signature = (\n BSM.sign(messageArray, derivedKey, \"raw\") as Signature\n ).toCompact(r, true, \"base64\") as string;\n\n return { address, signature };\n }\n\n /**\n * Sign an op_return hex array with AIP\n * @param opReturn {array}\n * @param signingPath {string}\n * @return {number[]}\n */\n signOpReturnWithAIP(opReturn: number[][], signingPath = \"\"): number[][] {\n const aipMessageBuffer = this.getAIPMessageBuffer(opReturn);\n const { address, signature } = this.signMessage(\n aipMessageBuffer.flat(),\n signingPath\n );\n return this.formatAIPOutput(opReturn, address, signature);\n }\n\n /**\n * Get all signing keys for this identity\n */\n async getIdSigningKeys(): Promise<GetSigningKeysResponse> {\n const signingKeys = await this.getApiData<GetSigningKeysResponse>(\n \"/signing-keys\",\n {\n idKey: this.identityKey,\n }\n );\n console.log(\"getIdSigningKeys\", signingKeys);\n\n return signingKeys;\n }\n\n /**\n * Get all attestations for the given attribute\n *\n * @param attribute\n */\n async getAttributeAttestations(\n attribute: string\n ): Promise<GetAttestationResponse> {\n // This function needs to make a call to a BAP server to get all the attestations for this\n // identity for the given attribute\n const attestationHash = this.getAttestationHash(attribute);\n\n // get all BAP ATTEST records for the given attestationHash\n const attestations = await this.getApiData<GetAttestationResponse>(\n \"/attestation/get\",\n {\n hash: attestationHash,\n }\n );\n console.log(\"getAttestations\", attribute, attestationHash, attestations);\n\n return attestations;\n }\n\n /**\n * Import an identity from a JSON object\n *\n * @param identity{{}}\n */\n import(identity: Identity | OldIdentity): void {\n this.idName = identity.name;\n this.description = identity.description || \"\";\n this.identityKey = identity.identityKey;\n this.#rootPath = identity.rootPath;\n this.rootAddress = identity.rootAddress;\n this.#previousPath = identity.previousPath;\n this.#currentPath = identity.currentPath;\n this.#idSeed = (\"idSeed\" in identity ? identity.idSeed : \"\") || \"\";\n this.identityAttributes = this.parseAttributes(identity.identityAttributes);\n }\n\n /**\n * Export this identity to a JSON object\n * @returns {{}}\n */\n export(): Identity {\n return {\n name: this.idName,\n description: this.description,\n identityKey: this.identityKey,\n rootPath: this.#rootPath,\n rootAddress: this.rootAddress,\n previousPath: this.#previousPath,\n currentPath: this.#currentPath,\n idSeed: this.#idSeed,\n identityAttributes: this.getAttributes(),\n lastIdPath: \"\",\n };\n }\n\n // New method to export a member-friendly backup, containing only the derived signing key\n exportMemberBackup(): MemberIdentity {\n let derivedKey: PrivateKey;\n \n if (this.#isType42) {\n if (!this.#masterPrivateKey) throw new Error(\"Master private key not initialized\");\n derivedKey = this.#masterPrivateKey.deriveChild(\n this.#masterPrivateKey.toPublicKey(),\n this.#currentPath\n );\n } else {\n if (!this.#HDPrivateKey) throw new Error(\"HD private key not initialized\");\n derivedKey = this.#HDPrivateKey.derive(this.#currentPath).privKey;\n }\n \n return {\n name: this.idName,\n description: this.description,\n derivedPrivateKey: derivedKey.toWif(),\n address: derivedKey.toPublicKey().toAddress(),\n identityAttributes: this.getAttributes(),\n identityKey: this.identityKey,\n };\n }\n\n // New method to derive a new member ID from the master HD key\n public newId(): MemberID {\n // Assuming incrementPath updates the internal current path\n this.incrementPath();\n \n let derivedKey: PrivateKey;\n if (this.#isType42) {\n if (!this.#masterPrivateKey) throw new Error(\"Master private key not initialized\");\n derivedKey = this.#masterPrivateKey.deriveChild(\n this.#masterPrivateKey.toPublicKey(),\n this.#currentPath\n );\n } else {\n if (!this.#HDPrivateKey) throw new Error(\"HD private key not initialized\");\n derivedKey = this.#HDPrivateKey.derive(this.#currentPath).privKey;\n }\n \n return new MemberID(derivedKey);\n }\n\n /**\n * Export member data in bitcoin-backup compatible format\n * @returns Object with wif and encrypted member data\n */\n exportMember(): { wif: string; encryptedData: string } {\n const memberExport = this.exportMemberBackup();\n \n let derivedKey: PrivateKey;\n if (this.#isType42) {\n if (!this.#masterPrivateKey) throw new Error(\"Master private key not initialized\");\n derivedKey = this.#masterPrivateKey.deriveChild(\n this.#masterPrivateKey.toPublicKey(),\n this.#currentPath\n );\n } else {\n if (!this.#HDPrivateKey) throw new Error(\"HD private key not initialized\");\n derivedKey = this.#HDPrivateKey.derive(this.#currentPath).privKey;\n }\n\n // Encrypt the member data using ECIES\n const encryptedData = toBase64(\n electrumEncrypt(\n toArray(JSON.stringify(memberExport)),\n derivedKey.toPublicKey()\n )\n );\n\n return {\n wif: memberExport.derivedPrivateKey,\n encryptedData,\n };\n }\n}\nexport { MasterID };\n",
9
9
  "import type { PathPrefix } from \"./interface.js\";\n\nexport const Utils = {\n /**\n * Helper function to generate cryptographically secure random bytes\n * \n * This follows the pattern used by BSV SDK and other Bitcoin libraries.\n * Uses crypto.getRandomValues() which is available in browsers and modern Node.js.\n *\n * @param {number} byteLength - Number of random bytes to generate (default: 32)\n * @returns {Uint8Array} Array of cryptographically secure random bytes\n */\n getRandomBytes(byteLength = 32): Uint8Array {\n // Use crypto.getRandomValues() - available in browsers and Node.js 15+\n if (typeof globalThis !== 'undefined' && globalThis.crypto && globalThis.crypto.getRandomValues) {\n const array = new Uint8Array(byteLength);\n globalThis.crypto.getRandomValues(array);\n return array;\n }\n\n // Fallback error - crypto operations require secure randomness\n throw new Error(\n 'Secure random number generation not available. ' +\n 'crypto.getRandomValues() is required for cryptographic operations. ' +\n 'This environment may not be suitable for secure key generation.'\n );\n },\n\n /**\n * Helper function to generate a random hex string\n *\n * @param {number} byteLength - Number of random bytes to generate (default: 32)\n * @returns {string} Hex string of random bytes\n */\n getRandomString(byteLength = 32): string {\n const bytes = this.getRandomBytes(byteLength);\n return Array.from(bytes, byte => byte.toString(16).padStart(2, '0')).join('');\n },\n\n /**\n * Get a signing path from a hex number\n *\n * @param hexString {string}\n * @param hardened {boolean} Whether to return a hardened path\n * @returns {string}\n */\n getSigningPathFromHex(hexString: string, hardened = true) {\n // \"m/0/0/1\"\n let signingPath = \"m\";\n const signingHex = hexString.match(/.{1,8}/g);\n if (!signingHex) {\n throw new Error(\"Invalid hex string\");\n }\n const maxNumber = 2147483648 - 1; // 0x80000000\n for (const hexNumber of signingHex) {\n let number = Number(`0x${hexNumber}`);\n if (number > maxNumber) number -= maxNumber;\n signingPath += `/${number}${hardened ? \"'\" : \"\"}`;\n }\n\n return signingPath;\n },\n\n /**\n * Increment that second to last part from the given part, set the last part to 0\n *\n * @param path string\n * @returns {*}\n */\n getNextIdentityPath(path: string): PathPrefix {\n const pathValues = path.split(\"/\");\n const secondToLastPart = pathValues[pathValues.length - 2];\n\n let hardened = false;\n if (secondToLastPart.match(\"'\")) {\n hardened = true;\n }\n\n const nextPath = (\n Number(secondToLastPart.replace(/[^0-9]/g, \"\")) + 1\n ).toString();\n pathValues[pathValues.length - 2] = nextPath + (hardened ? \"'\" : \"\");\n pathValues[pathValues.length - 1] = `0${hardened ? \"'\" : \"\"}`;\n\n return pathValues.join(\"/\") as PathPrefix;\n },\n\n /**\n * Increment that last part of the given path\n *\n * @param path string\n * @returns {*}\n */\n getNextPath(path: string) {\n const pathValues = path.split(\"/\");\n const lastPart = pathValues[pathValues.length - 1];\n let hardened = false;\n if (lastPart.match(\"'\")) {\n hardened = true;\n }\n const nextPath = (Number(lastPart.replace(/[^0-9]/g, \"\")) + 1).toString();\n pathValues[pathValues.length - 1] = nextPath + (hardened ? \"'\" : \"\");\n return pathValues.join(\"/\");\n },\n};\n",
10
- "import {\n BSM,\n type PublicKey,\n PrivateKey,\n BigNumber,\n} from \"@bsv/sdk\";\nimport type { Signature } from \"@bsv/sdk\";\nimport { BaseClass } from \"./BaseClass\";\nimport type { IdentityAttributes, MemberIdentity } from \"./interface\";\nimport { ENCRYPTION_PATH } from \"./constants\";\nconst { magicHash } = BSM;\n\nexport class MemberID extends BaseClass {\n private key: PrivateKey;\n public idName: string;\n public description: string;\n public address: string;\n public identityKey: string;\n\n constructor(key: PrivateKey, identityAttributes: IdentityAttributes = {}) {\n super();\n this.key = key;\n this.address = key.toAddress();\n this.idName = \"Member ID 1\";\n this.description = \"\";\n this.identityKey = \"\";\n this.identityAttributes = this.parseAttributes(identityAttributes);\n }\n\n // Implement the abstract signMessage method from BaseClass\n public signMessage(\n message: number[],\n _signingPath?: string\n ): { address: string; signature: string } {\n const childPk = this.key;\n const address = childPk.toAddress();\n\n // Sign using the raw message buffer directly\n const dummySig = BSM.sign(message, childPk, \"raw\") as Signature;\n const h = new BigNumber(magicHash(message));\n const r = dummySig.CalculateRecoveryFactor(childPk.toPublicKey(), h);\n\n const signature = (\n BSM.sign(message, childPk, \"raw\") as Signature\n ).toCompact(r, true, \"base64\") as string;\n\n return { address, signature };\n }\n\n // Implement signOpReturnWithAIP - MemberID ignores signing path\n public signOpReturnWithAIP(opReturn: number[][]): number[][] {\n const aipMessageBuffer = this.getAIPMessageBuffer(opReturn);\n const { address, signature } = this.signMessage(aipMessageBuffer.flat());\n return this.formatAIPOutput(aipMessageBuffer, address, signature);\n }\n\n // Return the member's public key\n public getPublicKey(): string {\n return this.key.toPublicKey().toString();\n }\n\n // Import the member identity from an object containing the derived private key and identity data\n public import(identity: MemberIdentity): void {\n this.idName = identity.name;\n this.description = identity.description;\n this.key = PrivateKey.fromWif(identity.derivedPrivateKey);\n this.address = this.key.toAddress();\n this.identityAttributes = identity.identityAttributes || {};\n this.identityKey = identity.identityKey;\n }\n\n static fromMemberIdentity(identity: MemberIdentity): MemberID {\n const member = new MemberID(PrivateKey.fromWif(identity.derivedPrivateKey));\n member.import(identity);\n return member;\n }\n\n static fromBackup(singleBackup: { wif: string; id: string }): MemberID {\n // decrypt the id and set the details\n const member = new MemberID(PrivateKey.fromWif(singleBackup.wif));\n const id = JSON.parse(member.decrypt(singleBackup.id));\n member.import(id);\n return member;\n }\n\n // Export the member identity as an object containing the derived private key and identity data\n public export(): MemberIdentity {\n return {\n name: this.idName,\n description: this.description,\n derivedPrivateKey: this.key.toWif(),\n address: this.address,\n identityAttributes: this.getAttributes(),\n identityKey: this.identityKey,\n };\n }\n\n /**\n * Get the encryption key pair for this identity\n * We use the same key for both signing and encryption for simplicity\n */\n getEncryptionKey(): { privKey: PrivateKey; pubKey: PublicKey } {\n // Derive the encryption key from the private key using the ENCRYPTION_PATH\n // Since member keys are not HD keys, we use the path as the invoice number,\n // and use our own public key as the other party's public key\n return {\n privKey: this.key.deriveChild(this.key.toPublicKey(), ENCRYPTION_PATH),\n pubKey: this.key\n .deriveChild(this.key.toPublicKey(), ENCRYPTION_PATH)\n .toPublicKey(),\n };\n }\n\n /**\n * Get the public key for encrypting data for this identity\n */\n getEncryptionPublicKey(): string {\n const { pubKey } = this.getEncryptionKey();\n return pubKey.toString();\n }\n\n /**\n * Export member data in bitcoin-backup compatible format\n * @param label Optional user-defined label\n * @returns BapMemberBackup compatible object\n */\n exportForBackup(label?: string): {\n wif: string;\n id: string;\n label?: string;\n createdAt: string;\n } {\n const memberData = this.export();\n const encryptedData = this.encrypt(JSON.stringify(memberData));\n\n return {\n wif: this.key.toWif(),\n id: encryptedData,\n ...(label && { label }),\n createdAt: new Date().toISOString(),\n };\n }\n}\n",
10
+ "import {\n BSM,\n PublicKey,\n PrivateKey,\n BigNumber,\n Hash,\n Utils as BSVUtils,\n ECIES,\n} from \"@bsv/sdk\";\nimport type { Signature } from \"@bsv/sdk\";\nimport { BaseClass } from \"./BaseClass\";\nimport type { IdentityAttributes, MemberIdentity } from \"./interface\";\nimport { ENCRYPTION_PATH } from \"./constants\";\nconst { magicHash } = BSM;\nconst { toArray, toUTF8, toBase64, toHex } = BSVUtils;\nconst { electrumDecrypt, electrumEncrypt } = ECIES;\n\nexport class MemberID extends BaseClass {\n private key: PrivateKey;\n public idName: string;\n public description: string;\n public address: string;\n public identityKey: string;\n\n constructor(key: PrivateKey, identityAttributes: IdentityAttributes = {}) {\n super();\n this.key = key;\n this.address = key.toAddress();\n this.idName = \"Member ID 1\";\n this.description = \"\";\n this.identityKey = \"\";\n this.identityAttributes = this.parseAttributes(identityAttributes);\n }\n\n // Implement the abstract signMessage method from BaseClass\n public signMessage(\n message: number[],\n _signingPath?: string\n ): { address: string; signature: string } {\n const childPk = this.key;\n const address = childPk.toAddress();\n\n // Sign using the raw message buffer directly\n const dummySig = BSM.sign(message, childPk, \"raw\") as Signature;\n const h = new BigNumber(magicHash(message));\n const r = dummySig.CalculateRecoveryFactor(childPk.toPublicKey(), h);\n\n const signature = (\n BSM.sign(message, childPk, \"raw\") as Signature\n ).toCompact(r, true, \"base64\") as string;\n\n return { address, signature };\n }\n\n // Implement signOpReturnWithAIP - MemberID ignores signing path\n public signOpReturnWithAIP(opReturn: number[][]): number[][] {\n const aipMessageBuffer = this.getAIPMessageBuffer(opReturn);\n const { address, signature } = this.signMessage(aipMessageBuffer.flat());\n return this.formatAIPOutput(aipMessageBuffer, address, signature);\n }\n\n // Return the member's public key\n public getPublicKey(): string {\n return this.key.toPublicKey().toString();\n }\n\n // Import the member identity from an object containing the derived private key and identity data\n public import(identity: MemberIdentity): void {\n this.idName = identity.name;\n this.description = identity.description;\n this.key = PrivateKey.fromWif(identity.derivedPrivateKey);\n this.address = this.key.toAddress();\n this.identityAttributes = identity.identityAttributes || {};\n this.identityKey = identity.identityKey;\n }\n\n static fromMemberIdentity(identity: MemberIdentity): MemberID {\n const member = new MemberID(PrivateKey.fromWif(identity.derivedPrivateKey));\n member.import(identity);\n return member;\n }\n\n static fromBackup(singleBackup: { wif: string; id: string }): MemberID {\n // decrypt the id and set the details\n const member = new MemberID(PrivateKey.fromWif(singleBackup.wif));\n const id = JSON.parse(member.decrypt(singleBackup.id));\n member.import(id);\n return member;\n }\n\n // Export the member identity as an object containing the derived private key and identity data\n public export(): MemberIdentity {\n return {\n name: this.idName,\n description: this.description,\n derivedPrivateKey: this.key.toWif(),\n address: this.address,\n identityAttributes: this.getAttributes(),\n identityKey: this.identityKey,\n };\n }\n\n /**\n * Get the encryption key pair for this identity\n * We use the same key for both signing and encryption for simplicity\n */\n getEncryptionKey(): { privKey: PrivateKey; pubKey: PublicKey } {\n // Derive the encryption key from the private key using the ENCRYPTION_PATH\n // Since member keys are not HD keys, we use the path as the invoice number,\n // and use our own public key as the other party's public key\n return {\n privKey: this.key.deriveChild(this.key.toPublicKey(), ENCRYPTION_PATH),\n pubKey: this.key\n .deriveChild(this.key.toPublicKey(), ENCRYPTION_PATH)\n .toPublicKey(),\n };\n }\n\n /**\n * Get the public key for encrypting data for this identity\n */\n getEncryptionPublicKey(): string {\n const { pubKey } = this.getEncryptionKey();\n return pubKey.toString();\n }\n\n /**\n * Get a derived encryption key using a seed string (Type42 derivation)\n * This allows deriving unique encryption keys per friend/conversation\n * @param seed - The seed string (e.g., friend's BAP ID)\n * @returns The derived private key for this seed\n */\n private getEncryptionPrivateKeyWithSeed(seed: string): PrivateKey {\n // Hash the seed to get a deterministic value\n const seedHash = toHex(Hash.sha256(seed, \"utf8\"));\n // Use Type42 derivation: deriveChild(publicKey, invoice)\n return this.key.deriveChild(this.key.toPublicKey(), seedHash);\n }\n\n /**\n * Get the encryption key pair for a specific seed\n * @param seed - The seed string (e.g., friend's BAP ID)\n */\n getEncryptionKeyWithSeed(seed: string): { privKey: PrivateKey; pubKey: PublicKey } {\n const privKey = this.getEncryptionPrivateKeyWithSeed(seed);\n return {\n privKey,\n pubKey: privKey.toPublicKey(),\n };\n }\n\n /**\n * Get the public key for encrypting data for a specific seed\n * This is the public key to include in friend requests\n * @param seed - The seed string (e.g., friend's BAP ID)\n */\n getEncryptionPublicKeyWithSeed(seed: string): string {\n return this.getEncryptionPrivateKeyWithSeed(seed).toPublicKey().toString();\n }\n\n /**\n * Encrypt data using a seed-derived key\n * @param stringData - The data to encrypt\n * @param seed - The seed string for key derivation (e.g., friend's BAP ID)\n * @param counterPartyPublicKey - Optional public key of the recipient\n * @returns Base64 encoded encrypted data\n */\n encryptWithSeed(stringData: string, seed: string, counterPartyPublicKey?: string): string {\n const derivedKey = this.getEncryptionPrivateKeyWithSeed(seed);\n const pubKey = derivedKey.toPublicKey();\n // Import PublicKey type-safely - counterPartyPublicKey is already a hex pubkey string\n const PublicKeyClass = this.key.toPublicKey().constructor as typeof import(\"@bsv/sdk\").PublicKey;\n const targetPubKey = counterPartyPublicKey\n ? PublicKeyClass.fromString(counterPartyPublicKey)\n : pubKey;\n return toBase64(electrumEncrypt(toArray(stringData), targetPubKey, derivedKey));\n }\n\n /**\n * Decrypt data using a seed-derived key\n * @param ciphertext - Base64 encoded encrypted data\n * @param seed - The seed string for key derivation (e.g., friend's BAP ID)\n * @param counterPartyPublicKey - Optional public key of the sender\n * @returns Decrypted string\n */\n decryptWithSeed(ciphertext: string, seed: string, counterPartyPublicKey?: string): string {\n const derivedKey = this.getEncryptionPrivateKeyWithSeed(seed);\n let senderPubKey: PublicKey | undefined;\n if (counterPartyPublicKey) {\n senderPubKey = PublicKey.fromString(counterPartyPublicKey);\n }\n return toUTF8(electrumDecrypt(toArray(ciphertext, \"base64\"), derivedKey, senderPubKey));\n }\n\n /**\n * Export member data in bitcoin-backup compatible format\n * @param label Optional user-defined label\n * @returns BapMemberBackup compatible object\n */\n exportForBackup(label?: string): {\n wif: string;\n id: string;\n label?: string;\n createdAt: string;\n } {\n const memberData = this.export();\n const encryptedData = this.encrypt(JSON.stringify(memberData));\n\n return {\n wif: this.key.toWif(),\n id: encryptedData,\n ...(label && { label }),\n createdAt: new Date().toISOString(),\n };\n }\n}\n",
11
11
  "import { ECIES, Utils as BSVUtils, OP, PublicKey } from \"@bsv/sdk\";\nimport type { PrivateKey } from \"@bsv/sdk\";\nimport { AIP_BITCOM_ADDRESS } from \"./constants\";\nimport type { IdentityAttribute, IdentityAttributes } from \"./interface\";\nimport { Utils } from \"./utils\";\nconst { toArray, toUTF8, toBase64 } = BSVUtils;\nconst { electrumDecrypt, electrumEncrypt } = ECIES;\n\nabstract class BaseClass {\n protected identityAttributes: IdentityAttributes = {};\n\n /**\n * Abstract method that must be implemented by derived classes to sign messages\n * @param message - The message to sign\n * @param signingPath - Optional signing path for HD wallets\n * @returns Object containing address and signature\n */\n abstract signMessage(\n message: number[],\n signingPath?: string\n ): { address: string; signature: string };\n\n /**\n * Abstract method that must be implemented by derived classes to get encryption key\n */\n abstract getEncryptionKey(): { privKey: PrivateKey; pubKey: PublicKey };\n\n /**\n * Encrypt the given string data with the identity encryption key\n * @param stringData\n * @param counterPartyPublicKey Optional public key of the counterparty\n * @return string Base64\n */\n encrypt(stringData: string, counterPartyPublicKey?: string): string {\n const { privKey, pubKey } = this.getEncryptionKey();\n const targetPubKey = counterPartyPublicKey\n ? PublicKey.fromString(counterPartyPublicKey)\n : pubKey;\n return toBase64(\n electrumEncrypt(toArray(stringData), targetPubKey, privKey)\n );\n }\n\n /**\n * Decrypt the given ciphertext with the identity encryption key\n * @param ciphertext\n * @param counterPartyPublicKey Optional public key of the counterparty\n */\n decrypt(ciphertext: string, counterPartyPublicKey?: string): string {\n const { privKey } = this.getEncryptionKey();\n let pubKey: PublicKey | undefined;\n if (counterPartyPublicKey) {\n pubKey = PublicKey.fromString(counterPartyPublicKey);\n }\n return toUTF8(\n electrumDecrypt(toArray(ciphertext, \"base64\"), privKey, pubKey)\n );\n }\n\n /**\n * Sign an op_return hex array with AIP\n * Each implementation must handle its own signing path logic\n * @param opReturn {array}\n * @param signingPath {string}\n * @return {number[]}\n */\n signOpReturnWithAIP(opReturn: number[][], signingPath?: string): number[][] {\n const aipMessageBuffer = this.getAIPMessageBuffer(opReturn);\n const { address, signature } = this.signMessage(\n aipMessageBuffer.flat(),\n signingPath\n );\n return this.formatAIPOutput(aipMessageBuffer, address, signature);\n }\n\n /**\n * Returns all the attributes in the identity\n * @returns {IdentityAttributes}\n */\n getAttributes(): IdentityAttributes {\n return this.identityAttributes;\n }\n\n /**\n * Get the value of the given attribute\n * @param attributeName\n * @returns {IdentityAttribute | null}\n */\n getAttribute(attributeName: string): IdentityAttribute | null {\n if (this.identityAttributes[attributeName]) {\n return this.identityAttributes[attributeName];\n }\n return null;\n }\n\n /**\n * Set the value of the given attribute\n * If an empty value ('' || null || false) is given, the attribute is removed from the ID\n * @param attributeName string\n * @param attributeValue any\n */\n setAttribute(\n attributeName: string,\n attributeValue: string | Record<string, string>\n ): void {\n if (!attributeValue) {\n return;\n }\n\n if (this.identityAttributes[attributeName]) {\n this.updateExistingAttribute(attributeName, attributeValue);\n } else {\n this.createNewAttribute(attributeName, attributeValue);\n }\n }\n\n /**\n * Unset the given attribute from the ID\n * @param attributeName\n */\n unsetAttribute(attributeName: string): void {\n delete this.identityAttributes[attributeName];\n }\n\n /**\n * Add an attribute to this identity\n * @param attributeName\n * @param value\n * @param nonce\n */\n addAttribute(attributeName: string, value: string, nonce = \"\"): void {\n let nonceToUse = nonce;\n if (!nonce) {\n nonceToUse = Utils.getRandomString();\n }\n\n this.identityAttributes[attributeName] = {\n value,\n nonce: nonceToUse,\n };\n }\n\n /**\n * Get all attribute URNs for this ID\n * @returns {string}\n */\n getAttributeUrns(): string {\n let urns = \"\";\n for (const key in this.identityAttributes) {\n const urn = this.getAttributeUrn(key);\n if (urn) {\n urns += `${urn}\\n`;\n }\n }\n return urns;\n }\n\n /**\n * Create and return the attribute URN for the given attribute\n * @param attributeName\n * @returns {string|null}\n */\n getAttributeUrn(attributeName: string): string | null {\n const attribute = this.identityAttributes[attributeName];\n if (attribute) {\n return `urn:bap:id:${attributeName}:${attribute.value}:${attribute.nonce}`;\n }\n return null;\n }\n\n /**\n * Parse a text of URN string into identity attributes\n * @param urnIdentityAttributes\n */\n protected parseStringUrns(urnIdentityAttributes: string): IdentityAttributes {\n const identityAttributes: IdentityAttributes = {};\n const attributesRaw = urnIdentityAttributes\n .replace(/^\\s+/g, \"\")\n .replace(/\\r/gm, \"\")\n .split(\"\\n\");\n\n for (const line of attributesRaw) {\n const attribute = line.replace(/^\\s+/g, \"\").replace(/\\s+$/g, \"\");\n const urn = attribute.split(\":\");\n if (\n urn[0] === \"urn\" &&\n urn[1] === \"bap\" &&\n urn[2] === \"id\" &&\n urn[3] &&\n urn[4] &&\n urn[5]\n ) {\n identityAttributes[urn[3]] = {\n value: urn[4],\n nonce: urn[5],\n };\n }\n }\n\n return identityAttributes;\n }\n\n /**\n * Helper function to parse identity attributes\n * @param identityAttributes\n * @returns {IdentityAttributes}\n */\n protected parseAttributes(\n identityAttributes: IdentityAttributes | string\n ): IdentityAttributes {\n if (typeof identityAttributes === \"string\") {\n return this.parseStringUrns(identityAttributes);\n }\n\n for (const key in identityAttributes) {\n if (!identityAttributes[key].value || !identityAttributes[key].nonce) {\n throw new Error(\"Invalid identity attribute\");\n }\n }\n\n return identityAttributes || {};\n }\n\n /**\n * Helper method to update an existing attribute\n */\n protected updateExistingAttribute(\n attributeName: string,\n attributeValue: string | Record<string, string>\n ): void {\n if (typeof attributeValue === \"string\") {\n this.identityAttributes[attributeName].value = attributeValue;\n return;\n }\n\n this.identityAttributes[attributeName].value = attributeValue.value || \"\";\n if (attributeValue.nonce) {\n this.identityAttributes[attributeName].nonce = attributeValue.nonce;\n }\n }\n\n /**\n * Helper method to create a new attribute\n */\n protected createNewAttribute(\n attributeName: string,\n attributeValue: string | Record<string, string>\n ): void {\n if (typeof attributeValue === \"string\") {\n this.addAttribute(attributeName, attributeValue);\n return;\n }\n\n this.addAttribute(\n attributeName,\n attributeValue.value || \"\",\n attributeValue.nonce\n );\n }\n\n /**\n * Construct an AIP buffer from the op return data\n * @param opReturn\n * @returns {number[]} Array of numbers representing the buffer\n */\n protected getAIPMessageBuffer(\n opReturn: number[][],\n indicies?: number[]\n ): number[][] {\n // locate the position of OP_RETURN in the opReturn array\n let opReturnIndex = opReturn.findIndex((op) => op[0] === OP.OP_RETURN);\n const buffers: number[][] = [];\n\n // include OP_RETURN in constructing the signature buffer\n if (opReturnIndex === -1) {\n buffers.push([OP.OP_RETURN]);\n opReturnIndex = 0;\n }\n\n // if indicies is specified, only include the specified indicies in the buffer\n // relative to the position of OP_RETURN as \"0\"\n if (indicies) {\n for (const index of indicies) {\n buffers.push(opReturn[opReturnIndex + index]);\n }\n } else {\n for (const op of opReturn) {\n buffers.push(op);\n }\n }\n\n return buffers;\n }\n\n /**\n * Helper method to format AIP output\n * @param opReturn Original OP_RETURN data\n * @param address Signing address\n * @param signature Base64 signature\n * @returns Formatted AIP output as number[]\n */\n protected formatAIPOutput(\n opReturnBuffers: number[][],\n address: string,\n signature: string\n ): number[][] {\n // Add AIP protocol elements\n const aipElements = [\n toArray(\"|\"),\n toArray(AIP_BITCOM_ADDRESS),\n toArray(\"BITCOIN_ECDSA\"),\n toArray(address),\n toArray(signature, \"base64\"),\n ];\n\n // Concatenate all buffers\n return [...opReturnBuffers, ...aipElements];\n }\n}\n\nexport { BaseClass };\n"
12
12
  ],
13
- "mappings": ";AAAA,cACE,eACA,YACA,SACA,SACA,eAEA,iBACA,kBAGF,gBAAS,kBCJF,IAAM,EAAa,MACxB,EACA,EACA,EACA,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MAAU,MAAM,YAAY,aAAiB,EAI/C,IAAM,EAAe,EAAS,aAAa,EAE3C,MAAO,CACL,IAAK,EAAa,IAClB,GAAI,EAAa,iBACb,GAAS,CAAE,OAAM,EACrB,UAAW,IAAI,KAAK,EAAE,YAAY,CACpC,EAEJ",
14
+ "debugId": "4BA596E1716B79D264756E2164756E21",
15
15
  "names": []
16
16
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "bsv-bap",
3
- "version": "0.1.12",
3
+ "version": "0.1.13",
4
4
  "description": "BAP npm module",
5
5
  "repository": {
6
6
  "type": "git",
@@ -48,6 +48,6 @@
48
48
  "schema-dts": "^1.1.5"
49
49
  },
50
50
  "peerDependencies": {
51
- "@bsv/sdk": "^1.6.1"
51
+ "@bsv/sdk": "^1.3.18"
52
52
  }
53
53
  }