Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
export function publicKeyFromBuffer(value: Buffer): string {
return stellar.StrKey.encodeEd25519PublicKey(value);
}
export function signerKeyFromXDR(xdr: any) {
switch (xdr.switch()) {
case stellar.xdr.SignerKeyType.signerKeyTypeEd25519():
return stellar.StrKey.encodeEd25519PublicKey(xdr.ed25519());
case stellar.xdr.SignerKeyType.signerKeyTypePreAuthTx():
return stellar.StrKey.encodePreAuthTx(xdr.preAuthTx());
case stellar.xdr.SignerKeyType.signerKeyTypeHashX():
return stellar.StrKey.encodeSha256Hash(xdr.hashX());
}
}
public static build(xdr: any): LedgerEvent | null {
const r = LedgerEvent.getTypeAndData(xdr);
if (r === null) {
return null;
}
const accountID = LedgerEvent.getAccountID(r.data);
if (accountID === null) {
return null;
}
return new LedgerEvent(stellar.StrKey.encodeEd25519PublicKey(accountID), r.type);
}
public static fromXDR(xdr: any) {
let key: string;
let type: SignerType;
switch (xdr.key().switch()) {
case stellar.xdr.SignerKeyType.signerKeyTypeEd25519():
key = stellar.StrKey.encodeEd25519PublicKey(xdr.key().ed25519());
type = "ed25519";
break;
case stellar.xdr.SignerKeyType.signerKeyTypePreAuthTx():
key = stellar.StrKey.encodePreAuthTx(xdr.key().preAuthTx());
type = "preAuthTx";
break;
case stellar.xdr.SignerKeyType.signerKeyTypeHashX():
key = stellar.StrKey.encodeSha256Hash(xdr.key().hashX());
type = "hashX";
break;
default:
throw new Error("We've encountered unknown XDR signer type");
}
return new Signer({ signer: key, weight: xdr.weight(), type });
}