2

我在模块中找不到crypto-js,同时尝试在点击和种子以及公钥和私钥上创建用户钱包。

我收到此错误消息:

错误调用模块函数错误找不到模块“crypto-js”,与 app/tns_modules/ 相关

这是我的代码:

    import { Component, ElementRef, ViewChild } from "@angular/core";
    import { Router } from "@angular/router";
    import { alert, prompt } from "tns-core-modules/ui/dialogs";
    import { Page } from "tns-core-modules/ui/page";
    import { Routes } from "@angular/router";
    import { publicKey, verifySignature, signBytes, address,     keyPair,         privateKey } from "../@waves/waves-crypto"

    import { User } from "../shared/user.model";
import { UserService } from "../shared/user.service";

@Component({
    selector: "app-login",
    moduleId: module.id,
    templateUrl: "./login.component.html",
    styleUrls: ['./login.component.css']
})
export class LoginComponent {
    isLoggingIn = true;
    user: User;
    @ViewChild("password") password: ElementRef;
    @ViewChild("confirmPassword") confirmPassword: ElementRef;
    @ViewChild("waves") waves: ElementRef;

    constructor(private page: Page, private userService: UserService, private router: Router) {
        this.page.actionBarHidden = true;
        this.user = new User();
        // this.user.email = "foo2@foo.com";
        // this.user.password = "foo";
        const seed = 'magicseed';
        const pubKey = publicKey(seed);
        const bytes = Uint8Array.from([1, 2, 3, 4]);
        const sig = signBytes(bytes, seed);
        const isValid = verifySignature(pubKey, bytes, sig)
    }

    wallet() {
        let walletAddress = address('seed', 'T');
        keyPair('seed');
        publicKey('seed');
        privateKey('seed');
        alert(walletAddress);
        console.log(walletAddress);
        console.log(keyPair);
    }

    toggleForm() {
        this.isLoggingIn = !this.isLoggingIn;
    }

    submit() {
        if (!this.user.email || !this.user.password) {
            this.alert("Please provide both an email address and password.");
            return;
        }

        if (this.isLoggingIn) {
            this.login();
        } else {
            this.register();
        }
    }

    login() {
        this.userService.login(this.user)
            .then(() => {
                this.router.navigate(["/home"]);
            })
            .catch(() => {
                this.alert("Unfortunately we could not find your account.");
            });
    }

    register() {
        if (this.user.password != this.user.confirmPassword) {
            this.alert("Your passwords do not match.");
            return;
        }
        this.userService.register(this.user)
            .then(() => {
                this.alert("Your account was successfully created.");
                this.isLoggingIn = true;
            })
            .catch(() => {
                this.alert("Unfortunately we were unable to create your account.");
            });
    }

    forgotPassword() {
        prompt({
            title: "Forgot Password",
            message: "Enter the email address you used to register for APP NAME to reset your password.",
            inputType: "email",
            defaultText: "",
            okButtonText: "Ok",
            cancelButtonText: "Cancel"
        }).then((data) => {
            if (data.result) {
                this.userService.resetPassword(data.text.trim())
                    .then(() => {
                        this.alert("Your password was successfully reset. Please check your email for instructions on choosing a new password.");
                    }).catch(() => {
                        this.alert("Unfortunately, an error occurred resetting your password.");
                    });
            }
        });
    }

    focusPassword() {
        this.password.nativeElement.focus();
    }
    focusConfirmPassword() {
        if (!this.isLoggingIn) {
            this.confirmPassword.nativeElement.focus();
        }
    }

    alert(message: string) {
        return alert({
            title: "APP NAME",
            okButtonText: "OK",
            message: message
        });
    }
}
4

2 回答 2

2

好像您已经手动复制了库。@waves/waves-crypto通过 npm重新安装,并像这样从node_modules导入它:

import * as wavesCrypto from '@waves/waves-crypto'
于 2019-04-05T08:33:03.393 回答
0

在这里查看我对相同问题的回答。

我有同样的问题,我在 Github repo 上打开了下一个问题(你可以去点击喜欢或评论),链接在这里

在问题中,我解释了一种对我有用的解决方法来验证签名,您可以使用相同的代码段。

首先手动导入所需的子模块:

import { default as axlsign } from '@waves/signature-generator/libs/axlsign';
import { default as convert } from '@waves/signature-generator/dist/utils/convert';
import { concatUint8Arrays } from '@waves/signature-generator/dist/utils/concat';
import { default as base58 } from '@waves/signature-generator/dist/libs/base58';

然后你可以使用下面的代码来验证签名和公钥:

let prefix = "WavesWalletAuthentication";
let host = new URL(yourServerUrl).hostname;

let user = wavesAddressString;
let payload = theStringThatWasSigned;

let data = [prefix, host, payload]
    .map(d => convert.stringToByteArrayWithSize(d))
    .map(stringWithSize => Uint8Array.from(stringWithSize));
let dataBytes = concatUint8Arrays(...data);

let publicKeyBytes = base58.decode(publicKeyOnBase58Format);
let signatureBytes = base58.decode(signatureOnBase58Format);

let validSignature = axlsign.verify(publicKeyBytes, dataBytes, signatureBytes);
console.log("(login) validSignature?", validSignature);
于 2019-04-08T19:15:55.383 回答