New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

stellar-base

Package Overview
Dependencies
Maintainers
1
Versions
182
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

stellar-base - npm Package Compare versions

Comparing version 0.3.11 to 0.4.0

lib/network.js

45

lib/asset.js

@@ -18,4 +18,8 @@ "use strict";

var padRight = require("lodash").padRight;
var _lodash = require("lodash");
var clone = _lodash.clone;
var padRight = _lodash.padRight;
var trimRight = _lodash.trimRight;
/**

@@ -47,5 +51,3 @@ * Asset class represents an asset, either the native asset ("XLM")

// pad code with null bytes if necessary
var padLength = code.length <= 4 ? 4 : 12;
this.code = padRight(code, padLength, "\u0000");
this.code = code;
this.issuer = issuer;

@@ -75,4 +77,8 @@ }

// pad code with null bytes if necessary
var padLength = this.code.length <= 4 ? 4 : 12;
var paddedCode = padRight(this.code, padLength, "\u0000");
var assetType = new xdrType({
assetCode: this.code,
assetCode: paddedCode,
issuer: Keypair.fromAddress(this.issuer).accountId()

@@ -85,2 +91,22 @@ });

},
getCode: {
/**
* Return the asset code
*/
value: function getCode() {
return clone(this.code);
}
},
getIssuer: {
/**
* Return the asset issuer
**/
value: function getIssuer() {
return clone(this.issuer);
}
},
isNative: {

@@ -103,3 +129,3 @@

value: function equals(asset) {
return this.code == asset.code && this.issuer == asset.issuer;
return this.code == asset.getCode() && this.issuer == asset.getIssuer();
}

@@ -127,2 +153,3 @@ }

var anum = undefined,
code = undefined,
issuer = undefined;

@@ -135,7 +162,9 @@ switch (cx["switch"]()) {

issuer = encodeCheck("accountId", anum.issuer().ed25519());
return new this(anum.assetCode(), issuer);
code = trimRight(anum.assetCode(), "\u0000");
return new this(code, issuer);
case xdr.AssetType.assetTypeCreditAlphanum12():
anum = cx.alphaNum12();
issuer = encodeCheck("accountId", anum.issuer().ed25519());
return new this(anum.assetCode(), issuer);
code = trimRight(anum.assetCode(), "\u0000");
return new this(code, issuer);
default:

@@ -142,0 +171,0 @@ throw new Error("Invalid asset type: " + cx["switch"]().name);

@@ -35,2 +35,7 @@ "use strict";

var _network = require("./network");
exports.Network = _network.Network;
exports.Networks = _network.Networks;
_defaults(exports, _interopRequireWildcard(require("./strkey")));

9

lib/transaction.js

@@ -20,2 +20,4 @@ "use strict";

var Network = require("./network").Network;
var _lodash = require("lodash");

@@ -120,10 +122,5 @@

value: function signatureBase() {
return Buffer.concat([this.signatureBasePrefix(), this.tx.toXDR()]);
return Buffer.concat([Network.current().networkId(), xdr.EnvelopeType.envelopeTypeTx().toXDR(), this.tx.toXDR()]);
}
},
signatureBasePrefix: {
value: function signatureBasePrefix() {
return xdr.EnvelopeType.envelopeTypeTx().toXDR();
}
},
toEnvelope: {

@@ -130,0 +127,0 @@

{
"name": "stellar-base",
"version": "0.3.11",
"version": "0.4.0",
"description": "Low level stellar support library",

@@ -65,2 +65,3 @@ "main": "lib/index.js",

"js-xdr": "0.0.10",
"karma": "^0.13.9",
"lodash": "^3.6.0",

@@ -67,0 +68,0 @@ "sha.js": "^2.3.6",

import {xdr, Keypair} from "./index";
import {encodeCheck} from "./strkey";
import {padRight} from 'lodash';
import {clone, padRight, trimRight} from 'lodash';

@@ -24,3 +24,3 @@ /**

static fromOperation(cx) {
let anum, issuer;
let anum, code, issuer;
switch(cx.switch()) {

@@ -32,7 +32,9 @@ case xdr.AssetType.assetTypeNative():

issuer = encodeCheck("accountId", anum.issuer().ed25519());
return new this(anum.assetCode(), issuer);
code = trimRight(anum.assetCode(), '\0');
return new this(code, issuer);
case xdr.AssetType.assetTypeCreditAlphanum12():
anum = cx.alphaNum12();
issuer = encodeCheck("accountId", anum.issuer().ed25519());
return new this(anum.assetCode(), issuer);
code = trimRight(anum.assetCode(), '\0');
return new this(code, issuer);
default:

@@ -58,5 +60,3 @@ throw new Error(`Invalid asset type: ${cx.switch().name}`);

// pad code with null bytes if necessary
let padLength = code.length <= 4 ? 4 : 12;
this.code = padRight(code, padLength, '\0');
this.code = code;
this.issuer = issuer;

@@ -81,4 +81,8 @@ }

// pad code with null bytes if necessary
let padLength = this.code.length <= 4 ? 4 : 12;
let paddedCode = padRight(this.code, padLength, '\0');
var assetType = new xdrType({
assetCode: this.code,
assetCode: paddedCode,
issuer: Keypair.fromAddress(this.issuer).accountId()

@@ -92,2 +96,16 @@ });

/**
* Return the asset code
*/
getCode() {
return clone(this.code);
}
/**
* Return the asset issuer
**/
getIssuer() {
return clone(this.issuer);
}
/**
* Returns true if this asset object is the native asset.

@@ -103,4 +121,4 @@ */

equals(asset) {
return this.code == asset.code && this.issuer == asset.issuer;
return this.code == asset.getCode() && this.issuer == asset.getIssuer();
}
}

@@ -15,3 +15,4 @@

export {Account} from "./account";
export {Network, Networks} from "./network";
export * from "./strkey";

@@ -5,2 +5,3 @@ import {xdr, hash} from "./index";

import {Operation} from "./operation";
import {Network} from "./network";
import {map, each} from "lodash";

@@ -72,3 +73,4 @@

return Buffer.concat([
this.signatureBasePrefix(),
Network.current().networkId(),
xdr.EnvelopeType.envelopeTypeTx().toXDR(),
this.tx.toXDR(),

@@ -78,6 +80,2 @@ ]);

signatureBasePrefix() {
return xdr.EnvelopeType.envelopeTypeTx().toXDR();
}
/**

@@ -84,0 +82,0 @@ * To envelope returns a xdr.TransactionEnvelope which can be submitted to the network.

@@ -14,2 +14,26 @@ describe('Asset', function() {

describe("getCode()", function () {
it("returns a code for a native asset object", function () {
var asset = new StellarBase.Asset.native();
expect(asset.getCode()).to.be.equal('XLM');
});
it("returns a code for a non-native asset", function () {
var asset = new StellarBase.Asset("USD", "GCEZWKCA5VLDNRLN3RPRJMRZOX3Z6G5CHCGSNFHEYVXM3XOJMDS674JZ");
expect(asset.getCode()).to.be.equal('USD');
});
});
describe("getIssuer()", function () {
it("returns a code for a native asset object", function () {
var asset = new StellarBase.Asset.native();
expect(asset.getIssuer()).to.be.undefined;
});
it("returns a code for a non-native asset", function () {
var asset = new StellarBase.Asset("USD", "GCEZWKCA5VLDNRLN3RPRJMRZOX3Z6G5CHCGSNFHEYVXM3XOJMDS674JZ");
expect(asset.getIssuer()).to.be.equal('GCEZWKCA5VLDNRLN3RPRJMRZOX3Z6G5CHCGSNFHEYVXM3XOJMDS674JZ');
});
});
describe("toXdrObject()", function () {

@@ -16,0 +40,0 @@ it("parses a native asset object", function () {

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is too big to display

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc