Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

scryptlib

Package Overview
Dependencies
Maintainers
2
Versions
295
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

scryptlib - npm Package Compare versions

Comparing version 0.1.9 to 0.2.0

5

CHANGELOG.md
# CHANGELOG
## 0.2.0
* add some options to compile function
* change source location in compileResult from path to uri
## 0.1.9

@@ -4,0 +9,0 @@

5

dist/compilerWrapper.d.ts

@@ -59,2 +59,4 @@ import { ABIEntity } from './abi';

}, settings?: {
npxArgs?: string;
scVersion?: string;
ast?: boolean;

@@ -66,4 +68,5 @@ asm?: boolean;

outputToFiles?: boolean;
cwd?: string;
cmdArgs?: string;
}): CompileResult;
export declare function compilerVersion(): string;
export declare function compilerVersion(cwd?: string): string;

56

dist/compilerWrapper.js

@@ -10,2 +10,3 @@ "use strict";

const md5 = require("md5");
const utils_1 = require("./utils");
const SYNTAX_ERR_REG = /(?<filePath>[^\s]+):(?<line>\d+):(?<column>\d+):\n([^\n]+\n){3}(unexpected (?<unexpected>[^\n]+)\nexpecting (?<expecting>[^\n]+)|(?<message>[^\n]+))/g;

@@ -30,4 +31,7 @@ const SEMANTIC_ERR_REG = /Error:\s*(?<filePath>[^\s]+):(?<line>\d+):(?<column>\d+)\n(?<message>[^\n]+)\n/g;

}) {
const st = Date.now();
const npxArg = settings.npxArgs || '--no-install';
const sourcePath = source.path;
const srcDir = path_1.dirname(sourcePath);
const curWorkingDir = settings.cwd || srcDir;
const sourceFileName = path_1.basename(sourcePath);

@@ -38,4 +42,4 @@ const outputDir = settings.outputDir || srcDir;

const sourceContent = source.content !== undefined ? source.content : fs_1.readFileSync(sourcePath, 'utf8');
const cmd = `npx --no-install scryptc compile ${settings.asm || settings.desc ? '--asm' : ''} ${settings.ast || settings.desc ? '--ast' : ''} ${settings.debug == false ? '' : '--debug'} -r -o "${outputDir}" ${settings.cmdArgs ? settings.cmdArgs : ''}`;
const output = child_process_1.execSync(cmd, { input: sourceContent, cwd: srcDir }).toString();
const cmd = `npx ${npxArg} scryptc${settings.scVersion ? '@' + settings.scVersion : ''} compile ${settings.asm || settings.desc ? '--asm' : ''} ${settings.ast || settings.desc ? '--ast' : ''} ${settings.debug == false ? '' : '--debug'} -r -o "${outputDir}" ${settings.cmdArgs ? settings.cmdArgs : ''}`;
const output = child_process_1.execSync(cmd, { input: sourceContent, cwd: curWorkingDir }).toString();
if (output.startsWith('Error:')) {

@@ -103,15 +107,7 @@ if (output.includes('import') && output.includes('File not found')) {

outputFiles['ast'] = outputFilePath;
const allAst = addSourceLocation(JSON.parse(fs_1.readFileSync(outputFilePath, 'utf8')), srcDir);
result.ast = allAst['stdin'];
result.dependencyAsts = Object.keys(allAst)
.filter(k => k !== 'stdin')
.reduce((res, key) => {
if (key === 'std') {
res[key] = allAst[key];
}
else {
res[path_1.join(srcDir, key)] = allAst[key];
}
return res;
}, {});
const allAst = addSourceLocation(JSON.parse(fs_1.readFileSync(outputFilePath, 'utf8')), srcDir, sourceFileName);
const sourceUri = utils_1.path2uri(sourcePath);
result.ast = allAst[sourceUri];
delete allAst[sourceUri];
result.dependencyAsts = allAst;
}

@@ -122,3 +118,3 @@ if (settings.asm || settings.desc) {

if (settings.debug == false) {
result.asm = fs_1.readFileSync(outputFilePath, 'utf8');
result.asm = JSON.parse(fs_1.readFileSync(outputFilePath, 'utf8')).join(' ');
}

@@ -146,3 +142,3 @@ else {

return {
file: fileIndex > -1 ? sources[fileIndex] : undefined,
file: sources[fileIndex] ? getFullFilePath(sources[fileIndex], srcDir, sourceFileName) : undefined,
line: sources[fileIndex] ? parseInt(match.groups.line) : undefined,

@@ -168,3 +164,3 @@ endLine: sources[fileIndex] ? parseInt(match.groups.endLine) : undefined,

const description = {
compilerVersion: compilerVersion(),
compilerVersion: compilerVersion(settings.cwd),
contract: name,

@@ -206,18 +202,26 @@ md5: md5(sourceContent),

}
// console.log('compile time spent: ', Date.now() - st)
}
}
exports.compile = compile;
function compilerVersion() {
const text = child_process_1.execSync(`npx --no-install scryptc version`).toString();
function compilerVersion(cwd) {
const text = child_process_1.execSync(`npx --no-install scryptc version`, { cwd }).toString();
return /Version:\s*([^\s]+)\s*/.exec(text)[1];
}
exports.compilerVersion = compilerVersion;
function addSourceLocation(astRoot, basePath) {
function addSourceLocation(astRoot, basePath, curFileName) {
for (const fileName in astRoot) {
const path = fileName === 'std' ? null : path_1.join(basePath, fileName);
astRoot[fileName] = _addSourceLocationProperty(astRoot[fileName], path);
if (fileName === 'std') {
astRoot['std'] = _addSourceLocationProperty(astRoot['std'], null);
}
else {
const realFileName = fileName === 'stdin' ? curFileName : fileName;
const uri = utils_1.path2uri(path_1.join(basePath, realFileName));
astRoot[uri] = _addSourceLocationProperty(astRoot[fileName], uri);
delete astRoot[fileName];
}
}
return astRoot;
}
function _addSourceLocationProperty(astObj, path) {
function _addSourceLocationProperty(astObj, uri) {
if (!(astObj instanceof Object)) {

@@ -235,3 +239,3 @@ return astObj;

astObj.loc = {
source: path,
source: uri,
start: { line: parseInt(matches[1]), column: parseInt(matches[2]) },

@@ -244,3 +248,3 @@ end: { line: parseInt(matches[3]), column: parseInt(matches[4]) }

else if (value instanceof Object) {
_addSourceLocationProperty(value, path);
_addSourceLocationProperty(value, uri);
}

@@ -247,0 +251,0 @@ }

@@ -33,5 +33,5 @@ import { ABICoder, ABIEntity, FunctionCall, Script } from "./abi";

run_verify(unlockingScriptASM: string, txContext?: TxContext): VerifyResult;
private _dataLoad?;
private _dataLoad;
set dataLoad(dataInHex: string | undefined | null);
get dataLoad(): string;
get dataLoad(): string | undefined | null;
get codePart(): Script;

@@ -38,0 +38,0 @@ get dataPart(): Script | undefined;

@@ -9,3 +9,3 @@ "use strict";

let lsASM = this.scriptedConstructor.toASM();
if (this._dataLoad !== undefined) {
if (this._dataLoad !== undefined && this._dataLoad !== null) {
lsASM += ` OP_RETURN ${this._dataLoad}`;

@@ -48,3 +48,3 @@ }

get dataLoad() {
return this._dataLoad;
return this._dataLoad || null;
}

@@ -51,0 +51,0 @@ get codePart() {

@@ -24,1 +24,3 @@ import bsv = require('bsv');

export declare function num2bin(n: number, dataLen: number): string;
export declare function path2uri(path: string): string;
export declare function uri2path(uri: string): string;
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.num2bin = exports.getPreimage = exports.toHex = exports.signTx = exports.getValidatedHexString = exports.hexStringToBytes = exports.bytesToHexString = exports.bytes2Literal = exports.literal2Asm = exports.int2Asm = exports.bool2Asm = exports.DEFAULT_SIGHASH_TYPE = exports.DEFAULT_FLAGS = exports.bsv = void 0;
exports.uri2path = exports.path2uri = exports.num2bin = exports.getPreimage = exports.toHex = exports.signTx = exports.getValidatedHexString = exports.hexStringToBytes = exports.bytesToHexString = exports.bytes2Literal = exports.literal2Asm = exports.int2Asm = exports.bool2Asm = exports.DEFAULT_SIGHASH_TYPE = exports.DEFAULT_FLAGS = exports.bsv = void 0;
const url_1 = require("url");
const bsv = require("bsv");

@@ -217,2 +218,10 @@ exports.bsv = bsv;

exports.num2bin = num2bin;
function path2uri(path) {
return url_1.pathToFileURL(path).toString();
}
exports.path2uri = path2uri;
function uri2path(uri) {
return url_1.fileURLToPath(uri);
}
exports.uri2path = uri2path;
//# sourceMappingURL=utils.js.map
{
"name": "scryptlib",
"version": "0.1.9",
"version": "0.2.0",
"description": "Javascript SDK for integration of Bitcoin SV Smart Contracts written in sCrypt language.",

@@ -53,5 +53,5 @@ "engines": {

"md5": "^2.2.1",
"scryptc": "0.1.20",
"scryptc": "0.2.2",
"ts-optchain": "^0.1.8"
}
}

@@ -88,3 +88,3 @@ # scryptlib

```typescript
const MyContract = buildContractClass(JSON.parse(descFileContent));`
const MyContract = buildContractClass(JSON.parse(descFileContent));
```

@@ -120,3 +120,3 @@ To create an instance of the contract class, for example:

A useful method `verify(txContext)` is provided for each contract function call. It would execute the function call with the given context locally. The `txContext` argument provides some context information of the current transaction, needed only if signature is checked inside the contract.
A useful method `verify(txContext)` is provided for each contract function call. It would execute the function call with the given context locally. The `txContext` argument provides some context information of the current transaction, **needed only if signature is checked inside the contract**.
```typescript

@@ -140,4 +140,11 @@ {

```typescript
const context = { tx, inputIndex, inputSatoshis };
// 1) set context per verify()
const funcCall = instance.someFunc(new Sig('0123456'), new Bytes('aa11ff'), ...parameters);
const result = funcCall.verify( { tx, inputIndex, inputSatoshis } );
const result = funcCall.verify(context);
// 2) alternatively, context can be set at instance level and all following verify() will use it
instance.txContext = context;
const result = funcCall.verify();
expect(result.success, result.error).to.be.true;

@@ -144,0 +151,0 @@ assert.isFalse(result.success, result.error);

Sorry, the diff of this file is not supported yet

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