Comparing version 0.1.0-rc.14 to 0.1.0-rc.15
@@ -7,2 +7,10 @@ "use strict"; | ||
const utils_1 = require("./utils"); | ||
function isSchemaArray(schema) { | ||
return (Array.isArray(schema) && | ||
schema.length === 2 && | ||
typeof schema[1] === 'number'); | ||
} | ||
function assertSchemaIsTuple(_schema) { | ||
return true; | ||
} | ||
function stringifySchema(schema) { | ||
@@ -29,3 +37,3 @@ if (typeof schema === 'string') { | ||
} | ||
if (schema.length === 2 && typeof schema[1] === 'number') { | ||
if (isSchemaArray(schema)) { | ||
// array | ||
@@ -38,3 +46,6 @@ const count = schema[1]; | ||
} | ||
return `(${schema.map(stringifySchema).join(', ')})`; // tuple | ||
if (assertSchemaIsTuple(schema)) { | ||
return `(${schema.map(stringifySchema).join(', ')})`; // tuple | ||
} | ||
utils_1.unreachable(schema, `unknown schema: \`${schema}\``); | ||
} | ||
@@ -48,3 +59,3 @@ return schema.constructor.name; | ||
function abiEncode(schema, obj, encoder) { | ||
encoder = (encoder !== null && encoder !== void 0 ? encoder : new Encoder()); | ||
encoder = encoder !== null && encoder !== void 0 ? encoder : new Encoder(); | ||
doAbiEncode(schema, obj, encoder); | ||
@@ -55,4 +66,4 @@ return encoder.finish(); | ||
function doAbiEncode(schema, obj, encoder, parentTy) { | ||
var _a, _b, _c, _d, _e, _f, _g, _h; | ||
const throwUnexpectedType = () => { | ||
var _a, _b, _c, _d; | ||
function throwUnexpectedType() { | ||
const got = obj === null ? 'null' : obj.constructor.name; | ||
@@ -62,3 +73,3 @@ const schemaStr = stringifySchema(schema); | ||
throw new Error(`unexpected type \`${got}\`. expected \`${expected}\``); | ||
}; | ||
} | ||
if (typeof schema === 'string') { | ||
@@ -99,3 +110,4 @@ const ty = schema; | ||
return encoder.writeI128(BigInt(obj)); | ||
if (typeof obj !== 'number' && Number(obj) != obj) { | ||
const unsafeBigInt = Number(obj) != obj; | ||
if (typeof obj !== 'number' && unsafeBigInt) { | ||
/* istanbul ignore next */ | ||
@@ -105,18 +117,18 @@ throwUnexpectedType(); | ||
if (ty === 'u8') | ||
return encoder.writeU8(obj); | ||
return encoder.writeU8(Number(obj)); | ||
if (ty === 'i8') | ||
return encoder.writeI8(obj); | ||
return encoder.writeI8(Number(obj)); | ||
if (ty === 'u16') | ||
return encoder.writeU16(obj); | ||
return encoder.writeU16(Number(obj)); | ||
if (ty === 'i16') | ||
return encoder.writeI16(obj); | ||
return encoder.writeI16(Number(obj)); | ||
if (ty === 'u32') | ||
return encoder.writeU32(obj); | ||
return encoder.writeU32(Number(obj)); | ||
if (ty === 'i32') | ||
return encoder.writeI32(obj); | ||
return encoder.writeI32(Number(obj)); | ||
if (ty === 'f32') | ||
return encoder.writeF32(obj); | ||
return encoder.writeF32(Number(obj)); | ||
if (ty === 'f64') | ||
return encoder.writeF64(obj); | ||
throw new Error(`unknown schema type: \`${ty}\``); | ||
return encoder.writeF64(Number(obj)); | ||
utils_1.unreachable(ty, `unknown schema type: \`${ty}\``); | ||
} | ||
@@ -127,10 +139,7 @@ else if (Array.isArray(schema)) { | ||
let entries; | ||
if (obj instanceof Map) { | ||
entries = []; | ||
for (const entry of obj.entries()) { | ||
entries.push(entry); | ||
} | ||
if (obj instanceof Map || obj instanceof types_1.OasisMap) { | ||
entries = [...obj.entries()]; | ||
} | ||
else { | ||
entries = Object.entries(obj); | ||
throwUnexpectedType(); | ||
} | ||
@@ -146,13 +155,16 @@ entries.sort(); | ||
const ty = schema[1]; | ||
if (!(obj instanceof Set)) { | ||
let keys; | ||
if (obj instanceof Set || obj instanceof types_1.OasisSet) { | ||
keys = [...obj.keys()]; | ||
} | ||
else if (Array.isArray(obj)) { | ||
keys = obj; | ||
} | ||
else { | ||
throwUnexpectedType(); | ||
} | ||
const entries = []; | ||
for (const [k, _] of obj.entries()) { | ||
entries.push(k); | ||
} | ||
entries.sort(); | ||
encoder.writeU32(entries.length); | ||
entries.forEach(entry => { | ||
doAbiEncode(ty, entry, encoder); | ||
keys.sort(); | ||
encoder.writeU32(keys.length); | ||
keys.forEach(key => { | ||
doAbiEncode(ty, key, encoder); | ||
}); | ||
@@ -170,4 +182,4 @@ } | ||
const [_, okTy, errTy] = schema; | ||
if (typeof ((_a = obj) === null || _a === void 0 ? void 0 : _a.isOk) !== 'function' && | ||
typeof ((_b = obj) === null || _b === void 0 ? void 0 : _b.isErr) !== 'function') { | ||
if (typeof (obj === null || obj === void 0 ? void 0 : obj.isOk) !== 'function' && | ||
typeof (obj === null || obj === void 0 ? void 0 : obj.isErr) !== 'function') { | ||
throwUnexpectedType(); | ||
@@ -184,3 +196,3 @@ } | ||
} | ||
else if (schema.length === 2 && typeof schema[1] === 'number') { | ||
else if (isSchemaArray(schema)) { | ||
// array | ||
@@ -211,4 +223,5 @@ const ty = schema[0]; | ||
} | ||
else if (ty == 'u16') | ||
else if (ty == 'u16') { | ||
encoder.writeU16Array(obj); | ||
} | ||
else if (ty == 'i16') { | ||
@@ -240,3 +253,3 @@ encoder.writeI16Array(obj); | ||
} | ||
else { | ||
else if (assertSchemaIsTuple(schema)) { | ||
// tuple | ||
@@ -253,4 +266,7 @@ if (!Array.isArray(obj)) { | ||
} | ||
else { | ||
utils_1.unreachable(schema, `unknown schema: \`${schema}\``); | ||
} | ||
} | ||
else if (typeof ((_c = obj) === null || _c === void 0 ? void 0 : _c.abiEncode) === 'function') { | ||
else if (typeof (obj === null || obj === void 0 ? void 0 : obj.abiEncode) === 'function') { | ||
return obj.abiEncode(encoder); | ||
@@ -260,3 +276,3 @@ } | ||
/* istanbul ignore next */ | ||
throw new Error(`invalid object for schema: expected \`${_h = (_e = (_d = schema) === null || _d === void 0 ? void 0 : _d.name, (_e !== null && _e !== void 0 ? _e : (_g = (_f = schema) === null || _f === void 0 ? void 0 : _f.constructor) === null || _g === void 0 ? void 0 : _g.name)), (_h !== null && _h !== void 0 ? _h : JSON.stringify(schema))}\`, but got \`${JSON.stringify(obj)}\`.`); | ||
throw new Error(`invalid object for schema: expected \`${(_d = (_b = (_a = schema) === null || _a === void 0 ? void 0 : _a.name) !== null && _b !== void 0 ? _b : (_c = schema === null || schema === void 0 ? void 0 : schema.constructor) === null || _c === void 0 ? void 0 : _c.name) !== null && _d !== void 0 ? _d : JSON.stringify(schema)}\`, but got \`${JSON.stringify(obj)}\`.`); | ||
} | ||
@@ -311,5 +327,4 @@ } | ||
return decoder.readI128(); | ||
if (ty === 'string') { | ||
if (ty === 'string') | ||
return decoder.readString(); | ||
} | ||
utils_1.unreachable(ty, `unknown schema type: \`${ty}\``); | ||
@@ -321,3 +336,3 @@ } | ||
const length = decoder.readU32(); | ||
const m = new Map(); | ||
const m = new types_1.OasisMap(); | ||
for (let i = 0; i < length; i++) { | ||
@@ -331,3 +346,3 @@ m.set(doAbiDecode(keyTy, decoder), doAbiDecode(valTy, decoder)); | ||
const length = decoder.readU32(); | ||
const s = new Set(); | ||
const s = new types_1.OasisSet(); | ||
for (let i = 0; i < length; i++) { | ||
@@ -349,3 +364,3 @@ s.add(doAbiDecode(ty, decoder)); | ||
// array | ||
if (schema.length === 2 && typeof schema[1] === 'number') { | ||
if (isSchemaArray(schema)) { | ||
const ty = schema[0]; | ||
@@ -382,3 +397,6 @@ const count = schema[1] === Number.POSITIVE_INFINITY | ||
// tuple | ||
return schema.map(s => doAbiDecode(s, decoder)); | ||
if (assertSchemaIsTuple(schema)) { | ||
return schema.map(s => doAbiDecode(s, decoder)); | ||
} | ||
utils_1.unreachable(schema, `unknown schema: \`${schema}\``); | ||
} | ||
@@ -385,0 +403,0 @@ else if (typeof ((_a = schema) === null || _a === void 0 ? void 0 : _a.abiDecode) === 'function') { |
@@ -9,5 +9,10 @@ import EventEmitter from 'eventemitter3'; | ||
readonly apiToken: string; | ||
readonly options?: { | ||
oauthToken?: string | undefined; | ||
} | undefined; | ||
private inner; | ||
private subscriptionId; | ||
constructor(url: string, apiToken: string); | ||
constructor(url: string, apiToken: string, options?: { | ||
oauthToken?: string | undefined; | ||
} | undefined); | ||
/** | ||
@@ -14,0 +19,0 @@ * Deploy a new confidential service. |
@@ -44,7 +44,12 @@ "use strict"; | ||
class Gateway { | ||
constructor(url, apiToken) { | ||
constructor(url, apiToken, options) { | ||
this.url = url; | ||
this.apiToken = apiToken; | ||
this.options = options; | ||
this.subscriptionId = 0; | ||
this.inner = new gateway_1.HttpGateway(url, apiToken, { headers: new Map() }); | ||
const headers = new Map(); | ||
if (options === null || options === void 0 ? void 0 : options.oauthToken) { | ||
headers.set('X-GOOGLE-ID-TOKEN', options.oauthToken); | ||
} | ||
this.inner = new gateway_1.HttpGateway(url, apiToken, { headers }); | ||
} | ||
@@ -57,5 +62,4 @@ /** | ||
deploy(payload, options) { | ||
var _a; | ||
return __awaiter(this, void 0, void 0, function* () { | ||
const deployCode = service_1.DeployHeader.deployCode({ confidential: false, expiry: (_a = options) === null || _a === void 0 ? void 0 : _a.expiry }, payload); | ||
const deployCode = service_1.DeployHeader.deployCode({ confidential: false, expiry: options === null || options === void 0 ? void 0 : options.expiry }, payload); | ||
return new types_1.Address((yield this.inner.deploy({ data: deployCode })).address); | ||
@@ -87,3 +91,2 @@ }); | ||
subscribe(address, topics, decoder) { | ||
var _a; | ||
return __awaiter(this, void 0, void 0, function* () { | ||
@@ -94,3 +97,3 @@ this.subscriptionId += 1; | ||
filter: { | ||
address: (_a = address) === null || _a === void 0 ? void 0 : _a.bytes, | ||
address: address === null || address === void 0 ? void 0 : address.bytes, | ||
topics, | ||
@@ -97,0 +100,0 @@ }, |
export { AbiDecodable, AbiEncodable, Decoder, Encoder, Schema, abiDecode, abiEncode, encodeEventTopic, } from './abi'; | ||
export * from './gateway'; | ||
export { Address, Balance, ExecutionError, Result } from './types'; | ||
export { Address, Balance, ExecutionError, OasisMap as Map, OasisSet as Set, Result, } from './types'; | ||
export { decodeHex, encodeHex, fetchBytecode } from './utils'; |
@@ -17,2 +17,4 @@ "use strict"; | ||
exports.ExecutionError = types_1.ExecutionError; | ||
exports.Map = types_1.OasisMap; | ||
exports.Set = types_1.OasisSet; | ||
exports.Result = types_1.Result; | ||
@@ -19,0 +21,0 @@ var utils_1 = require("./utils"); |
@@ -16,2 +16,3 @@ import { AbiEncodable, Encoder, Decoder } from './abi'; | ||
equals(other: this): boolean; | ||
toJSON(): string; | ||
} | ||
@@ -26,2 +27,3 @@ /** | ||
static abiDecode(decoder: Decoder): Address; | ||
static fromJSON(json: string): Address; | ||
} | ||
@@ -39,2 +41,3 @@ /** | ||
get hex(): string; | ||
static fromJSON(json: string): Balance; | ||
} | ||
@@ -72,2 +75,38 @@ export declare class ExecutionError { | ||
export declare type Result<T, E> = Result.Ok<T, E> | Result.Err<T, E>; | ||
declare class MapLike<K, V> { | ||
protected inner: { | ||
[key: string]: [K, V]; | ||
}; | ||
constructor(items?: [K, V][]); | ||
size(): number; | ||
has(key: K): boolean; | ||
delete(key: K): void; | ||
clear(): void; | ||
keys(): IterableIterator<K>; | ||
protected _get(key: K): V | undefined; | ||
protected _set(key: K, value: V): void; | ||
protected _entries(): IterableIterator<[K, V]>; | ||
} | ||
/** | ||
* A `Map` type that's used by the Oasis ABI. Its primary purpose is to contain POD keys | ||
* (i.e. those that do not have user-defined methods and are represenable solely through JSON). | ||
* Equality in this type is defined as equality of JSON representations. | ||
*/ | ||
export declare class OasisMap<K, V> extends MapLike<K, V> { | ||
get(key: K): V | undefined; | ||
set(key: K, value: V): void; | ||
entries(): IterableIterator<[K, V]>; | ||
values(): IterableIterator<V>; | ||
} | ||
/** | ||
* A `Set` type that's used by the Oasis ABI. Its primary purpose is to contain POD types | ||
* (i.e. those that do not have user-defined methods and are represenable solely through JSON). | ||
* Equality in this type is defined as equality of JSON representations. | ||
*/ | ||
export declare class OasisSet<T> extends MapLike<T, true> { | ||
constructor(items?: T[]); | ||
add(item: T): void; | ||
entries(): IterableIterator<[T, T]>; | ||
values(): IterableIterator<T>; | ||
} | ||
export {}; |
@@ -36,2 +36,5 @@ "use strict"; | ||
} | ||
toJSON() { | ||
return this.hex; | ||
} | ||
} | ||
@@ -58,2 +61,5 @@ /** | ||
} | ||
static fromJSON(json) { | ||
return new Address(JSON.parse(json)); | ||
} | ||
} | ||
@@ -116,2 +122,5 @@ exports.Address = Address; | ||
} | ||
static fromJSON(json) { | ||
return new Balance(JSON.parse(json)); | ||
} | ||
} | ||
@@ -169,2 +178,83 @@ exports.Balance = Balance; | ||
})(Result = exports.Result || (exports.Result = {})); | ||
class MapLike { | ||
constructor(items = []) { | ||
this.inner = {}; | ||
for (const [k, v] of items) { | ||
this._set(k, v); | ||
} | ||
} | ||
size() { | ||
return Object.keys(this.inner).length; | ||
} | ||
has(key) { | ||
return this._get(key) !== undefined; | ||
} | ||
delete(key) { | ||
delete this.inner[JSON.stringify(key)]; | ||
} | ||
clear() { | ||
this.inner = {}; | ||
} | ||
*keys() { | ||
for (const entry of this._entries()) { | ||
yield entry[0]; | ||
} | ||
} | ||
_get(key) { | ||
const v = this.inner[JSON.stringify(key)]; | ||
return v ? v[1] : undefined; | ||
} | ||
_set(key, value) { | ||
this.inner[JSON.stringify(key)] = [key, value]; | ||
} | ||
*_entries() { | ||
for (const entry of Object.values(this.inner)) { | ||
yield entry; | ||
} | ||
} | ||
} | ||
/** | ||
* A `Map` type that's used by the Oasis ABI. Its primary purpose is to contain POD keys | ||
* (i.e. those that do not have user-defined methods and are represenable solely through JSON). | ||
* Equality in this type is defined as equality of JSON representations. | ||
*/ | ||
class OasisMap extends MapLike { | ||
get(key) { | ||
return this._get(key); | ||
} | ||
set(key, value) { | ||
this._set(key, value); | ||
} | ||
*entries() { | ||
yield* this._entries(); | ||
} | ||
*values() { | ||
for (const [_, v] of this._entries()) { | ||
yield v; | ||
} | ||
} | ||
} | ||
exports.OasisMap = OasisMap; | ||
/** | ||
* A `Set` type that's used by the Oasis ABI. Its primary purpose is to contain POD types | ||
* (i.e. those that do not have user-defined methods and are represenable solely through JSON). | ||
* Equality in this type is defined as equality of JSON representations. | ||
*/ | ||
class OasisSet extends MapLike { | ||
constructor(items = []) { | ||
super(items.map(item => [item, true])); | ||
} | ||
add(item) { | ||
this._set(item, true); | ||
} | ||
*entries() { | ||
for (const entry of this._entries()) { | ||
yield [entry[0], entry[0]]; | ||
} | ||
} | ||
*values() { | ||
yield* this.keys(); | ||
} | ||
} | ||
exports.OasisSet = OasisSet; | ||
//# sourceMappingURL=types.js.map |
/// <reference types="node" /> | ||
import 'node-fetch'; | ||
export declare type TypedArray = Uint8Array | Uint8ClampedArray | Int8Array | Uint16Array | Int16Array | Uint32Array | Int32Array | BigUint64Array | BigInt64Array | Float32Array | Float64Array; | ||
@@ -4,0 +3,0 @@ /** Parses a (possibly 0x-prefixed) big-endian hex string into bytes */ |
@@ -11,4 +11,7 @@ "use strict"; | ||
}; | ||
var __importDefault = (this && this.__importDefault) || function (mod) { | ||
return (mod && mod.__esModule) ? mod : { "default": mod }; | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
require("node-fetch"); | ||
const node_fetch_1 = __importDefault(require("node-fetch")); | ||
/** Parses a (possibly 0x-prefixed) big-endian hex string into bytes */ | ||
@@ -37,3 +40,3 @@ function decodeHex(hex) { | ||
else { | ||
return new Uint8Array(yield (yield fetch(bytecodeUrl)).arrayBuffer()); | ||
return new Uint8Array(yield (yield node_fetch_1.default(bytecodeUrl)).arrayBuffer()); | ||
} | ||
@@ -40,0 +43,0 @@ }); |
{ | ||
"name": "oasis-std", | ||
"version": "0.1.0-rc.14", | ||
"version": "0.1.0-rc.15", | ||
"description": "Oasis platform standard library", | ||
@@ -30,3 +30,3 @@ "license": "Apache-2.0", | ||
}, | ||
"gitHead": "3940060c222701a5a6add6560b1523c77073007b" | ||
"gitHead": "c2c29e25b5251873b081640f95c2f0575a16d8bd" | ||
} |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Network access
Supply chain riskThis module accesses the network.
Found 1 instance in 1 package
284610
1558
0